Skip to content

Commit

Permalink
optimize(huff): reduce GrimReaperHuffV2 bytecode size
Browse files Browse the repository at this point in the history
  • Loading branch information
massun-onibakuchi committed Jun 9, 2024
1 parent de8bdea commit 9b80fac
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ GrimReaperHuffTest:testLiquidate() (gas: 390429)
GrimReaperHuffTest:testOnlyOwner(address) (runs: 257, μ: 20250, ~: 20250)
GrimReaperHuffTest:testRecoverERC20() (gas: 330913)
GrimReaperHuffTest:testRevertIfLiquidationFail() (gas: 8937393460516728353)
GrimReaperHuffV2Test:testFuzz_Liquidate(uint256,address) (runs: 257, μ: 390456, ~: 390661)
GrimReaperHuffV2Test:testFuzz_Liquidate(uint256,address) (runs: 257, μ: 390456, ~: 390662)
GrimReaperHuffV2Test:testLiquidate() (gas: 390588)
GrimReaperHuffV2Test:testOnlyOwner(address) (runs: 257, μ: 20415, ~: 20415)
GrimReaperHuffV2Test:testRecoverERC20() (gas: 330913)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ For more information on how to use Foundry, check out the [Foundry Github Reposi
| Assembly | 97679 | 0.303 |
| Assembly (GrimReaper V2) | 97648 | 0.317 + table |
| Huff Contract | 97597 | 0.231 |
| Huff Contract (GrimReaper V2) | 97564 | 0.244 + table |
| Huff Contract (GrimReaper V2) | 97564 | 0.243 + 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.244 + table |
| Huff Contract (GrimReaper V2) | 96986 | 0.243 + table |

> `66270` gas is used for the liquidation logic itself on mock Aave v3 pool.
Expand Down
8 changes: 4 additions & 4 deletions src/GrimReaperV2.huff
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@
__FUNC_SIG(liquidationCall) 0xe0 shl 0x00 mstore // [debt, collateralId, user, debtToCover]
0x24 mstore // [collateralId, user, debtToCover]
// Copy the collateral asset address to memory from a table appended to the bytecode
0x20 mul // [0x20 * collateralId, user, debtToCover]
0x20 swap1 // [0x20 * collateralId, 0x20, user, debtToCover]
[COLLATERAL_ASSETS_TABLE_OFFSET] codesize sub // [codesize - offset, 0x14 * collateralId, 0x20, user, debtToCover]
add // [add(codesize - offset, 0x14 * collateralId), 0x20, user, debtToCover]
0x20 swap1 // [collateralId, 0x20, user, debtToCover]
dup2 mul // [0x20 * collateralId, 0x20, user, debtToCover]
[COLLATERAL_ASSETS_TABLE_OFFSET] codesize sub // [codesize - offset, 0x20 * collateralId, 0x20, user, debtToCover]
add // [add(codesize - offset, 0x20 * collateralId), 0x20, user, debtToCover]
0x04 codecopy // [user, debtToCover]

0x44 mstore // [user, debtToCover]
Expand Down

0 comments on commit 9b80fac

Please sign in to comment.