Closed code423n4 closed 3 years ago
This issue is valid; however, as the first point in the known issues in the contracts in the C4 repo for this contest, this issue was marked out of scope: https://github.com/code-423n4/2021-10-tracer#c4-audit-known-issues
The finding was excluded, I've checked that the readme wasn't changed during the contest
As such the issue is invalid
Handle
cmichel
Vulnerability details
The
PoolCommitter.commit
function first adds the amount to the shadow pool (shadowPools[_commitType] = shadowPools[_commitType] + amount
) and then computes theamountOut
with this updated value already:The shadow pool must be updated only after the computation.
Impact
It leads to a wrong
amountOut
and commitments that should be accepted could be denied.Example: Initial values:
totalSupply = 1000, longBalance = 1000
,shadowPools[LongBurn] = 0
. The formula foramountOut
is:balance * amountIn / (tokenSupply + shadowBalance)
amount = 1000
: Note howshadowPools[LongBurn]
is updated to1000
first. Then,amountOut = 1000 * 1000 / (1000 + 1000) = 1000 * 1/2 = 500
. Clearly if we intend to burn all existing tokens, thetotalSupply
, we should receive the entirebalance
, but we only receive half of it.This under-reports the actual amount we receive and can therefore lead to legitimate burns being dismissed due to the
require(amountOut >= minimumCommitSize)
check.The same issue exists for the
ShortBurn
case.Recommended Mitigation Steps
Increase the shadow pool after the computation. It makes sense to do it after the actual
burn
call as the invariant is thattotalSupply_long + shadowPools[LongBurn]
should stay constant across burn commits.