-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
85 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
[submodule "lib/forge-std"] | ||
path = lib/forge-std | ||
url = https://github.com/foundry-rs/forge-std | ||
[submodule "lib/foundry-huff"] | ||
path = lib/foundry-huff | ||
url = https://github.com/huff-language/foundry-huff |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ src = 'contracts' | |
out = 'foundry_artifacts' | ||
libs = ["node_modules", "lib"] | ||
test = 'foundry_test' | ||
ffi = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.13; | ||
|
||
import "foundry_test/base/AdvTest.sol"; | ||
|
||
import { HuffConfig } from "foundry-huff/HuffConfig.sol"; | ||
import { HuffDeployer } from "foundry-huff/HuffDeployer.sol"; | ||
|
||
interface L2CompressorImps { | ||
function testLoadDynamicSize( | ||
bytes32 _a, | ||
bytes32 _b, | ||
uint256 rindex, | ||
uint256 size | ||
) external pure returns (uint256, uint256); | ||
} | ||
|
||
contract L2CompressorHuffTests is Test { | ||
L2CompressorImps public imp; | ||
|
||
function setUp() public { | ||
imp = L2CompressorImps( | ||
HuffDeployer | ||
.config() | ||
.with_evm_version("paris") | ||
.deploy("imps/L2CompressorImps") | ||
); | ||
} | ||
|
||
function test_load_dynamic_size() external { | ||
(uint256 size, uint256 rindex) = imp.testLoadDynamicSize( | ||
bytes32(0x082366f82de6ef3a1d439d0adbfa2ee606f86c2774b4d946f895dfc1f88443a2), | ||
bytes32(0), | ||
4, | ||
1 | ||
); | ||
|
||
assertEq(size, 8); | ||
assertEq(rindex, 5); | ||
|
||
(size, rindex) = imp.testLoadDynamicSize( | ||
bytes32(0x082366f82de6ef3a1d439d0adbfa2ee606f86c2774b4d946f895dfc1f88443a2), | ||
bytes32(0), | ||
4 + 32 - 3, | ||
2219024896 | ||
); | ||
} | ||
} |
Submodule foundry-huff
added at
7648fa
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include "../L2Compressor.huff" | ||
|
||
#define function testLoadDynamicSize(bytes32 _a, bytes32 _b, uint256, uint256) view returns (uint256, uint256) | ||
|
||
// Function Dispatching | ||
#define macro MAIN() = takes (1) returns (1) { | ||
// Identify which function is being called. | ||
0x00 calldataload 0xE0 shr // [func_sig] | ||
|
||
dup1 __FUNC_SIG(testLoadDynamicSize) eq testLoadDynamicSize jumpi | ||
|
||
// Revert if no match is found. | ||
0x00 dup1 revert | ||
|
||
testLoadDynamicSize: | ||
IMP_LOAD_DYNAMIC_SIZE() | ||
} | ||
|
||
#define macro IMP_LOAD_DYNAMIC_SIZE() = takes (2) returns (0) { | ||
0x04 0x40 add calldataload // [rindex] | ||
0x04 0x60 add calldataload // [size, rindex] | ||
|
||
LOAD_DYNAMIC_SIZE() // [size bits, rindex + size] | ||
|
||
0x00 mstore // [rindex + size] | ||
0x20 mstore // [] | ||
|
||
0x40 0x00 return | ||
} |