UNPKG

@unruggable/gateways

Version:

Trustless Ethereum Multichain CCIP-Read Gateway

50 lines (49 loc) 1.84 kB
import { isInclusionProof } from './types.mjs'; import { GatewayV1 } from '../gateway.mjs'; import { ABI_CODER } from '../utils.mjs'; import { requireV1Needs } from '../vm.mjs'; // https://github.com/Consensys/linea-ens/blob/main/packages/linea-ccip-gateway/src/L2ProofService.ts // the deployed linea verifier is not compatible with the current gateway design // due to strange proof encoding: incorrect negative proofs + unnecessary data (key) export class LineaGatewayV1 extends GatewayV1 { async handleRequest(commit, request) { const state = await commit.prover.evalRequest(request.v2()); const { target, slots } = requireV1Needs(state.needs); const proofs = await commit.prover.getProofs(target, slots); if (!isInclusionProof(proofs.accountProof)) { throw new Error(`not a contract: ${request.target}`); } const witness = ABI_CODER.encode([ 'uint256', '(address, uint256, (bytes, bytes[]))', '(bytes32, uint256, (bytes32, bytes[]), bool)[]', ], [ commit.index, encodeAccountProof(proofs.accountProof), proofs.storageProofs.map(encodeStorageProof), ]); return ABI_CODER.encode(['bytes'], [witness]); } } function encodeAccountProof(proof) { return [ proof.key, proof.leafIndex, [proof.proof.value, proof.proof.proofRelatedNodes], ]; } function encodeStorageProof(proof) { return isInclusionProof(proof) ? [ proof.key, proof.leafIndex, [proof.proof.value, proof.proof.proofRelatedNodes], true, ] : [ proof.key, proof.leftLeafIndex, [proof.leftProof.value, proof.leftProof.proofRelatedNodes], false, ]; }