Skip to content

Commit

Permalink
Implement read sequence signature
Browse files Browse the repository at this point in the history
  • Loading branch information
Agusx1211 committed Jan 23, 2024
1 parent faa80f3 commit c476938
Show file tree
Hide file tree
Showing 3 changed files with 201 additions and 105 deletions.
28 changes: 27 additions & 1 deletion foundry_test/modules/utils/L2CompressorEncoder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -274,4 +274,30 @@ function encode_nested(uint8 _weight, uint8 _threshold, bytes memory _nested) pu

function encode_dynamic_signature(uint8 _weight, address _signer, bytes memory _signature) pure returns (bytes memory) {
return abi.encodePacked(uint8(0x44), uint8(_weight), encodeWord(uint256(uint160(_signer))), encode_bytes_n(_signature));
}
}

function encode_sequence_signature(bool _noChainId, uint256 _threshold, uint32 _checkpoint, bytes memory _tree) pure returns (bytes memory) {
uint8 flag;

bytes memory t;

if (_noChainId) {
if (_threshold <= type(uint8).max) {
flag = 0x45;
t = abi.encodePacked(uint8(_threshold));
} else {
flag = 0x47;
t = abi.encodePacked(uint16(_threshold));
}
} else {
if (_threshold <= type(uint8).max) {
flag = 0x46;
t = abi.encodePacked(uint8(_threshold));
} else {
flag = 0x48;
t = abi.encodePacked(uint16(_threshold));
}
}

return abi.encodePacked(flag, t, encodeWord(_checkpoint), encode_bytes_n(_tree));
}
15 changes: 15 additions & 0 deletions foundry_test/modules/utils/L2CompressorHuffReadFlag.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -517,4 +517,19 @@ contract L2CompressorHuffReadFlagTests is AdvTest {

assertEq(res, abi.encodePacked(uint8(2), uint8(_weight), _signer, uint24(_signature.length + 1), _signature, uint8(3)));
}

function test_read_sequence_signature(bool _noChainId, uint16 _threshold, uint32 _checkpoint, bytes memory _tree) external {
bytes memory encoded = encode_sequence_signature(_noChainId, _threshold, _checkpoint, _tree);

(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, FMS + res.length);

assertEq(res, abi.encodePacked(uint8(_noChainId ? 0x02 : 0x01), uint16(_threshold), uint32(_checkpoint), _tree));
}
}
Loading

0 comments on commit c476938

Please sign in to comment.