UNPKG

@unruggable/gateways

Version:

Trustless Ethereum Multichain CCIP-Read Gateway

54 lines (53 loc) 2.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LineaGatewayV1 = void 0; const types_js_1 = require("./types.cjs"); const gateway_js_1 = require("../gateway.cjs"); const utils_js_1 = require("../utils.cjs"); const vm_js_1 = require("../vm.cjs"); // 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) class LineaGatewayV1 extends gateway_js_1.GatewayV1 { async handleRequest(commit, request) { const state = await commit.prover.evalRequest(request.v2()); const { target, slots } = (0, vm_js_1.requireV1Needs)(state.needs); const proofs = await commit.prover.getProofs(target, slots); if (!(0, types_js_1.isInclusionProof)(proofs.accountProof)) { throw new Error(`not a contract: ${request.target}`); } const witness = utils_js_1.ABI_CODER.encode([ 'uint256', '(address, uint256, (bytes, bytes[]))', '(bytes32, uint256, (bytes32, bytes[]), bool)[]', ], [ commit.index, encodeAccountProof(proofs.accountProof), proofs.storageProofs.map(encodeStorageProof), ]); return utils_js_1.ABI_CODER.encode(['bytes'], [witness]); } } exports.LineaGatewayV1 = LineaGatewayV1; function encodeAccountProof(proof) { return [ proof.key, proof.leafIndex, [proof.proof.value, proof.proof.proofRelatedNodes], ]; } function encodeStorageProof(proof) { return (0, types_js_1.isInclusionProof)(proof) ? [ proof.key, proof.leafIndex, [proof.proof.value, proof.proof.proofRelatedNodes], true, ] : [ proof.key, proof.leftLeafIndex, [proof.leftProof.value, proof.leftProof.proofRelatedNodes], false, ]; }