Skip to content

Commit

Permalink
Remove CircuitAbi & add abi utils
Browse files Browse the repository at this point in the history
  • Loading branch information
LogvinovLeon committed May 28, 2024
1 parent 93f1254 commit 7027a09
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 27 deletions.
5 changes: 2 additions & 3 deletions ethereum/oracles/src/noir/circuit/abi.test.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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]);
});
});
34 changes: 15 additions & 19 deletions ethereum/oracles/src/noir/circuit/abi.ts
Original file line number Diff line number Diff line change
@@ -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
};
}
10 changes: 5 additions & 5 deletions ethereum/oracles/src/noir/circuit/verifierData.ts
Original file line number Diff line number Diff line change
@@ -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<InputMap>(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[] {
Expand All @@ -23,7 +23,7 @@ export class VerifierData {
}

private constructor(
private abi: CircuitAbi,
private abi: Abi,
private verifierData: InputMap
) {}
}

0 comments on commit 7027a09

Please sign in to comment.