Skip to content
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

Closed
1 task
joss-aztec opened this issue Mar 28, 2023 · 4 comments · Fixed by #3902
Closed
1 task

Support oracle opcode when invoking circuits via nargo #1052

joss-aztec opened this issue Mar 28, 2023 · 4 comments · Fixed by #3902
Assignees
Labels
discussion enhancement New feature or request

Comments

@joss-aztec
Copy link
Contributor

Problem

Circuits containing oracle opcodes are not compatible with either nargo execute or nargo test. Addressing this first requires us to decide on a minimal acceptable DX for providing answers to oracle calls.

Proposed solution

Possibilities:

  • Show a stdout prompt that awaits an oracle answer via stdin before continuing
  • Log missing oracles answers, prompting the dev to fill them in via Prover.toml or some other file

Alternatives considered

No response

Additional context

No response

Submission Checklist

  • Once I hit submit, I will assign this issue to the Project Board with the appropriate tags.
@sirasistant
Copy link
Contributor

We'll try to implement this as a JSON-RPC resolver for oracles in nargo

@TomAFrench
Copy link
Member

JSON-RPC resolver for oracles

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?

@sirasistant
Copy link
Contributor

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!

@sirasistant
Copy link
Contributor

I'll start working in this direction tomorrow

github-merge-queue bot pushed a commit that referenced this issue Dec 22, 2023
# 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 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion enhancement New feature or request
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

6 participants