Skip to content

Commit

Permalink
Add a test that incorrect proof returned from oracle is failing in na…
Browse files Browse the repository at this point in the history
…rgo prove
  • Loading branch information
LogvinovLeon committed Feb 12, 2024
1 parent c660a24 commit 2829bc8
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/circuits_failing_proof_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: circuit failing proof test

on: [push]

jobs:
test:
name: nargo test
runs-on: ubuntu-latest
environment: CI
env:
ETHEREUM_JSON_RPC_API_URL: ${{ secrets.ETHEREUM_JSON_RPC_API_URL }}

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install Nargo
uses: noir-lang/noirup@v0.1.3
with:
toolchain: 0.23.0

- name: Use Node.js 20.x
uses: actions/setup-node@v3
with:
node-version: '20.x'

- name: Enable Corepack and Install Yarn 4
run: |
corepack enable
yarn set version latest
- name: Install Dependencies
run: yarn install

- name: Start Faulty Oracle Server
env:
RETURN_INVALID_PROOF: true
working-directory: packages/noir-ethereum-api
run: |
yarn oracle-server &
ORACLE_SERVER_PID=$!
echo "ORACLE_SERVER_PID=$ORACLE_SERVER_PID" >> $GITHUB_ENV
- name: Generate Proof
run: |
! nargo prove --package main --oracle-resolver=http://localhost:5555
- name: Stop Faulty Oracle Server
if: always()
run: kill $ORACLE_SERVER_PID
6 changes: 6 additions & 0 deletions packages/noir-ethereum-api/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
# noir-ethereum-api

## Oracle server

### Configuration

Pass `RETURN_INVALID_PROOF=true` to return incorrect proofs. By default correct proofs are returned
7 changes: 5 additions & 2 deletions packages/noir-ethereum-api/src/noir/oracles/accountOracles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { type ForeignCallOutput } from '@noir-lang/noir_js';
import { fromRlp, type GetProofReturnType, type Hex, isHex, type PublicClient } from 'viem';
import { assert } from '../../util/assert.js';
import { decodeField, decodeHexAddress, encodeField, encodeHex, encodeU120, encodeU64 } from './encode.js';
import { padArray } from '../../util/array.js';
import { alterArray, padArray } from '../../util/array.js';
import { NoirArguments } from './oracles.js';

const PROOF_ONE_LEVEL_LENGTH = 532;
Expand Down Expand Up @@ -53,8 +53,11 @@ export function encodeAccount(ethProof: GetProofReturnType): ForeignCallOutput[]

const key = encodeHex(ethProof.address);
const value = encodeValue(ethProof.accountProof);
const proof = encodeProof(ethProof.accountProof);
const correctProof = encodeProof(ethProof.accountProof);
const depth = encodeField(ethProof.accountProof.length);

const proof = process.env.RETURN_INVALID_PROOF === 'true' ? alterArray(correctProof) : correctProof;

return [nonce, balance, storageHash, codeHash, key, value, proof, depth];
}

Expand Down

0 comments on commit 2829bc8

Please sign in to comment.