Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Missing virtual modifier in BaseHook contract causing inheritance and override problems #455

Open
oftiyf opened this issue Mar 3, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@oftiyf
Copy link

oftiyf commented Mar 3, 2025

Describe the bug

Description

I encountered a compilation error when trying to inherit and override the beforeSwap function as instructed in the test case README. The README example directly inherits and implements the beforeSwap function, but compilation fails in practice.

Root Cause

After examining the code, I found the issue in the main/src/utils/BaseHook.sol file. The beforeSwap function lacks the virtual modifier, preventing child contracts from properly overriding this function.

// Current implementation (problematic):
function beforeSwap(...) returns (...) {
    // function implementation
}

// Expected implementation:
function beforeSwap(...) virtual returns (...) {
    // function implementation
}

Steps to Reproduce

  1. Create a new contract that inherits from BaseHook following the test case README example
  2. Attempt to override the beforeSwap function
  3. Compile the contract
  4. Observe the compilation error indicating that a non-virtual function cannot be overridden

Impact

This issue prevents developers from correctly extending and customizing hook logic as shown in the documentation examples, hindering the development of new hooks.

Proposed Solution

Add the virtual modifier to the beforeSwap function in the main/src/utils/BaseHook.sol file to allow it to be overridden by child contracts.

Additional Notes

I discovered this issue while learning from the official documentation. The examples in the docs imply these functions are meant to be overridable, but the actual implementation doesn't support this behavior.

Expected Behavior

// ... existing code ...
function beforeSwap(
address sender,
PoolKey calldata key,
IPoolManager.SwapParams calldata params,
bytes calldata hookData
) external virtual returns (bytes4, BeforeSwapDelta, uint24) {
// ... existing code ...
}
// ... existing code ...

To Reproduce

No response

Additional context

No response

@oftiyf oftiyf added the bug Something isn't working label Mar 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant