diff --git a/contracts/base/AppStateVerifier.sol b/contracts/base/AppStateVerifier.sol index 51dea2d..a9c2438 100644 --- a/contracts/base/AppStateVerifier.sol +++ b/contracts/base/AppStateVerifier.sol @@ -18,7 +18,9 @@ pragma solidity 0.8.15; import {RLPReader} from "optimism/libraries/rlp/RLPReader.sol"; -import {IAppStateVerifier, Ics23Proof, OpIcs23Proof} from "../interfaces/IProofVerifier.sol"; + +import {IAppStateVerifier} from "../interfaces/IAppStateVerifier.sol"; +import {Ics23Proof, OpIcs23Proof} from "../libs/ReceiptParser.sol"; /** * @title OptimisticProofVerifier diff --git a/contracts/core/CrossL2Prover.sol b/contracts/core/CrossL2Prover.sol index b80ac29..06de52f 100644 --- a/contracts/core/CrossL2Prover.sol +++ b/contracts/core/CrossL2Prover.sol @@ -20,12 +20,12 @@ pragma solidity 0.8.15; import {RLPReader} from "optimism/libraries/rlp/RLPReader.sol"; import {MerkleTrie} from "optimism/libraries/trie/MerkleTrie.sol"; import {Bytes} from "optimism/libraries/Bytes.sol"; -import {ReceiptParser} from "../../libs/ReceiptParser.sol"; -import {AppStateVerifier} from "../../base/AppStateVerifier.sol"; -import {ICrossL2Prover} from "../../interfaces/ICrossL2Prover.sol"; -import {Ics23Proof} from "../../interfaces/IProofVerifier.sol"; -import {ISignatureVerifier} from "../../interfaces/ISignatureVerifier.sol"; -import {LightClientType} from "../../interfaces/IClientUpdates.sol"; +import {ReceiptParser} from "../libs/ReceiptParser.sol"; +import {AppStateVerifier} from "../base/AppStateVerifier.sol"; +import {ICrossL2Prover} from "../interfaces/ICrossL2Prover.sol"; +import {Ics23Proof} from "../libs/ReceiptParser.sol"; +import {ISignatureVerifier} from "../interfaces/ISignatureVerifier.sol"; +import {LightClientType} from "../interfaces/IClientUpdates.sol"; contract CrossL2Prover is AppStateVerifier, ICrossL2Prover { LightClientType public constant LIGHT_CLIENT_TYPE = LightClientType.SequencerLightClient; // Stored as a constant diff --git a/contracts/interfaces/IAppStateVerifier.sol b/contracts/interfaces/IAppStateVerifier.sol index c8fbb65..8c137ea 100644 --- a/contracts/interfaces/IAppStateVerifier.sol +++ b/contracts/interfaces/IAppStateVerifier.sol @@ -16,34 +16,7 @@ */ pragma solidity ^0.8.0; -// OpIcs23ProofPath represents a commitment path in an ICS23 proof, which consists of a commitment prefix and a suffix. -struct OpIcs23ProofPath { - bytes prefix; - bytes suffix; -} - -// OpIcs23Proof represents an ICS23 proof -struct OpIcs23Proof { - OpIcs23ProofPath[] path; - bytes key; - bytes value; - bytes prefix; -} - -// the Ics23 proof related structs are used to do membership verification. These are not the actual Ics23 -// format but a "solidity friendly" version of it - data is the same just packaged differently -struct Ics23Proof { - OpIcs23Proof[] proof; - uint256 height; -} - -// This is the proof we use to verify the apphash (state) updates. -struct OpL2StateProof { - bytes[] accountProof; - bytes[] outputRootProof; - bytes32 l2OutputProposalKey; - bytes32 l2BlockHash; -} +import {Ics23Proof} from "../libs/ReceiptParser.sol"; // The `header` field is a list of RLP encoded L1 header fields. Both stateRoot and number are not // encoded for easy usage. They must match with their RLP encoded counterparty versions. @@ -86,4 +59,3 @@ interface IAppStateVerifier { */ function verifyNonMembership(bytes32 appHash, bytes calldata key, Ics23Proof calldata proof) external pure; } - diff --git a/contracts/interfaces/IClientUpdates.sol b/contracts/interfaces/IClientUpdates.sol index 9ac7bc9..7634437 100644 --- a/contracts/interfaces/IClientUpdates.sol +++ b/contracts/interfaces/IClientUpdates.sol @@ -16,7 +16,7 @@ */ pragma solidity ^0.8.0; -import {Ics23Proof} from "./IProofVerifier.sol"; +import {Ics23Proof} from "../libs/ReceiptParser.sol"; enum LightClientType { SimTestLightClient, // Note: not deployed on any mainnets diff --git a/contracts/interfaces/ICrossL2Prover.sol b/contracts/interfaces/ICrossL2Prover.sol index bff839e..6ea0f84 100644 --- a/contracts/interfaces/ICrossL2Prover.sol +++ b/contracts/interfaces/ICrossL2Prover.sol @@ -16,8 +16,8 @@ */ pragma solidity ^0.8.0; -import {Ics23Proof} from "./IProofVerifier.sol"; import {IClientUpdates} from "./IClientUpdates.sol"; +import {Ics23Proof} from "../libs/ReceiptParser.sol"; /** * @title ICrossL2Prover diff --git a/contracts/interfaces/ISignatureVerifier.sol b/contracts/interfaces/ISignatureVerifier.sol index 80d87cf..5294069 100644 --- a/contracts/interfaces/ISignatureVerifier.sol +++ b/contracts/interfaces/ISignatureVerifier.sol @@ -16,7 +16,7 @@ */ pragma solidity ^0.8.0; -import {IAppStateVerifier} from "./AppStateverifier.sol"; +import {IAppStateVerifier} from "./IAppStateVerifier.sol"; /** * @title ISignatureVerifier diff --git a/contracts/libs/ReceiptParser.sol b/contracts/libs/ReceiptParser.sol index 12124ee..b8a2261 100644 --- a/contracts/libs/ReceiptParser.sol +++ b/contracts/libs/ReceiptParser.sol @@ -19,14 +19,59 @@ pragma solidity ^0.8.0; import {RLPReader} from "optimism/libraries/rlp/RLPReader.sol"; import {Bytes} from "optimism/libraries/Bytes.sol"; -import {ProtoChannel, ProtoCounterparty} from "proto/channel.sol"; -import {Base64} from "base64/base64.sol"; +// OpIcs23ProofPath represents a commitment path in an ICS23 proof, which consists of a commitment prefix and a suffix. +struct OpIcs23ProofPath { + bytes prefix; + bytes suffix; +} + +// OpIcs23Proof represents an ICS23 proof +struct OpIcs23Proof { + OpIcs23ProofPath[] path; + bytes key; + bytes value; + bytes prefix; +} + +// the Ics23 proof related structs are used to do membership verification. These are not the actual Ics23 +// format but a "solidity friendly" version of it - data is the same just packaged differently +struct Ics23Proof { + OpIcs23Proof[] proof; + uint256 height; +} /** * A library for helpers for proving peptide state */ library ReceiptParser { + error invalidAddressBytes(); + + function toStr(uint256 _number) public pure returns (string memory outStr) { + if (_number == 0) { + return "0"; + } + + uint256 length; + uint256 number = _number; + + // Determine the length of the string + while (number != 0) { + length++; + number /= 10; + } + + bytes memory buffer = new bytes(length); + + // Convert each digit to its ASCII representation + for (uint256 i = length; i > 0; i--) { + buffer[i - 1] = bytes1(uint8(48 + (_number % 10))); + _number /= 10; + } + + outStr = string(buffer); + } + function bytesToAddr(bytes memory a) public pure returns (address addr) { if (a.length != 20) { revert invalidAddressBytes(); @@ -36,8 +81,6 @@ library ReceiptParser { } } - - function parseLog(uint256 logIndex, bytes memory receiptRLP) internal pure