Open code423n4 opened 2 years ago
Noting here that I received this warden's full submission via DM shortly after the contest closed, and have edited their placeholder submission. Warden had written the report but was unable to upload it due to technical problems. The report was submitted to me at 2:00 AM UTC, two hours after contest close; additional lag time was on my end, due to time zones and work schedules.
Unchecked math will save on gas
Duplicate of https://github.com/code-423n4/2022-02-pooltogether-findings/issues/15
Unneeded Zero Address Check
PR: https://github.com/pooltogether/v4-twab-delegator/pull/25
More efficient order of operations in updateDelegatee
I get a pretty different result on my end when implementing this change.
Without it (on average): 146,921 With it (on average): 146,888
So we save only 33 gas and the code becomes a little bit less legible.
I also wonder how the code example provided by the warden compile since block.timestamp
need to be casted to uint96
: uint96 _lockUntil = uint96(block.timestamp);
So for the reason above, I won't implement this change.
Missing comment for the to parameter
Incorrect Comment Associated with transferDelegationTo
Duplicate of https://github.com/code-423n4/2022-02-pooltogether-findings/issues/16
Incorrect Event Parameters
No, the passed address _to
will be the delegator since this function offer the possibility to stake on behalf of another user.
This _to
user will then receive an ERC20 token representing his stake in the contract and will be able to create a delegation by using the function createDelegation
and then fund it with the function fundDelegationFromStake
.
Gas Optimizations
Unchecked math will save on gas
The
_computeLockUntil
function inTWABDelegator.sol
can be optimized by adding theunchecked
directive as this will never overflow theuint96
type since it is limited by theMAX_LOCK
constant (which is currently assigned to 180 days() by the call to_requireLockDuration(_lockDuration);
.Unneeded Zero Address Check
In the
stake
function of theTWABDelegator.sol
file, the_requireRecipientNotZeroAddress
function is called on the_to
parameter. However, this is unnecessary since the_mint
function checks for the zero address when called. As such, it would be more gas efficient to not perform this call.More efficient order of operations in
updateDelegatee
In the
updateDelegatee
function of theTWABDelegator.sol
file the_lockUntil
variable is defined by calling the_computeLockUntil
function. However, if the_lockDuration
is 0, then this value is the same as the currentblock.timestamp
. As a result, the following code would be an optimization:Original Code:
Optimized Code:
Here are the tests with the optimizations (* indicates Optimized case):
Non-Critcal
Missing comment for the
to
parameterThere is no comment on the
to
parameter for theTransferredDelegation
event in theTWABDelegator.sol
file.Low
Incorrect Event Parameters
The
TWABDelegator.sol
'sTicketsStaked
event's first parameter should be the delegator, as such, it should bemsg.sender
not_to
as_to
is the recipient.Incorrect Comment Associated with
transferDelegationTo
The comments above the
transferDelegationTo
function are incorrect. The first line, which begins with@notice
, saysThe tickets are transferred to the caller
. However, the tickets are transfered to the_to
parameter as can be seen by the line_transfer(_delegation, _to, _amount);
In addition, the comment directly below that statesWill directly send the tickets to the delegator wallet.
This is also incorrect per the above reason.