code-423n4 / 2022-01-elasticswap-findings

1 stars 0 forks source link

Assignment Of Variables To Default #120

Closed code423n4 closed 2 years ago

code423n4 commented 2 years ago

Handle

ye0lde

Vulnerability details

Impact

A struct is being assigned its default value which is unnecessary. Removing the assignment will save gas when deploying.

Proof of Concept

https://github.com/code-423n4/2022-01-elasticswap/blob/d107a198c0d10fbe254d69ffe5be3e40894ff078/elasticswap/src/contracts/Exchange.sol#L27-L28

Tools Used

Visual Studio Code, Remix

Recommended Mitigation Steps

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
0xean commented 2 years ago

dupe of #158