UNPKG

@unruggable/gateways

Version:

Trustless Ethereum Multichain CCIP-Read Gateway

75 lines (74 loc) 2.49 kB
import { Interface } from 'ethers/abi'; import { ABI_CODER, NULL_CODE_HASH } from '../utils.mjs'; import { dataSlice } from 'ethers/utils'; export const ROLLUP_ABI = new Interface([ // ZkEvmV2.sol `function currentL2BlockNumber() view returns (uint256)`, `function stateRootHashes(uint256 l2BlockNumber) view returns (bytes32)`, `function shnarfFinalBlockNumbers(bytes32 shnarf) external view returns (uint256)`, // ILineaRollup.sol `event DataFinalized( uint256 indexed lastBlockFinalized, bytes32 indexed startingRootHash, bytes32 indexed finalRootHash, bool withProof )`, `event DataFinalizedV3( uint256 indexed startBlockNumber, uint256 indexed endBlockNumber, bytes32 indexed shnarf, bytes32 parentStateRootHash, bytes32 finalStateRootHash )`, `event DataSubmittedV3( bytes32 parentShnarf, bytes32 indexed shnarf, bytes32 finalStateRootHash )`, `function submitBlobs( ( uint256 dataEvaluationClaim, bytes kzgCommitment, bytes kzgProof, bytes32 finalStateRootHash, bytes32 snarkHash, )[] blobSubmissionData, bytes32 parentShnarf, bytes32 finalBlobShnarf ) external`, // IZkEvmV2.sol `event BlocksVerificationDone( uint256 indexed lastBlockFinalized, bytes32 startingRootHash, bytes32 finalRootHash )`, ]); export function isInclusionProof(proof) { return 'leafIndex' in proof; } //const NULL_CODE_HASH = '0x0134373b65f439c874734ff51ea349327c140cde2e47a933146e6f9f2ad8eb17'; // mimc(ZeroHash) export function isContract(accountProof) { return (isInclusionProof(accountProof) && // https://github.com/Consensys/linea-monorepo/blob/a001342170768a22988a29b2dca8601199c6e205/contracts/contracts/lib/SparseMerkleProof.sol#L23 dataSlice(accountProof.proof.value, 128, 160) !== NULL_CODE_HASH); } export function encodeProof(proof) { const T = '(uint256, bytes, bytes[])'; return ABI_CODER.encode([T, T], isInclusionProof(proof) ? [ [proof.leafIndex, proof.proof.value, proof.proof.proofRelatedNodes], [0, '0x', []], ] : [ [ proof.leftLeafIndex, proof.leftProof.value, proof.leftProof.proofRelatedNodes, ], [ proof.rightLeafIndex, proof.rightProof.value, proof.rightProof.proofRelatedNodes, ], ]); }