The updateTokenWhiteListed function allows the owner to add or remove tokens from the whitelist. Attackers can observe pending transactions to update the whitelist and submit their own transactions with higher gas fees to manipulate the whitelist status before the original transaction is processed.
1.Initial Setup
Involved Tokens: TokenA
Initial State: TokenA is not in the whitelist (tokenWhiteListed[TokenA] = false).
2.Authorized User Transactions
Authorized User: Alice
Goal: Add TokenA to the whitelist.
Alice's Transactions:
updateTokenWhiteListed([TokenA], true);
Gas Fee: Alice sends a transaction with the default gas fee.
3.Attacker Observes Transactions
Attacker: Bob
Goal: Disrupt or manipulate the whitelist.
Attacker Steps:
Bob observes Alice's transactions in the mempool.
Bob sends a transaction with a higher gas fee to ensure his transaction is processed before Alice's transaction.
4.Attacker Transaction
Bob's transaction:
updateTokenWhiteListed([TokenA], false);
Gas Fee: Bob sends a transaction with a higher gas fee than Alice's transaction.
5.Transaction Processing Order (Continued)
Bob's transaction is processed first because the gas fee is higher.
o tokenWhiteListed[TokenA] remains false or is changed to false if it was previously true.
o Emit event UpdateTokenWhiteListed(tokenAddress: 0x000000000000000000000000000000000000000000003, isWhiteListed: false).
Alice's transaction is processed after Bob's transaction.
o tokenWhiteListed[TokenA] is changed to true.
o Emit event UpdateTokenWhiteListed(tokenAddress: 0x000000000000000000000000000000000000003, isWhiteListed: true).
Exploit Impact
• If Bob Removes TokenA from the Whitelist:
o If TokenA is already in the whitelist, Bob can remove it before Alice's transaction re-adds it.
o This could cause confusion or failure in operations that depend on the whitelist status.
• If Bob Adds TokenA to the Whitelist:
o Bob could add TokenA to the whitelist before Alice's transaction, which Alice may not want.
Potential Downsides
• Failed Transactions: Legitimate users' transactions may not work as expected if the whitelist status changes before they are processed.
• Gas Wastage: Legitimate users may have to resubmit transactions at an additional gas cost if the first transaction fails or does not produce the desired result.
Manual review
Foundry
Add a timelock mechanism to slow down changes to the whitelist, giving users time to react to the changes.
Use a multi-signature mechanism to validate changes to the whitelist, requiring multiple signatures from the owner or authorized parties.
Limit the frequency of changes to the whitelist to prevent rapid changes and allow users to react.
Add a mechanism to wait for event confirmation before allowing further changes.
forge test --match-path test/ExploitTest.t.sol
[⠊] Compiling...
[⠰] Compiling 1 files with Solc 0.8.26
[⠒] Solc 0.8.26 finished in 1.32s
Compiler run successful!
Ran 1 test for test/ExploitTest.t.sol:ExploitTest
[PASS] testExploit() (gas: 48680)
Suite result: ok. 1 passed; 0 failed; 0 skipped; finished in 45.99ms (11.12ms CPU time)
Ran 1 test suite in 82.84ms (45.99ms CPU time): 1 tests passed, 0 failed, 0 skipped (1 total tests)
The following issues and its duplicates are invalid as admin errors/input validation/malicious intents are1 generally considered invalid based on [codehawks guidelines](https://docs.codehawks.com/hawks-auditors/how-to-determine-a-finding-validity#findings-that-may-be-invalid). If they deploy/set inputs of the contracts appropriately, there will be no issue. Additionally admins are trusted as noted in READ.ME they can break certain assumption of the code based on their actions, and
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.