Skip to content

Commit

Permalink
Merge branch 'main' into leo/rlp-account
Browse files Browse the repository at this point in the history
  • Loading branch information
LogvinovLeon committed Feb 4, 2024
2 parents dea2504 + 47cbd17 commit 2a48fa9
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 24 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/ts_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,34 @@ jobs:
- name: Generate Proof
run: nargo prove --package main --oracle-resolver=http://localhost:5555

- name: Run nargo codegen-verifier
run: nargo codegen-verifier --package main

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Start Anvil
run: |
anvil &
ANVIL_PID=$!
echo "ANVIL_PID=$ANVIL_PID" >> $GITHUB_ENV
- name: Compile Smart Contract
working-directory: contracts
run: forge build

- name: Deploy Smart Contract
working-directory: contracts
run: forge create --rpc-url $ETH_RPC_URL --private-key $ANVIL_TEST_ACCOUNT_PRIVATE_KEY UltraVerifier
env:
ETH_RPC_URL: '127.0.0.1:8545'
ANVIL_TEST_ACCOUNT_PRIVATE_KEY: '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80'

- name: Run e2e Tests
run: yarn test:e2e

- name: Stop Anvil
if: always()
run: kill $ANVIL_PID
Binary file modified .yarn/install-state.gz
Binary file not shown.
4 changes: 4 additions & 0 deletions circuits/main/Prover.0.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Proving premine state in block 0. Has a tree depth of 4
block_no = "0"
address = ['0x8b', '0x50', '0x5E', '0x28', '0x71', '0xF7', '0xdE', '0xb7', '0xa6', '0x38', '0x95', '0x20', '0x8e', '0x82', '0x27', '0xdc', '0xAa', '0x1B', '0xff', '0x05']
state_root = ['0xd7', '0xf8', '0x97', '0x4f', '0xb5', '0xac', '0x78', '0xd9', '0xac', '0x09', '0x9b', '0x9a', '0xd5', '0x01', '0x8b', '0xed', '0xc2', '0xce', '0x0a', '0x72', '0xda', '0xd1', '0x82', '0x7a', '0x17', '0x09', '0xda', '0x30', '0x58', '0x0f', '0x05', '0x44']
26 changes: 2 additions & 24 deletions packages/noir-ethereum-api/src/noir/oracles/server.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
import { JSONRPCRequest, JSONRPCServer, TypedJSONRPCServer } from 'json-rpc-2.0';
import Fastify from 'fastify';
import { getHeaderHandler, getAccountHandler, JSONRPCServerMethods, ServerParams } from './server/handlers.js';
import { createDefaultClient } from '../../ethereum/client.js';
import { buildOracleServer } from './server/app.js';

const PORT = 5555;
const client = createDefaultClient();

const jsonRPCServer: TypedJSONRPCServer<JSONRPCServerMethods, ServerParams> = new JSONRPCServer();
const serverParams = { client };
jsonRPCServer.addMethod('get_header', getHeaderHandler);
jsonRPCServer.addMethod('get_account', getAccountHandler);

const app = Fastify({
const app = buildOracleServer({
logger: {
transport: {
target: 'pino-pretty',
Expand All @@ -23,19 +14,6 @@ const app = Fastify({
}
});

app.post('/', (request, reply) => {
const jsonRPCRequest = request.body as JSONRPCRequest;
request.log.info({ jsonRPCRequest }, 'Received request');

jsonRPCServer.receive(jsonRPCRequest, serverParams).then((jsonRPCResponse) => {
if (jsonRPCResponse) {
reply.send(jsonRPCResponse);
} else {
reply.status(204).send();
}
});
});

app.listen({ port: PORT }, (err) => {
if (err) throw err;
});

Large diffs are not rendered by default.

68 changes: 68 additions & 0 deletions packages/noir-ethereum-api/src/noir/oracles/server/app.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { buildOracleServer } from './app.js';

import { describe, it, expect, afterAll } from 'vitest';

describe('Oracle Server', () => {
const app = buildOracleServer();
afterAll(() => {
app.close();
});

it('should handle get_header request', async () => {
const response = await app.inject({
method: 'POST',
url: '/',
payload: {
method: 'get_header',
params: [{ Single: { inner: '0000000000000000000000000000000000000000000000000000000000d895ce' } }],
id: 2,
jsonrpc: '2.0'
}
});

expect(response.statusCode).toBe(200);
expect(response.body).toMatchSnapshot();
});

it('should handle get_account request', async () => {
const response = await app.inject({
method: 'POST',
url: '/',
payload: {
method: 'get_account',
params: [
{ Single: { inner: '0000000000000000000000000000000000000000000000000000000000d895ce' } },
{
Array: [
{ inner: '00000000000000000000000000000000000000000000000000000000000000b4' },
{ inner: '000000000000000000000000000000000000000000000000000000000000007e' },
{ inner: '000000000000000000000000000000000000000000000000000000000000003c' },
{ inner: '00000000000000000000000000000000000000000000000000000000000000d8' },
{ inner: '0000000000000000000000000000000000000000000000000000000000000037' },
{ inner: '00000000000000000000000000000000000000000000000000000000000000dd' },
{ inner: '00000000000000000000000000000000000000000000000000000000000000f8' },
{ inner: '00000000000000000000000000000000000000000000000000000000000000e4' },
{ inner: '00000000000000000000000000000000000000000000000000000000000000c5' },
{ inner: '000000000000000000000000000000000000000000000000000000000000007f' },
{ inner: '0000000000000000000000000000000000000000000000000000000000000005' },
{ inner: '00000000000000000000000000000000000000000000000000000000000000d7' },
{ inner: '000000000000000000000000000000000000000000000000000000000000000a' },
{ inner: '00000000000000000000000000000000000000000000000000000000000000b8' },
{ inner: '0000000000000000000000000000000000000000000000000000000000000065' },
{ inner: '00000000000000000000000000000000000000000000000000000000000000de' },
{ inner: '000000000000000000000000000000000000000000000000000000000000006e' },
{ inner: '0000000000000000000000000000000000000000000000000000000000000019' },
{ inner: '000000000000000000000000000000000000000000000000000000000000003b' },
{ inner: '00000000000000000000000000000000000000000000000000000000000000bb' }
]
}
],
id: 2,
jsonrpc: '2.0'
}
});

expect(response.statusCode).toBe(200);
expect(response.body).toMatchSnapshot();
});
});
31 changes: 31 additions & 0 deletions packages/noir-ethereum-api/src/noir/oracles/server/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { JSONRPCRequest, JSONRPCServer, TypedJSONRPCServer } from 'json-rpc-2.0';
import Fastify from 'fastify';
import http from 'http';
import { getHeaderHandler, getAccountHandler, JSONRPCServerMethods, ServerParams } from './handlers.js';
import { createDefaultClient } from '../../../ethereum/client.js';

const client = createDefaultClient();

const jsonRPCServer: TypedJSONRPCServer<JSONRPCServerMethods, ServerParams> = new JSONRPCServer();
const serverParams = { client };
jsonRPCServer.addMethod('get_header', getHeaderHandler);
jsonRPCServer.addMethod('get_account', getAccountHandler);

export function buildOracleServer(opts: Fastify.FastifyHttpOptions<http.Server> = {}): Fastify.FastifyInstance {
const app = Fastify(opts);

app.post('/', (request, reply) => {
const jsonRPCRequest = request.body as JSONRPCRequest;
request.log.info({ jsonRPCRequest }, 'Received request');

jsonRPCServer.receive(jsonRPCRequest, serverParams).then((jsonRPCResponse) => {
if (jsonRPCResponse) {
reply.send(jsonRPCResponse);
} else {
reply.status(204).send();
}
});
});

return app;
}

0 comments on commit 2a48fa9

Please sign in to comment.