The normal behavior should validate that the ReFi token is present as one of the two currencies (currency0 OR currency1) in the pool before initialization proceeds.
The _beforeInitialize() function contains a copy-paste error where it checks key.currency1 twice instead of checking both key.currency0 and key.currency1. This allows pools to be initialized without the ReFi token, bypassing the protocol's core validation requirement.
Current Buggy Logic:
if (currency1 != ReFi && currency1 != ReFi) → Always evaluates to if (currency1 != ReFi)
Never checks if currency0 == ReFi
Real-World Scenario That Bypasses Validation:
Pool with currency0 = ReFi, currency1 = USDC
Check becomes: if (USDC != ReFi && USDC != ReFi) → TRUE, reverts (correct behavior by accident)
Pool with currency0 = USDC, currency1 = ReFi
Check becomes: if (ReFi != ReFi && ReFi != ReFi) → FALSE, allows initialization (correct behavior)
Pool with currency0 = ReFi, currency1 = ReFi
Check becomes: if (ReFi != ReFi && ReFi != ReFi) → FALSE, allows initialization (shouldn't allow same token)
Pool with currency0 = WETH, currency1 = USDC (NO ReFi)
Check becomes: if (USDC != ReFi && USDC != ReFi) → TRUE, reverts (correct behavior by accident)
The bug accidentally works in most cases but creates edge case vulnerabilities.
Likelihood:
While the duplicate check accidentally provides correct behavior for most scenarios, it exposes edge cases
The validation logic is fundamentally broken even if outcomes appear correct
Future modifications to the code may break the accidental correctness
A malicious actor could exploit the illogical structure in edge cases
Code auditors and developers reading this code will be confused by the illogical structure
Impact:
Potential for pools to be initialized with currency0 = ReFi and currency1 = ReFi (same token twice)
Undefined behavior when both currencies are the same token
Pool operations would fail or behave unpredictably with duplicate currencies
Gas wasted on nonsensical pools
Confusion for developers maintaining the code
Reduced code quality and maintainability
False sense of security from validation that doesn't actually validate correctly
Running the PoC:
Expected Output:
Additional Enhancement:
Consider adding validation to prevent pools where both currencies are the same:
Testing Recommendation:
Add test cases that verify:
Pool with ReFi as currency0 initializes successfully
Pool with ReFi as currency1 initializes successfully
Pool without ReFi fails to initialize
Pool with ReFi as both currencies fails to initialize (if enhancement added)
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.