Skip to content

Commit

Permalink
working on foundry files
Browse files Browse the repository at this point in the history
  • Loading branch information
RnkSngh committed Jan 8, 2025
1 parent 147c642 commit a924cf5
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 43 deletions.
4 changes: 3 additions & 1 deletion contracts/base/AppStateVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions contracts/core/CrossL2Prover.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 1 addition & 29 deletions contracts/interfaces/IAppStateVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -86,4 +59,3 @@ interface IAppStateVerifier {
*/
function verifyNonMembership(bytes32 appHash, bytes calldata key, Ics23Proof calldata proof) external pure;
}

2 changes: 1 addition & 1 deletion contracts/interfaces/IClientUpdates.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/ICrossL2Prover.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/ISignatureVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
pragma solidity ^0.8.0;

import {IAppStateVerifier} from "./AppStateverifier.sol";
import {IAppStateVerifier} from "./IAppStateVerifier.sol";

/**
* @title ISignatureVerifier
Expand Down
51 changes: 47 additions & 4 deletions contracts/libs/ReceiptParser.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -36,8 +81,6 @@ library ReceiptParser {
}
}



function parseLog(uint256 logIndex, bytes memory receiptRLP)
internal
pure
Expand Down

0 comments on commit a924cf5

Please sign in to comment.