Skip to content

Commit

Permalink
update gas report
Browse files Browse the repository at this point in the history
  • Loading branch information
massun-onibakuchi committed Jun 11, 2024
1 parent 107d5a3 commit e723f00
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 34 deletions.
49 changes: 27 additions & 22 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
GrimReaperHuffTest:testFuzz_Liquidate(uint256,address) (runs: 257, μ: 390297, ~: 390502)
GrimReaperHuffTest:testLiquidate() (gas: 390429)
GrimReaperHuffTest:testOnlyOwner(address) (runs: 257, μ: 20250, ~: 20250)
GrimReaperHuffL2Test:testFuzz_Liquidate(uint256,address) (runs: 257, μ: 387782, ~: 387988)
GrimReaperHuffL2Test:testGas_Liquidate() (gas: 387679)
GrimReaperHuffL2Test:testLiquidate() (gas: 387916)
GrimReaperHuffL2Test:testOnlyOwner(address) (runs: 257, μ: 17038, ~: 17038)
GrimReaperHuffL2Test:testRecoverERC20() (gas: 330913)
GrimReaperHuffL2Test:testRevertIfLiquidationFail() (gas: 8937393460516725027)
GrimReaperHuffTest:testFuzz_Liquidate(uint256,address) (runs: 257, μ: 387670, ~: 387876)
GrimReaperHuffTest:testGas_Liquidate() (gas: 387574)
GrimReaperHuffTest:testLiquidate() (gas: 387804)
GrimReaperHuffTest:testOnlyOwner(address) (runs: 257, μ: 16936, ~: 16936)
GrimReaperHuffTest:testRecoverERC20() (gas: 330913)
GrimReaperHuffTest:testRevertIfLiquidationFail() (gas: 8937393460516728353)
GrimReaperHuffV2Test:testFuzz_Liquidate(uint256,address) (runs: 257, μ: 390456, ~: 390662)
GrimReaperHuffV2Test:testLiquidate() (gas: 390588)
GrimReaperHuffV2Test:testOnlyOwner(address) (runs: 257, μ: 20415, ~: 20415)
GrimReaperHuffV2Test:testRecoverERC20() (gas: 330913)
GrimReaperHuffV2Test:testRevertIfLiquidationFail() (gas: 8937393460516728359)
GrimReaperSolTest:testFuzz_Liquidate(uint256,address) (runs: 257, μ: 390936, ~: 391328)
GrimReaperSolTest:testLiquidate() (gas: 391254)
GrimReaperSolTest:testOnlyOwner(address) (runs: 257, μ: 21195, ~: 21195)
GrimReaperHuffTest:testRevertIfLiquidationFail() (gas: 8937393460516725026)
GrimReaperSolTest:testFuzz_Liquidate(uint256,address) (runs: 257, μ: 388301, ~: 388692)
GrimReaperSolTest:testGas_Liquidate() (gas: 388478)
GrimReaperSolTest:testLiquidate() (gas: 388619)
GrimReaperSolTest:testOnlyOwner(address) (runs: 257, μ: 17873, ~: 17873)
GrimReaperSolTest:testRecoverERC20() (gas: 331758)
GrimReaperSolTest:testRevertIfLiquidationFail() (gas: 52904)
OptimizedGrimReaperSolTest:testFuzz_Liquidate(uint256,address) (runs: 257, μ: 390378, ~: 390584)
OptimizedGrimReaperSolTest:testLiquidate() (gas: 390511)
OptimizedGrimReaperSolTest:testOnlyOwner(address) (runs: 257, μ: 20421, ~: 20421)
GrimReaperSolTest:testRevertIfLiquidationFail() (gas: 49702)
OptimizedGrimReaperSolL2Test:testFuzz_Liquidate(uint256,address) (runs: 257, μ: 387866, ~: 388072)
OptimizedGrimReaperSolL2Test:testGas_Liquidate() (gas: 387762)
OptimizedGrimReaperSolL2Test:testLiquidate() (gas: 387999)
OptimizedGrimReaperSolL2Test:testOnlyOwner(address) (runs: 257, μ: 17209, ~: 17209)
OptimizedGrimReaperSolL2Test:testRecoverERC20() (gas: 330891)
OptimizedGrimReaperSolL2Test:testRevertIfLiquidationFail() (gas: 48830)
OptimizedGrimReaperSolTest:testFuzz_Liquidate(uint256,address) (runs: 257, μ: 387762, ~: 387959)
OptimizedGrimReaperSolTest:testGas_Liquidate() (gas: 387656)
OptimizedGrimReaperSolTest:testLiquidate() (gas: 387885)
OptimizedGrimReaperSolTest:testOnlyOwner(address) (runs: 257, μ: 17107, ~: 17107)
OptimizedGrimReaperSolTest:testRecoverERC20() (gas: 330891)
OptimizedGrimReaperSolTest:testRevertIfLiquidationFail() (gas: 51884)
OptimizedGrimReaperSolV2Test:testFuzz_Liquidate(uint256,address) (runs: 257, μ: 390540, ~: 390745)
OptimizedGrimReaperSolV2Test:testLiquidate() (gas: 390672)
OptimizedGrimReaperSolV2Test:testOnlyOwner(address) (runs: 257, μ: 20586, ~: 20586)
OptimizedGrimReaperSolV2Test:testRecoverERC20() (gas: 330891)
OptimizedGrimReaperSolV2Test:testRevertIfLiquidationFail() (gas: 52085)
OptimizedGrimReaperSolTest:testRevertIfLiquidationFail() (gas: 48691)
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,31 +38,31 @@ For more information on how to use Foundry, check out the [Foundry Github Reposi

| Single Liquidation (Optimizer runs: 200) | Gas Used | Bytecode Size (kB) |
| ---------------------------------------- | -------- | ------------------ |
| Solidity Contract | 98783 | 1.005 |
| Assembly | 97679 | 0.303 |
| Assembly (GrimReaper V2) | 97648 | 0.317 + table |
| Huff Contract | 97597 | 0.231 |
| Huff Contract (GrimReaper V2) | 97564 | 0.243 + table |
| Solidity Contract | 94877 | 1.039 |
| Assembly | 94024 | 0.336 |
| Assembly (GrimReaper L2) | 94060 | 0.350 + table |
| Huff Contract | 93942 | 0.248 |
| Huff Contract (GrimReaper L2) | 93976 | 0.260 + table |

| Single Liquidation (Optimizer runs: 10_000_000) | Gas Used | Bytecode Size (kB) |
| ----------------------------------------------- | -------- | ------------------ |
| Solidity Contract | 98127 | 1.308 |
| Assembly | 97089 | 0.330 |
| Assembly (GrimReaper V2) | 97058 | 0.344 + table |
| Huff Contract | 97019 | 0.231 |
| Huff Contract (GrimReaper V2) | 96986 | 0.243 + table |
| Solidity Contract | 94301 | 1.342 |
| Assembly | 93508 | 0.363 |
| Assembly (GrimReaper L2) | 93544 | 0.377 + table |
| Huff Contract | 93438 | 0.248 |
| Huff Contract (GrimReaper L2) | 93472 | 0.260 + table |

> `66270` gas is used for the liquidation logic itself on mock Aave v3 pool.
> Note: Optimizer runs affects how well the compiler optimizes tests contract as well. So, it affects measurements.
- solc version: 0.8.24, evm version: cancun with `bytecode_hash = "none"` and `cbor_metadata = false`.
- `forge snapshot --fuzz-seed=111 -vv`
- `forge test -vv --mt=testGas_Liquidate`

## Further Optimization Ideas

- Support limited kinds of collateral tokens and remove `collateral` parameter from main entrypoint
- [x] O(1) selector table for token addresses. (`GrimReaper V2`)
- [x] O(1) selector table for token addresses to remove calldata size. (`GrimReaper L2`)
- [ ] Approve once on contract deployment instead of every liquidation
- Replace `jumpi` with other operations
- [x] Use `mload(type(uint256).max)` for `jumpi` if-else-revert pattern (`GrimReaperHuff`)
Expand Down

0 comments on commit e723f00

Please sign in to comment.