github.com/ethereum-optimism/optimism@v1.7.2/packages/contracts-bedrock/scripts/fpac/SubmitLPP.sol (about)

     1  // SPDX-License-Identifier: MIT
     2  pragma solidity 0.8.15;
     3  
     4  import { PreimageOracle } from "src/cannon/PreimageOracle.sol";
     5  import { Script } from "forge-std/Script.sol";
     6  import { StdAssertions } from "forge-std/StdAssertions.sol";
     7  import "src/cannon/libraries/CannonTypes.sol";
     8  
     9  contract SubmitLPP is Script, StdAssertions {
    10      /// @notice Test UUID
    11      uint256 private constant TEST_UUID = uint256(keccak256("TEST_UUID"));
    12      /// @notice Number of bytes to submit to the preimage oracle.
    13      uint256 private constant BYTES_TO_SUBMIT = 4_012_000;
    14      /// @notice Chunk size to submit to the preimage oracle.
    15      uint256 private constant CHUNK_SIZE = 500 * 136;
    16  
    17      PreimageOracle private oracle;
    18  
    19      function post(address _po) external {
    20          // Bootstrap
    21          oracle = PreimageOracle(_po);
    22  
    23          // Allocate chunk - worst case w/ all bits set.
    24          bytes memory chunk = new bytes(CHUNK_SIZE);
    25          for (uint256 i; i < chunk.length; i++) {
    26              chunk[i] = 0xFF;
    27          }
    28  
    29          // Mock state commitments. Worst case w/ all bits set.
    30          bytes32[] memory mockStateCommitments = new bytes32[](CHUNK_SIZE / 136);
    31          bytes32[] memory mockStateCommitmentsLast = new bytes32[](CHUNK_SIZE / 136 + 1);
    32          for (uint256 i; i < mockStateCommitments.length; i++) {
    33              mockStateCommitments[i] = bytes32(type(uint256).max);
    34              mockStateCommitmentsLast[i] = bytes32(type(uint256).max);
    35          }
    36          // Assign last mock state commitment to all bits set.
    37          mockStateCommitmentsLast[mockStateCommitmentsLast.length - 1] = bytes32(type(uint256).max);
    38  
    39          vm.broadcast();
    40          oracle.initLPP({ _uuid: TEST_UUID, _partOffset: 0, _claimedSize: uint32(BYTES_TO_SUBMIT) });
    41  
    42          // Submit LPP in 500 * 136 byte chunks.
    43          for (uint256 i = 0; i < BYTES_TO_SUBMIT; i += CHUNK_SIZE) {
    44              bool finalize = i + CHUNK_SIZE >= BYTES_TO_SUBMIT;
    45  
    46              vm.broadcast();
    47              oracle.addLeavesLPP({
    48                  _uuid: TEST_UUID,
    49                  _inputStartBlock: i / 136,
    50                  _input: chunk,
    51                  _stateCommitments: finalize ? mockStateCommitmentsLast : mockStateCommitments,
    52                  _finalize: finalize
    53              });
    54          }
    55  
    56          // Assert that all bytes were submitted.
    57          LPPMetaData metaData = oracle.proposalMetadata(msg.sender, TEST_UUID);
    58          assertEq(metaData.bytesProcessed(), BYTES_TO_SUBMIT);
    59          assertEq(metaData.blocksProcessed(), (BYTES_TO_SUBMIT / 136) + 1);
    60      }
    61  }