openmina / mina-p2p-messages-rs

0 stars 0 forks source link

As a Developer, I need to deserialize the JSON zkapp command to p2p type the same way Mina does #41

Open MartinOndejka opened 1 year ago

MartinOndejka commented 1 year ago

I am trying to deserialize zkapp command generated from snarkyjs and apply it to the ledger.

The idea is to deserialize it to MinaBaseZkappCommandTStableV1WireStableV1 and then convert it to ZkappCommand from ledger.

There are few issues with deserialization of json:

  1. MinaBaseSignatureStableV1 is a tuple but from snarkyjs I’m getting for signature bs58 string.
  2. I’m getting missing field "elt" here.
tizoc commented 1 year ago

Hi @MartinOndejka, can you share an example of the JSON you are trying to deserialize?

akoptelov commented 1 year ago

Hi @MartinOndejka We have some lining-up with Mina JSON for V2 structures, thought there are some missing bits still. Also we never applied that JSON encoding to snarkyjs (yet).

MartinOndejka commented 1 year ago

Here is the minimal example of simple transfer and snarkyjs local blockchain that I've been trying it with so far. Let me know if you need more.

Snarkyjs deserializes it directly to the Mina Ocaml type, that's why I was hoping it might work here as well.

https://github.com/o1-labs/snarkyjs-bindings/blob/main/ocaml/lib/snarky_js_bindings_lib.ml#L2614-L2615

Example here ```json { "feePayer": { "body": { "publicKey": "B62qnPZzpnQWA8FLBn9qqJqPTeGuDdHTZgpmEMUNFCq8fWCRSqJS6Jd", "fee": "0", "validUntil": null, "nonce": "0" }, "authorization": "7mXS9Y91bWtTYNKuDbxTuG18wUiZLHUySy9Ms8bPyAT9KNnME1q2nctwnvowJi2Y79dnsL18iVSCuaQF1ufUKwUZZKAXHqnF" }, "accountUpdates": [ { "body": { "publicKey": "B62qnPZzpnQWA8FLBn9qqJqPTeGuDdHTZgpmEMUNFCq8fWCRSqJS6Jd", "tokenId": "wSHV2S4qX9jFsLjQo8r1BsMLH2ZRKsZx6EJd1sbozGPieEC4Jf", "update": { "appState": [ null, null, null, null, null, null, null, null ], "delegate": null, "verificationKey": null, "permissions": null, "zkappUri": null, "tokenSymbol": null, "timing": null, "votingFor": null }, "balanceChange": { "magnitude": "10", "sgn": "Negative" }, "incrementNonce": false, "events": [], "actions": [], "callData": "0", "callDepth": 0, "preconditions": { "network": { "snarkedLedgerHash": null, "blockchainLength": null, "minWindowDensity": null, "totalCurrency": null, "globalSlotSinceGenesis": null, "stakingEpochData": { "ledger": { "hash": null, "totalCurrency": null }, "seed": null, "startCheckpoint": null, "lockCheckpoint": null, "epochLength": null }, "nextEpochData": { "ledger": { "hash": null, "totalCurrency": null }, "seed": null, "startCheckpoint": null, "lockCheckpoint": null, "epochLength": null } }, "account": { "balance": null, "nonce": null, "receiptChainHash": null, "delegate": null, "state": [ null, null, null, null, null, null, null, null ], "actionState": null, "provedState": null, "isNew": null }, "validWhile": null }, "useFullCommitment": true, "implicitAccountCreationFee": false, "mayUseToken": { "parentsOwnToken": false, "inheritFromParent": false }, "authorizationKind": { "isSigned": true, "isProved": false, "verificationKeyHash": "0" } }, "authorization": { "proof": null, "signature": "7mXS9Y91bWtTYNKuDbxTuG18wUiZLHUySy9Ms8bPyAT9KNnME1q2nctwnvowJi2Y79dnsL18iVSCuaQF1ufUKwUZZKAXHqnF" } }, { "body": { "publicKey": "B62qm8mVEkhAZdnnoE4gzKhTYj2Gre88GNhoknbJdgDrE8JQojNBgWa", "tokenId": "wSHV2S4qX9jFsLjQo8r1BsMLH2ZRKsZx6EJd1sbozGPieEC4Jf", "update": { "appState": [ null, null, null, null, null, null, null, null ], "delegate": null, "verificationKey": null, "permissions": null, "zkappUri": null, "tokenSymbol": null, "timing": null, "votingFor": null }, "balanceChange": { "magnitude": "10", "sgn": "Positive" }, "incrementNonce": false, "events": [], "actions": [], "callData": "0", "callDepth": 1, "preconditions": { "network": { "snarkedLedgerHash": null, "blockchainLength": null, "minWindowDensity": null, "totalCurrency": null, "globalSlotSinceGenesis": null, "stakingEpochData": { "ledger": { "hash": null, "totalCurrency": null }, "seed": null, "startCheckpoint": null, "lockCheckpoint": null, "epochLength": null }, "nextEpochData": { "ledger": { "hash": null, "totalCurrency": null }, "seed": null, "startCheckpoint": null, "lockCheckpoint": null, "epochLength": null } }, "account": { "balance": null, "nonce": null, "receiptChainHash": null, "delegate": null, "state": [ null, null, null, null, null, null, null, null ], "actionState": null, "provedState": null, "isNew": null }, "validWhile": null }, "useFullCommitment": false, "implicitAccountCreationFee": false, "mayUseToken": { "parentsOwnToken": false, "inheritFromParent": false }, "authorizationKind": { "isSigned": false, "isProved": false, "verificationKeyHash": "0" } }, "authorization": { "proof": null, "signature": null } } ], "memo": "E4YM2vTHhWEg66xpj52JErHUBU4pZ1yageL4TVDDpTTSsv8mK6YaH" } ```
akoptelov commented 1 year ago

So, after some short investigation I see these issues:

a. Signature in our lib doesn't have proper base58 encoding. b. snarkyjs uses camelCase fields while Mina (and our code) uses snake_case. c. Account update in Mina/our lib has more data then snarkyjs, that's why that error about elt is reported.

While a is very easy to fix, b can be worked around by modifying snarkyjs JSON, c is not obvious for me right now. I will need to check how types on snarkyjs are generated/mapped from Mina ones.