Skip to content
This repository has been archived by the owner on Mar 12, 2024. It is now read-only.

Commit

Permalink
fix(contracts): input size limit check
Browse files Browse the repository at this point in the history
  • Loading branch information
guidanoli committed Jun 26, 2023
1 parent 495a12c commit 0308f24
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 12 deletions.
5 changes: 3 additions & 2 deletions onchain/rollups/contracts/common/CanonicalMachine.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ library CanonicalMachine {
/// @notice Keccak-256 output size (32 bytes).
Log2Size constant KECCAK_LOG2_SIZE = Log2Size.wrap(5);

/// @notice Maximum input size (32 megabytes).
Log2Size constant INPUT_MAX_LOG2_SIZE = Log2Size.wrap(25);
/// @notice Maximum input size (~2 megabytes).
/// @dev The offset and size fields use up the extra 64 bytes.
uint256 constant INPUT_MAX_SIZE = (1 << 21) - 64;

/// @notice Maximum voucher metadata memory range (2 megabytes).
Log2Size constant VOUCHER_METADATA_LOG2_SIZE = Log2Size.wrap(21);
Expand Down
7 changes: 1 addition & 6 deletions onchain/rollups/contracts/library/LibInput.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,7 @@ library LibInput {
bytes calldata input,
uint256 inboxInputIndex
) internal pure returns (bytes32) {
// Currently sending an input larger than driveSize surpasses the block gas limit
// But we keep the following check in case this changes in the future
if (
input.length >
(1 << CanonicalMachine.INPUT_MAX_LOG2_SIZE.uint64OfSize())
) {
if (input.length > CanonicalMachine.INPUT_MAX_SIZE) {
revert InputSizeExceedsLimit();
}

Expand Down
5 changes: 1 addition & 4 deletions onchain/rollups/test/foundry/inputs/InputBox.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,7 @@ contract InputBoxTest is Test {

// assume #bytes for each input is within bounds
for (uint256 i; i < numInputs; ++i) {
vm.assume(
_inputs[i].length <=
(1 << CanonicalMachine.INPUT_MAX_LOG2_SIZE.uint64OfSize())
);
vm.assume(_inputs[i].length <= CanonicalMachine.INPUT_MAX_SIZE);
}

// adding inputs
Expand Down

0 comments on commit 0308f24

Please sign in to comment.