Platform: Code4rena
Start Date: 20/01/2022
Pot Size: $50,000 USDC
Total HM: 3
Participants: 35
Period: 7 days
Judge: GalloDaSballo
Total Solo HM: 2
Id: 77
League: ETH
Rank: 17/35
Findings: 2
Award: $75.84
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: sorrynotsorry
Also found by: 0v3rf10w, Dravee, Meta0xNull, WatchPug, byterocket, defsec, robee, sirhashalot, ye0lde
ye0lde
Shortening revert strings to fit in 32 bytes will decrease deployment time gas and will decrease runtime gas when the revert condition has been met. Revert strings that are longer than 32 bytes require at least one additional mstore, along with additional overhead for computing memory offset, etc.
It's clear the sponsor is committed to consistent, verbose revert messages. But I just wanted to note that a lot of these messages are close to the limit and could be shortened and be under the limit just by abbreviating the "contract" name or removing a space.
https://github.com/code-423n4/2022-01-elasticswap/blob/d107a198c0d10fbe254d69ffe5be3e40894ff078/elasticswap/src/contracts/Exchange.sol#L137 https://github.com/code-423n4/2022-01-elasticswap/blob/d107a198c0d10fbe254d69ffe5be3e40894ff078/elasticswap/src/contracts/Exchange.sol#L176
https://github.com/code-423n4/2022-01-elasticswap/blob/d107a198c0d10fbe254d69ffe5be3e40894ff078/elasticswap/src/contracts/ExchangeFactory.sol#L44 https://github.com/code-423n4/2022-01-elasticswap/blob/d107a198c0d10fbe254d69ffe5be3e40894ff078/elasticswap/src/contracts/ExchangeFactory.sol#L47 https://github.com/code-423n4/2022-01-elasticswap/blob/d107a198c0d10fbe254d69ffe5be3e40894ff078/elasticswap/src/contracts/ExchangeFactory.sol#L52 https://github.com/code-423n4/2022-01-elasticswap/blob/d107a198c0d10fbe254d69ffe5be3e40894ff078/elasticswap/src/contracts/ExchangeFactory.sol#L75
https://github.com/code-423n4/2022-01-elasticswap/blob/d107a198c0d10fbe254d69ffe5be3e40894ff078/elasticswap/src/libraries/MathLib.sol#L267 https://github.com/code-423n4/2022-01-elasticswap/blob/d107a198c0d10fbe254d69ffe5be3e40894ff078/elasticswap/src/libraries/MathLib.sol#L337 https://github.com/code-423n4/2022-01-elasticswap/blob/d107a198c0d10fbe254d69ffe5be3e40894ff078/elasticswap/src/libraries/MathLib.sol#L497 https://github.com/code-423n4/2022-01-elasticswap/blob/d107a198c0d10fbe254d69ffe5be3e40894ff078/elasticswap/src/libraries/MathLib.sol#L501 https://github.com/code-423n4/2022-01-elasticswap/blob/d107a198c0d10fbe254d69ffe5be3e40894ff078/elasticswap/src/libraries/MathLib.sol#L608 https://github.com/code-423n4/2022-01-elasticswap/blob/d107a198c0d10fbe254d69ffe5be3e40894ff078/elasticswap/src/libraries/MathLib.sol#L641
Visual Studio Code
Consider shortening the revert strings to fit in 32 bytes or using custom errors in the future.
#0 - 0xean
2022-01-31T14:08:36Z
dupe of #159
47.9414 USDC - $47.94
ye0lde
A struct
is being assigned its default value which is unnecessary.
Removing the assignment will save gas when deploying.
Visual Studio Code, Remix
Remove the assignment.
Or if you feel it is important to show the default assignment will occur then replace the assignments with a comment.
I suggest the following:
Change this:
MathLib.InternalBalances public internalBalances = MathLib.InternalBalances(0, 0, 0);
to something like:
MathLib.InternalBalances public internalBalances; // Tracking x*y=k with x=0, y=0, k=0 initially
#0 - 0xean
2022-01-31T14:15:46Z
dupe of #158
ye0lde
Redundant arithmetic underflow/overflow checks can be avoided when an underflow/overflow cannot happen.
The "unchecked" keyword can be applied to these since there is an if
statement before to ensure the arithmetic operations would not cause an integer underflow or overflow.
Change the code at 224 to:
unchecked { // We should ensure no possible overflow here. if (quoteTokenQtyToReturn > internalBalances.quoteTokenReserveQty) { internalBalances.quoteTokenReserveQty = 0; } else { internalBalances.quoteTokenReserveQty -= quoteTokenQtyToReturn; } }
Change the code at 75 to:
unchecked { if (a >= b) { return a - b; } return b - a; }
Visual Studio Code, Remix
Add the "unchecked" keyword as shown above.
#0 - 0xean
2022-01-31T13:54:48Z
dupe of #177
19.4163 USDC - $19.42
ye0lde
Using the existing named returns more efficiently can reduce gas usage and improve code clarity.
These functions have named return variables and don't need explicit return statements at the end.
I suggest deleting the following explicit returns: https://github.com/code-423n4/2022-01-elasticswap/blob/d107a198c0d10fbe254d69ffe5be3e40894ff078/elasticswap/src/libraries/MathLib.sol#L282 https://github.com/code-423n4/2022-01-elasticswap/blob/d107a198c0d10fbe254d69ffe5be3e40894ff078/elasticswap/src/libraries/MathLib.sol#L362
Visual Studio Code, Remix
See POC
#0 - 0xean
2022-01-31T14:27:01Z
dupe of #151