setAllowedSellToken()
lets the owner waste gas by setting the same token status over and over again.The contract allows the owner to mark any token as "allowed" for selling on the order book by toggling its status via setAllowedSellToken
.
Currently, the contract does not check whether the token is already in the desired state. As a result, repeatedly setting the same token to the same _isAllowed
value leads to redundant storage writes and unnecessary event emissions.
Likelihood:
This issue is triggered when the owner
calls setAllowedSellToken()
with the same value that’s already set — for example, calling setAllowedSellToken(token, true)
even though the token is already allowed.
Impact:
Each useless call wastes around 3736 gas (as confirmed in the test).
The contract writes to storage even though the value is already the same — this is unnecessary and expensive.
It pollutes the blockchain with extra logs.
This Proof of Concept demonstrates how the setAllowedSellToken()
function allows duplicate entries for the same token, resulting in unnecessary gas usage. Here's how the PoC works:
A dummy token address (0x123
) is created to simulate a real token.
The token is allowed once using setAllowedSellToken(token, true)
.
The same function is called again with the same token and the same true
status.
Gas usage before and after the second call is measured using gasleft()
, and the difference is logged.
To avoid unnecessary gas consumption and improve function efficiency, the setAllowedSellToken()
function should include a conditional check before updating the mapping.
Before writing to the allowedSellToken
mapping, check if the new value is different from the current one.
It ensures that the function can only updates storage when an actual change is needed.
Don't forget to add TokenAlreadyAllowed()
custom error in contract.
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.