[IPool] - gulp
should check if the token exists before updating state and executing outside code
#8
Labels
gulp
should check if the token exists before updating state and executing outside code
#8
Description
If one of the users sends tokens directly to the contract and wants the pool to update its internal balance, they can call the publicly available method
gulp
. This method first callsbalanceOf
for the provided token of the pool.The
balanceOf
method of the provided token address is executed whether the token exists in the pool or not. This is because_records
is defined as a storage mapping.This means that any user can provide any contract's address, which contains a
balanceOf
method, which will be executed by theIPool
contract. Because the token is not bound, the execution follows the else branch ingulp
.Not only the contract executes external code, but it also calls
_unbindHandler.handleUnbindToken(token, balance);
which, in its current implementation, emits an event which could potentially be malicious when parsed by the frontend or the backend.Recommendation
Only accept valid tokens
Check the validity of the provided address before executing any external code or emitting any events.
Static call
balanceOf
While presenting the current issue to Dillon, a good suggestion was surfaced to do a static
balanceOf
call.However, after checking the generated assembly, we realized Solidity already uses
STATICCALL
when callingview
functions. This is also described in the official documentation.The text was updated successfully, but these errors were encountered: