o1-labs / o1js Goto Github PK
View Code? Open in Web Editor NEWTypeScript framework for zk-SNARKs and zkApps
Home Page: https://docs.minaprotocol.com/en/zkapps/how-to-write-a-zkapp
License: Apache License 2.0
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
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.
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,
We need to get the client bundle size much smaller.
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)
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)
Do we want stuff like Field.fromBitstring()
?
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!
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!
Hi, these two methods(UInt64.assertGt and UInt32.assertGt) do not work correctly, as shown in the code. Is the assertGte method also missing?
Todo: Check with Nathan & Martin to ask about their latest progress, before starting.
Issue: JS of OCaml only builds to CommonJS.
It could work everywhere
...in the current examples when funding a snapp account.
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.
Hello,
The .toStrting()
is giving the value of the Field. I think this is a bug in the Mocking and not intended, right?
You can check how I am able to get the numeric value of UInt64
here:
https://github.com/Muhammad-Altabba/snarkyjs-tender/blob/bf6ba9503fe905c65376237c18a81422c119cc28/src/sealed-bid-auction-snapp.ts#L90
and deprecate (but not remove) short forms
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.
contract1
with initial state and logic to snappPublicKey
contract2
to the same snappPublicKey
contract2
, works and updates the state
contract1
still works, with old contract logic, but over the new 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.
Currently transactions tend to fail silently, which is discovered later when an account is not available or a state update didn't happen
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.
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
it'd be nice to leverage CI as much as possible to perform releases.
(Optional) Automatic releases and changelog, using Semantic release, Commitizen, Conventional changelog and Husky (for the git hooks)
from https://github.com/alexjoverm/typescript-library-starter
@mitschabaude points to https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages also
This just means Circuit.array has to be ported to JS
For consistency given we use new Bool()
.
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.
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
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.