Swivel v3 contest - 0xsam's results

The Capital-Efficient Protocol For Fixed-Rate Lending.

General Information

Platform: Code4rena

Start Date: 12/07/2022

Pot Size: $35,000 USDC

Total HM: 13

Participants: 78

Period: 3 days

Judge: 0xean

Total Solo HM: 6

Id: 135

League: ETH

Swivel

Findings Distribution

Researcher Performance

Rank: 69/78

Findings: 1

Award: $30.57

🌟 Selected for report: 0

🚀 Solo Findings: 0

Awards

30.5703 USDC - $30.57

Labels

bug
duplicate
G (Gas Optimization)
wontfix

External Links

Gas Optimization

Hardcode a constant value (0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) instead of using code to calculate (2**256 - 1)

File: Swivel/Swivel.sol uint256 max = 2**256 - 1;

https://github.com/code-423n4/2022-07-swivel/blob/daf72892d8a8d6eaa43b9e7d1924ccb0e612ee3c/Swivel/Swivel.sol#L549

++i costs less gas than i++

File: Swivel/Swivel.sol unchecked {i++;}

https://github.com/code-423n4/2022-07-swivel/blob/daf72892d8a8d6eaa43b9e7d1924ccb0e612ee3c/Swivel/Swivel.sol#L100

File: Swivel/Swivel.sol unchecked {i++;}

https://github.com/code-423n4/2022-07-swivel/blob/daf72892d8a8d6eaa43b9e7d1924ccb0e612ee3c/Swivel/Swivel.sol#L269

File: Swivel/Swivel.sol i++;

https://github.com/code-423n4/2022-07-swivel/blob/daf72892d8a8d6eaa43b9e7d1924ccb0e612ee3c/Swivel/Swivel.sol#L418

File: Swivel/Swivel.sol x++;

https://github.com/code-423n4/2022-07-swivel/blob/daf72892d8a8d6eaa43b9e7d1924ccb0e612ee3c/Swivel/Swivel.sol#L511

File: Swivel/Swivel.sol i++;

https://github.com/code-423n4/2022-07-swivel/blob/daf72892d8a8d6eaa43b9e7d1924ccb0e612ee3c/Swivel/Swivel.sol#L564

Use calculated amount instead of calculate again

File: Swivel/Swivel.sol // checks the side, and the amount compared to available uint256 amount = a + filled[hash]; if (amount > o.premium) { revert Exception(5, amount, o.premium, address(0), address(0)); } // TODO cheaper to assign amount here or keep the ADD? filled[hash] += a;

https://github.com/code-423n4/2022-07-swivel/blob/daf72892d8a8d6eaa43b9e7d1924ccb0e612ee3c/Swivel/Swivel.sol#L121

File: Swivel/Swivel.sol uint256 amount = a + filled[hash]; if (amount > o.principal) { revert Exception(5, amount, o.principal, address(0), address(0)); } // TODO assign amount or keep the ADD? filled[hash] += a;

https://github.com/code-423n4/2022-07-swivel/blob/daf72892d8a8d6eaa43b9e7d1924ccb0e612ee3c/Swivel/Swivel.sol#L158

File: Swivel/Swivel.sol uint256 amount = a + filled[hash]; if (amount > o.principal) { revert Exception(5, amount, o.principal, address(0), address(0)); } // TODO assign amount or keep the ADD? filled[hash] += a;

https://github.com/code-423n4/2022-07-swivel/blob/daf72892d8a8d6eaa43b9e7d1924ccb0e612ee3c/Swivel/Swivel.sol#L193

File: Swivel/Swivel.sol uint256 amount = a + filled[hash]; if (amount > o.premium) { revert Exception(5, amount, o.premium, address(0), address(0)); } // TODO assign amount or keep ADD? filled[hash] += a;

https://github.com/code-423n4/2022-07-swivel/blob/daf72892d8a8d6eaa43b9e7d1924ccb0e612ee3c/Swivel/Swivel.sol#L222

File: Swivel/Swivel.sol uint256 amount = a + filled[hash]; if (amount > o.premium) { revert Exception(5, amount, o.premium, address(0), address(0)); } // TODO assign amount or keep the ADD? filled[hash] += a;

https://github.com/code-423n4/2022-07-swivel/blob/daf72892d8a8d6eaa43b9e7d1924ccb0e612ee3c/Swivel/Swivel.sol#L287

File: Swivel/Swivel.sol uint256 amount = a + filled[hash]; if (amount > o.principal) { revert Exception(5, amount, o.principal, address(0), address(0)); } // TODO assign amount or keep the ADD? filled[hash] += a;

https://github.com/code-423n4/2022-07-swivel/blob/daf72892d8a8d6eaa43b9e7d1924ccb0e612ee3c/Swivel/Swivel.sol#L318

File: Swivel/Swivel.sol uint256 amount = a + filled[hash]; if (amount > o.principal) { revert Exception(5, amount, o.principal, address(0), address(0)); } // TODO assign amount or keep the ADD? filled[hash] += a;

https://github.com/code-423n4/2022-07-swivel/blob/daf72892d8a8d6eaa43b9e7d1924ccb0e612ee3c/Swivel/Swivel.sol#L348

File: Swivel/Swivel.sol uint256 amount = a + filled[hash]; if (amount > o.premium) { revert Exception(5, amount, o.premium, address(0), address(0)); } // TODO assign amount or keep the ADD? filled[hash] += a;

https://github.com/code-423n4/2022-07-swivel/blob/daf72892d8a8d6eaa43b9e7d1924ccb0e612ee3c/Swivel/Swivel.sol#L383

Use 4 variables instead of fixed length array of 4 elements to avoid cost of indexing

File: Swivel/Swivel.sol uint16[4] public feenominators;

https://github.com/code-423n4/2022-07-swivel/blob/daf72892d8a8d6eaa43b9e7d1924ccb0e612ee3c/Swivel/Swivel.sol#L37

AuditHub

A portfolio for auditors, a security profile for protocols, a hub for web3 security.

Built bymalatrax © 2024

Auditors

Browse

Contests

Browse

Get in touch

ContactTwitter