From 95ae5bc7ad8c08b2fc9b849186831e96baef0796 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 27 May 2024 16:24:49 +0200 Subject: [PATCH] Remove CircuitAbi & add abi utils --- ethereum/oracles/src/noir/circuit/abi.test.ts | 5 ++- ethereum/oracles/src/noir/circuit/abi.ts | 34 ++++++++----------- .../oracles/src/noir/circuit/verifierData.ts | 10 +++--- 3 files changed, 22 insertions(+), 27 deletions(-) diff --git a/ethereum/oracles/src/noir/circuit/abi.test.ts b/ethereum/oracles/src/noir/circuit/abi.test.ts index 25afd70a..13034b06 100644 --- a/ethereum/oracles/src/noir/circuit/abi.test.ts +++ b/ethereum/oracles/src/noir/circuit/abi.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from 'vitest'; -import { CircuitAbi } from './abi.js'; +import { publicInputs } from './abi.js'; import { Abi } from '@noir-lang/noirc_abi'; const type = { kind: 'field' } as const; @@ -15,8 +15,7 @@ describe('abi', () => { return_witnesses: [], error_types: {} }; - const circuitAbi = new CircuitAbi(abi); - expect(circuitAbi.public().parameters).toEqual([publicParam]); + expect(publicInputs(abi).parameters).toEqual([publicParam]); }); }); diff --git a/ethereum/oracles/src/noir/circuit/abi.ts b/ethereum/oracles/src/noir/circuit/abi.ts index 436fea4d..89b6e82e 100644 --- a/ethereum/oracles/src/noir/circuit/abi.ts +++ b/ethereum/oracles/src/noir/circuit/abi.ts @@ -1,23 +1,19 @@ import { Abi } from '@noir-lang/noirc_abi'; -export class CircuitAbi { - constructor(public abi: Abi) {} - - public public(): Abi { - const parameters = this.abi.parameters.filter((param) => param.visibility === 'public'); - return { - ...this.abi, - parameters - }; - } +export function publicInputs(abi: Abi): Abi { + const parameters = abi.parameters.filter((param) => param.visibility === 'public'); + return { + ...abi, + parameters + }; +} - public return(): Abi { - return { - parameters: [], - param_witnesses: {}, - error_types: {}, - return_type: this.abi.return_type, - return_witnesses: this.abi.return_witnesses - }; - } +export function returnValues(abi: Abi): Abi { + return { + parameters: [], + param_witnesses: {}, + error_types: {}, + return_type: abi.return_type, + return_witnesses: abi.return_witnesses + }; } diff --git a/ethereum/oracles/src/noir/circuit/verifierData.ts b/ethereum/oracles/src/noir/circuit/verifierData.ts index 7fd8317d..018c6d87 100644 --- a/ethereum/oracles/src/noir/circuit/verifierData.ts +++ b/ethereum/oracles/src/noir/circuit/verifierData.ts @@ -1,20 +1,20 @@ import { Abi, InputMap, abiEncode } from '@noir-lang/noirc_abi'; import { readTomlObject } from '../../util/file.js'; import { Hex } from 'viem'; -import { CircuitAbi } from './abi.js'; +import { publicInputs, returnValues } from './abi.js'; export class VerifierData { public static async create(verifierTomlPath: string, abi: Abi) { const verifierData = await readTomlObject(verifierTomlPath); - return new VerifierData(new CircuitAbi(abi), verifierData); + return new VerifierData(abi, verifierData); } public publicInputs(): Hex[] { - return this.encodeSubset(this.abi.public()); + return this.encodeSubset(publicInputs(this.abi)); } public returnValues(): Hex[] { - return this.encodeSubset(this.abi.return()); + return this.encodeSubset(returnValues(this.abi)); } public encodeSubset(subset: Abi): Hex[] { @@ -23,7 +23,7 @@ export class VerifierData { } private constructor( - private abi: CircuitAbi, + private abi: Abi, private verifierData: InputMap ) {} }