Skip to content

Commit

Permalink
Implement read chained signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
Agusx1211 committed Jan 24, 2024
1 parent c476938 commit 0dc7809
Show file tree
Hide file tree
Showing 3 changed files with 191 additions and 59 deletions.
16 changes: 16 additions & 0 deletions foundry_test/modules/utils/L2CompressorEncoder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -301,3 +301,19 @@ function encode_sequence_signature(bool _noChainId, uint256 _threshold, uint32 _

return abi.encodePacked(flag, t, encodeWord(_checkpoint), encode_bytes_n(_tree));
}

function encode_sequence_chained_signatures(bytes[] memory _payloads) pure returns (bytes memory) {
bytes memory encoded;

if (_payloads.length > type(uint8).max) {
encoded = abi.encodePacked(uint8(0x4a), uint16(_payloads.length));
} else {
encoded = abi.encodePacked(uint8(0x49), uint8(_payloads.length));
}

for (uint256 i = 0; i < _payloads.length; i++) {
encoded = abi.encodePacked(encoded, encode_bytes_n(_payloads[i]));
}

return encoded;
}
25 changes: 25 additions & 0 deletions foundry_test/modules/utils/L2CompressorHuffReadFlag.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -532,4 +532,29 @@ contract L2CompressorHuffReadFlagTests is AdvTest {

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

function test_read_sequence_chained_signatures(bytes[] memory _signatures) external {
vm.assume(_signatures.length != 0);
for (uint256 i = 0; i < _signatures.length; i++) {
vm.assume(_signatures[i].length <= type(uint24).max);
}

bytes memory encoded = encode_sequence_chained_signatures(_signatures);

(bool s, bytes memory r) = imp.staticcall(encoded);
assertTrue(s);

(uint256 rindex, uint256 windex, bytes memory res) = abi.decode(r, (uint256, uint256, bytes));

assertEq(windex, FMS + res.length);
assertEq(rindex, encoded.length);

bytes memory expected = abi.encodePacked(uint8(0x03), uint24(_signatures.length));

for (uint256 i = 0; i < _signatures.length; i++) {
expected = abi.encodePacked(expected, uint24(_signatures[i].length), _signatures[i]);
}

assertEq(res, expected);
}
}
Loading

0 comments on commit 0dc7809

Please sign in to comment.