diff --git a/deploy/contracts/IStorageProofVerifier.sol b/deploy/contracts/IStorageProofVerifier.sol index 871c86f..b916927 100644 --- a/deploy/contracts/IStorageProofVerifier.sol +++ b/deploy/contracts/IStorageProofVerifier.sol @@ -23,6 +23,8 @@ interface IStorageProofVerifier { function verifyStorageProof( bytes calldata _blob, uint256[] calldata _init_params, - int256[][] calldata _columns_rotations + int256[][] calldata _columns_rotations, + bytes32 _root, + bytes32 _leaf ) external returns (bool result); } diff --git a/deploy/contracts/StorageProofVerifier.sol b/deploy/contracts/StorageProofVerifier.sol index 98064d8..25c8996 100644 --- a/deploy/contracts/StorageProofVerifier.sol +++ b/deploy/contracts/StorageProofVerifier.sol @@ -43,7 +43,9 @@ contract StorageProofVerifier is IStorageProofVerifier { function verifyStorageProof( bytes calldata _blob, uint256[] calldata _init_params, - int256[][] calldata _columns_rotations + int256[][] calldata _columns_rotations, + bytes32 _root, + bytes32 _leaf ) external returns (bool result) { result = IVerifier(verifier).verify(_blob, _init_params, _columns_rotations, gate_argument); diff --git a/deploy/hardhat.config.ts b/deploy/hardhat.config.ts index bb3b07b..3613f82 100644 --- a/deploy/hardhat.config.ts +++ b/deploy/hardhat.config.ts @@ -3,6 +3,7 @@ require('@openzeppelin/hardhat-upgrades'); require("@nomiclabs/hardhat-ethers"); import './tasks/deploy' +import './tasks/sendData' module.exports = { solidity: { diff --git a/deploy/tasks/sendData.ts b/deploy/tasks/sendData.ts new file mode 100644 index 0000000..223125c --- /dev/null +++ b/deploy/tasks/sendData.ts @@ -0,0 +1,41 @@ +import {task} from 'hardhat/config' +const {getAccountVerifierParams, getFileContents} = require("./utils") + +task("sendData", + "send beacon state verification request") + .addParam("blob", "blob file name") + .addParam("pubi", "public input") + .setAction(async ({blob, pubi}, {ethers, run}) => { + + // circit params --> init params, coloms rot + + const contract = '0x0000000000000000000000000000000000000000'; + const circuit_params_filepath = './contracts/circuit_params.json'; + + // ================== Data prep ================== + + const circuit_params_data = getAccountVerifierParams(circuit_params_filepath); + const columns_rotations = circuit_params_data.columns_rotations; + const init_params = circuit_params_data.init_params; + + const proof = getFileContents(blob); + const public_input = JSON.parse(getFileContents(pubi)); + + + // ================== Transaction ================== + + const [owner] = await ethers.getSigners(); + const StorageProofVerifier = await ethers.getContractFactory("StorageProofVerifier") + const stateVerifier_inst = StorageProofVerifier.attach(contract) + const stateVerifier = await stateVerifier_inst.connect(owner) + + const tx = await stateVerifier.verifyStorageProof( + proof, + init_params, + columns_rotations, + '0x' + public_input[0].root, + '0x' + public_input[1].leaf); + + const receipt = await tx.wait() + console.log(receipt) +}) diff --git a/deploy/tasks/utils.ts b/deploy/tasks/utils.ts new file mode 100644 index 0000000..eac495b --- /dev/null +++ b/deploy/tasks/utils.ts @@ -0,0 +1,67 @@ +const fs = require("fs"); +const path = require("path"); +const losslessJSON = require("lossless-json") +const {BigNumber} = require("ethers"); + + +function loadParamsFromFile(jsonFile) { + const named_params = losslessJSON.parse(fs.readFileSync(jsonFile, 'utf8')); + let params = {}; + params.init_params = []; + params.init_params.push(BigInt(named_params.modulus.value)); + params.init_params.push(BigInt(named_params.r.value)); + params.init_params.push(BigInt(named_params.max_degree.value)); + params.init_params.push(BigInt(named_params.lambda.value)); + params.init_params.push(BigInt(named_params.rows_amount.value)); + params.init_params.push(BigInt(named_params.omega.value)); + params.init_params.push(BigInt(named_params.D_omegas.length)); + for (let i in named_params.D_omegas) { + params.init_params.push(BigInt(named_params.D_omegas[i].value)) + } + params.init_params.push(named_params.step_list.length); + for (let i in named_params.step_list) { + params.init_params.push(BigInt(named_params.step_list[i].value)) + } + params.init_params.push(named_params.arithmetization_params.length); + for (let i in named_params.arithmetization_params) { + params.init_params.push(BigInt(named_params.arithmetization_params[i].value)) + } + + params.columns_rotations = []; + for (let i in named_params.columns_rotations) { + let r = [] + for (let j in named_params.columns_rotations[i]) { + r.push(BigInt(named_params.columns_rotations[i][j].value)); + } + params.columns_rotations.push(r); + } + return params; +} + +function getStateVerifierParams(baseParamsFile, scalarParamsFile) { + let params = {} + params['init_params'] = [[26048, 22920], [], []]; + params['columns_rotations'] = [[], []] + + // For proof 1 + let base_params = loadParamsFromFile(baseParamsFile); + params['init_params'][1] = base_params.init_params; + params['columns_rotations'][0] = base_params.columns_rotations; + + // For proof 2 + let scalar_params = loadParamsFromFile(scalarParamsFile); + params['init_params'][2] = scalar_params.init_params; + params['columns_rotations'][1] = scalar_params.columns_rotations; + return params; +} + +function getAccountVerifierParams(verifierParamsFile) { + let account_path_params = loadParamsFromFile(verifierParamsFile); + return account_path_params; +} + +function getFileContents(filePath) { + return fs.readFileSync(filePath, 'utf8'); +} + +module.exports = { getStateVerifierParams , getAccountVerifierParams,getFileContents}; \ No newline at end of file