-
Notifications
You must be signed in to change notification settings - Fork 219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support oracle opcode when invoking circuits via nargo #1052
Comments
We'll try to implement this as a JSON-RPC resolver for oracles in nargo |
Can you go into some more detail on what you're picturing on this? I'm not sure its been written down anywhere since Istanbul. Is is just we allow nargo to point at some url at which we expect some process to be running which will handle all of these? |
The idea is that nargo execute and nargo test have an optional parameter that is a resolver URL. This is propagated to the foreign call resolver, so when a foreign call is issued that nargo doesn't know about, if the resolver URL was passed it'll use it to fetch the foreign call results (passing the foreign call parameters). We also evaluated gRPC but it's less suitable for our use case! |
I'll start working in this direction tomorrow |
# Description This adds a JSON-RPC client to the DefaultForeignCallExecutor. This allows it to solve unknown oracle calls. The URL to the foreign call executor is an optional argument to nargo execute, nargo test and nargo prove. ## Problem\* Resolves #1052 ## Summary\* ## Additional Context An example echo server in typescript ```typescript import { JSONRPCServer, TypedJSONRPCServer, } from "json-rpc-2.0"; import express from "express"; import bodyParser from "body-parser"; type Methods = { echo(params: ForeignCallParam[]): ForeignCallResult; }; const server: TypedJSONRPCServer<Methods> = new JSONRPCServer(/* ... */); interface Value { inner: string, } interface SingleForeignCallParam { Single: Value, } interface ArrayForeignCallParam { Array: Value[], } type ForeignCallParam = SingleForeignCallParam | ArrayForeignCallParam; interface ForeignCallResult { values: ForeignCallParam[], } server.addMethod("echo", (params) => { return {values: params}; }); const app = express(); app.use(bodyParser.json()); app.post("/", (req, res) => { const jsonRPCRequest = req.body; console.log(jsonRPCRequest); // server.receive takes a JSON-RPC request and returns a promise of a JSON-RPC response. // It can also receive an array of requests, in which case it may return an array of responses. // Alternatively, you can use server.receiveJSON, which takes JSON string as is (in this case req.body). server.receive(jsonRPCRequest).then((jsonRPCResponse) => { if (jsonRPCResponse) { res.json(jsonRPCResponse); } else { // If response is absent, it was a JSON-RPC notification method. // Respond with no content status (204). res.sendStatus(204); } }); }); app.listen(5555); ``` And the corresponding main.nr ```rust #[oracle(echo)] fn echo_oracle(_x: Field) -> Field {} unconstrained fn echo(x: Field) -> Field { echo_oracle(x) } fn main(x: Field, y: pub Field) { assert(echo(x) == y); } ``` ## Documentation\* Check one: - [ ] No documentation needed. - [ ] Documentation included in this PR. - [ ] **[Exceptional Case]** Documentation to be submitted in a separate PR. (We can document this when we evaluate if this solution is enough) # PR Checklist\* - [x] I have tested the changes locally. - [x] I have formatted the changes with [Prettier](https://prettier.io/) and/or `cargo fmt` on default settings. --------- Co-authored-by: thunkar <gregojquiros@gmail.com>
Problem
Circuits containing oracle opcodes are not compatible with either
nargo execute
ornargo test
. Addressing this first requires us to decide on a minimal acceptable DX for providing answers to oracle calls.Proposed solution
Possibilities:
Alternatives considered
No response
Additional context
No response
Submission Checklist
The text was updated successfully, but these errors were encountered: