-
Notifications
You must be signed in to change notification settings - Fork 51
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
3 changed files
with
134 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.13; | ||
|
||
import "foundry_test/base/AdvTest.sol"; | ||
|
||
import "forge-std/console.sol"; | ||
import "forge-std/console2.sol"; | ||
|
||
import { HuffConfig } from "foundry-huff/HuffConfig.sol"; | ||
import { HuffDeployer } from "foundry-huff/HuffDeployer.sol"; | ||
|
||
import "contracts/modules/commons/interfaces/IModuleCalls.sol"; | ||
|
||
uint256 constant FMS = 0xa0; | ||
|
||
import "./L2CompressorEncoder.sol"; | ||
|
||
contract L2CompressorHuffReadNonceTest is AdvTest { | ||
address public imp; | ||
|
||
function setUp() public { | ||
imp = address( | ||
HuffDeployer | ||
.config() | ||
.with_evm_version("paris") | ||
.deploy("imps/L2CompressorReadNonce") | ||
); | ||
} | ||
|
||
function test_read_simple_nonce() external { | ||
uint256 space = 76518466025766696338879503773554426820412884125; | ||
uint256 nonce = 29095922913147819529123945996; | ||
|
||
bytes32 compact = 0x0d6734e95e00251b768924d47d52db3270fcc49d5e039555a5312d84eb305e0c; | ||
|
||
bytes memory encoded = abi.encodePacked( | ||
encodeWord(space), encodeWord(nonce) | ||
); | ||
|
||
(bool s, bytes memory r) = imp.staticcall(encoded); | ||
|
||
assertTrue(s); | ||
(uint256 rindex, uint256 windex, bytes memory res) = abi.decode(r, (uint256, uint256, bytes)); | ||
assertEq(rindex, encoded.length); | ||
assertEq(windex, res.length + FMS); | ||
|
||
assertEq(compact, abi.decode(res, (bytes32))); | ||
} | ||
|
||
function test_read_nonce(uint160 _space, uint96 _nonce) external { | ||
bytes memory encoded = abi.encodePacked( | ||
encodeWord(_space), encodeWord(_nonce) | ||
); | ||
|
||
(bool s, bytes memory r) = imp.staticcall(encoded); | ||
|
||
assertTrue(s); | ||
(uint256 rindex, uint256 windex, bytes memory res) = abi.decode(r, (uint256, uint256, bytes)); | ||
assertEq(rindex, encoded.length); | ||
assertEq(windex, res.length + FMS); | ||
|
||
assertEq(abi.encodePacked(_space, _nonce), res); | ||
} | ||
} |
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,30 @@ | ||
#include "../L2Compressor.huff" | ||
|
||
#define constant FMS = 0xa0 | ||
|
||
// Function Dispatching | ||
#define macro MAIN() = takes (1) returns (1) { | ||
// readAdvanced with whatever calldata is passed | ||
// first 32 bytes returns the new rindex and the next 32 bytes returns the new windex | ||
|
||
0x00 // [rindex] | ||
[FMS] // [windex, rindex] | ||
|
||
READ_NONCE_STANDALONE() // [windex, rindex] | ||
|
||
[FMS] // [0xa0, windex, rindex] | ||
dup2 // [windex, 0xa0, windex, rindex] | ||
sub // [len, windex, rindex] | ||
|
||
swap2 // [rindex, windex, len] | ||
|
||
0x80 [FMS] sub mstore // [windex, len] | ||
0x60 [FMS] sub mstore // [len] | ||
|
||
0x60 0x40 [FMS] sub mstore // [len] | ||
dup1 0x20 [FMS] sub mstore // [len] | ||
|
||
0x80 add // [len + 0x80] | ||
|
||
0x80 [FMS] sub return | ||
} |