GithubHelp home page GithubHelp logo

o1-labs / o1js Goto Github PK

View Code? Open in Web Editor NEW
471.0 28.0 104.0 513.69 MB

TypeScript framework for zk-SNARKs and zkApps

Home Page: https://docs.minaprotocol.com/en/zkapps/how-to-write-a-zkapp

License: Apache License 2.0

JavaScript 2.13% TypeScript 97.40% HTML 0.12% Shell 0.34%

o1js's Issues

During build, warn if unsupported JS/TS language constructs are used

During SnarkyJS’ build, we could help guide developers by checking for unsupported language constructs (e.g. throw, conditionals, native ternaries) and warning developers. Likely using an abstract syntax tree to do this reliably.

Related: we want to set up matching ES Lint custom rules in the Snapp CLI's projec-ts, if possible, to warn developers as they wrote their app.

When using `Circuit.if(...)`, Error: rangeCheckHelper: Expected 289...661 to fit in 64 bits

Hello,
When using Circuit.if(...) an exception occurs:

Error: rangeCheckHelper: Expected 28948022309329048855892746252171976963363056481941560715954676764349966633661 to fit in 64 bits
at Jv (eval at Be (:3010/js/chunk-QIK4YCST.js:7670), :3210:1356)
at eval (eval at Be (:3010/js/chunk-QIK4YCST.js:7670), :3210:8522)
at am (eval at Be (:3010/js/chunk-QIK4YCST.js:7670), :4:23673)
at Object.eval [as rangeCheckHelper] (eval at Be (:3010/js/chunk-QIK4YCST.js:7670), :4:80689)
at z.lte (:3010/js/chunk-QIK4YCST.js:8582)
at z.lt (:3010/js/chunk-QIK4YCST.js:8590)
at SealedBidAuctionSnapp.bid (:3010/js/sealed-bid-auction-snapp-HCY3URRZ.js:52)
at :3010/js/sealed-bid-auction-snapp-HCY3URRZ.js:135
at :3010/js/chunk-QIK4YCST.js:8980
at As (eval at Be (:3010/js/chunk-QIK4YCST.js:7670), :3210:24862)

To reproduce, uncomment the commented lines at https://github.com/Muhammad-Altabba/snarkyjs-tender/blob/bf6ba9503fe905c65376237c18a81422c119cc28/src/sealed-bid-auction-snapp.ts#L80 and run the project.

Is this an expected behavior? Could you please elaborate on this?

Thanks in advace,

`inProver` returns true in unexpected places

Circuit.inProver seems to behave weird with the current implementation.
They are false in the beginning but stay true after the first Mina.transaction was run

(Observed in simple SmartContract example, needs proper investigation)

Code style clean-up

Whenever there is time, I'd like to go through the code base to address the following stylistic points (copied from the discussion on PR #36)

  • scan the code base for usage of promises that can be simplified / made more readable by using async / await
  • don't use type annotations in assignments or function return signature, except where necessary
  • Classes which don't have instance methods should just be types instead. That removes the need for a constructor and makes the code less painful.
  • It would be less confusing to me if "signatureSufficient" would instead be called "proofNecessary", and the Bool negated (if that's accurate)
  • IMO it's easier to understand the purpose of a file if all its exports are listed at the very top (after the imports)
  • (TBD) I'm not a fan of having many names for the same types / classes

Building Snarkette

I would like to know how to build the dune dependency in https://github.com/o1-labs/snarkyjs. I am trying to learn to use a dune dependency in a js project as you did here by reading your code. It seems we are missing "../../config.mlh" required by the dune file. Can this script be provided?

error output:

mando@mandalarian ~/G/s/snarkette (master)> dune build
Info: Creating file dune-project with this contents:
| (lang dune 2.8)
File "dune", line 5, characters 20-36:
5 |  (preprocessor_deps ../../config.mlh)
                        ^^^^^^^^^^^^^^^^
Error: path outside the workspace: ../../config.mlh from default

Thank you.

Also, nice work on ocamlbyexample!

[feature request] exposing/(de)serializing proof and verification key

Thins idea was also mentioned in Discord.

Idea: Potentially allowing to "export" and "import" proofs and their coressponding verification key to allow verification and proofing of code outside of the Mina blockchain, inside of web2.0.

Reason: It would open up SnarkyJS to more developers, allowing many web 2.0 devs and other developers to utilize the power of zero knowledge proofs to some extend in normal web applications.

Possible usage: What it could look like

// example from ex00_preimage.ts

class Main extends Circuit {
  @circuitMain
  static main(preimage: Field, @public_ hash: Field) {
    Poseidon.hash([preimage]).assertEquals(hash);
  }
}

// ... 

let proof = Main.prove(/* .. */); // returns the proof
let encodedProof = proof.toBase58()) // potentially encoded in base58 for easy use eg 'RJcTKtswS9xgY4FDfxCq4ZaLRfQwGME8GYPFGpxieWZXJMGUuqN1zdKYEM6dLZER'  

let verificationKey = Main.getVerificationKey(); // returns the verification key; potentially also encoded for easy use

// usage in a different application

class MyVerifier extends Verifier {
  constructor(key: VerificationKey) {
     // ...
  }
}

let verificationKey = 'someVerificationKeyEncoded';
let myVerifier = new Verifier(VerificationKey.fromString(verificationKey))

let proof = 'someProofEncoded';
let isValid = myVerifier.verify(Proof.fromString(proof)); // returns true if proof matches verification key


Is something like that feasible and makes sense?
Or is something like that potentially even planned already?

Thanks!

[feature request] Decouple signing from transaction creation

In current snarkyjs (v0.1.11) creating and sending a transaction looks like this:

await Mina.transaction(senderPrivateKey, async () => {
    // transaction code
  })
    .send()
    .wait();

This means that the frontend code that creates the transaction and waits for it also has access to the private key.
I think it would be very useful to be able to create transactions without having direct access to the key, but rather by getting access to a signer object.

A back of the napkin example would be something like this:

interface MinaSigner {
  sign: (data: Uint8Array) => Promise<Uint8Array>
}

class SimpleSigner implements MinaSigner {
  constructor(privateKey: string) {}
  async sign(data: Uint8Array): Promise<Uint8Array> {
      // ...implement the actual signing
  }
}

const senderSigner = new MinaSigner(senderPrivateKey)

await Mina.transaction(senderSigner, async () => {
    // transaction code
  })
    .send()
    .wait();

The benefit of this approach is that you can separate concerns more cleanly between key management and frontend code.
You can let a wallet or an HSM handle keys and not have to trust that the frontend has no vulnerability that allows someone to sniff keys.

[BUG] Mina.LocalBlockchain() allows multiple snapps to share an address and state

It appears that multiple snapps can be deployed to the same address using snarkyjs v0.1.11 and LocalBlockchain().
The second deployment transaction doesn't fail silently, it actually executes and allows an outsider to overwrite the existing state.

I made a small proof of concept for this bug here: https://gist.github.com/mirceanis/b53b6acd0dbe6f1658c78706800736d5, based on one of the exercises from the workshop.

  1. deploy contract1 with initial state and logic to snappPublicKey
    • everything runs normally
  2. deploy contract2 to the same snappPublicKey
    • this should have failed but doesn't
    • It also works if the initial state is different, and existing state gets overridden
    • also, it doesn't matter if it's the same account performing the deployment. An external party can also do it.
  3. existing state of the old contract is overridden by the new initial state of the new contract
    • this should not even be possible if 2. is fixed
  4. execute code from contract2, works and updates the state
    • also should not work if 2. is fixed, but I thought I'd mention it since it may be related.
  5. execute code from contract1 still works, with old contract logic, but over the new state
    • this is even weirder, since the new contract is not an "upgrade", but rather a "sibling" of the same address, sharing the same state

I suppose this is only an issue with the mock local blockchain, but I can't test the real thing yet :)

Even so, I believe that fixing this bug is important even before testnet snapps, since it should make it clearer to devs which parts of the code actually matter for circuits and building the security model of snapps.

Change tsconfig.json `target` value to ES2020

Izaak has reported that decorators don't behave as expected on the feature/workshop-examples branch. By changing the target value from esnext to es2020, the decorator error he was experiencing was fixed. Further work should be made to figure out why this was a breaking change.

Because esnext targets the highest version of TypeScript that the project supports, maybe we should be more conservative with how we specify the target value.

Playground link of correct behavior:
https://www.typescriptlang.org/play?ts=4.4.4#code/GYVwdgxgLglg9mABMOcAUAPAXIsIC2ARgKYBOAlIgN4BQNpxUIpSoksCiaUAFjAM44AhmACeAGkRQhpAOaNhYyQGtionPyikYYWZVqJDiCAn5wANsQB05uLLQByAYgCCDydLmMrJsJtIg0HCkiAC84a7kANw0RsamFta29g68YALuUnz80bFGvmaWNnaOUJme8lC5cQDyhABWxNBWACbEwDrEAAqkcAAOZFCi3DKVKmqSVIj8ClwYlKEAfNTxfonFKTNQUGQO5AC+kpU4aAvLDiakDNAO++Q0+w80QoT+QtDG5kL8-IgAQtQ6I86BAvj9XIhiBgdmAWr8AYC4gABFDoACMAAZ7nFsNMtDpZDE8oYClpAlBgqdEXEjPwQANSKdiXFeAIrBgwogHAB3Xq6BwxOKPR6kxBCTlgYjc1ynIkFdbJNBCdn3IA

Output should specify the variable x as the value "correct" when run. On commit 953cc6020966e90e36f3410237a64a0d16dcc6c5, the same example is in index.ts and fails to set the variable correctly with the same code as the playground. To run the code on commit 953cc..., run npm run exec

Consider supporting mock snapp GraphQL API endpoint

We could consider allowing devs to send transactions to Mina's mock/dry run API endpoint, which will show them the rest of a transaction without actually executing the transaction state changes on chain.

Low priority.

Remove spin lock hack

This is a longer-term issue that probably requires some ocaml code to be rewritten to expect Promises when calling into the Wasm produced by Rust (marlin_plonk_bindings).

We currently have an awful hack in JS land just to present functions as sync to the JSOO code that in reality are async, context here:

https://o1-labs.slack.com/archives/C028Q27R8UC/p1633028074087000

It would make the JS project so much nicer if we could avoid this and deal with Promises from end to end

Enable calling other snapps, creating accounts, ...

and deploying snapps from within a snapp.

Also, fix weird 3-way account interaction in the current examples when funding a snapp account.

This is a nice-to-have in the current mocked-blockchain situation, but a must-have once testnet is available.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.