Git Product home page Git Product logo

masp's Introduction

MASP Logo

MASP Rust crates

This repository contains a (work-in-progress) set of Rust crates for working with the Multi Asset Shielded Pool extensions of the Sapling circuits from Zcash.

MASP Description

Using the original Sapling circuits for user defined assets, each asset or token type must have a separate shielded pool and asset type is transparent for all transactions.

Using the MASP circuits, MASP notes can have shielded type, multiple assets can share the same shielded pool, and the asset types in a transaction can be shielded (except where there is transparent balance change)

The MASP is based on proposed multi-asset extensions to the Zcash protocol:

The MASP attempts to keep most of the security, feature, and performance properties of the original Sapling circuits.

Additional Components

This Rust repository, by itself, is not a complete implementation of the MASP, as it only includes circuits and some other functionality (transaction balancing, etc) while other functionality (notes, etc) is implemented elsewhere.

Repository Structure

The masp_proofs crate contains the modified Spend and Output circuits to support multiple assets.

Much of the code that supports the original Sapling circuits can be shared and reused with the MASP circuits. Therefore, certain code from zcash_primitives and zcash_proofs is placed in masp_primitives and masp_proofs.

New code related to asset types is included in masp_primitives.

Zcash code that is not relevant to the circuits (e.g. protocol, transaction, consensus, blockchain code) has been removed.

The masp crate contains the C language bindings for accessing the circuits.

The docs folder includes technical documentation about the circuit changes.

Asset Identifiers

The major difference between MASP and original Sapling is the use of asset identifiers to identify distinct asset types. An asset identifier is an internal 32 byte string that uniquely identifies each asset in the circuits.

The asset identifier is independent of a specific token standard.

There are certain requirements for deriving asset identifiers. The AssetType struct in masp_primitives (also via the C bindings) gives functions to derive asset identifiers.

Convert Circuit

In addition to the modified Spend and Output circuits, the MASP includes a Convert circuit that allows shielded conversions between distinct asset types according to a public list of conversion ratios. This is not a fully general exchange mechanism, but can be used to issue shielded rewards or incentives inside a pool.

The Convert circuit provides a mechanism where burning and minting of asset types can be enabled by adding Convert value commitments in transaction and ensuring the homomorphic sum of Spend, Output and Convert value commitments to be zero.

The Convert value commitment is constructed from AllowedConversion which was published earlier in AllowedConversion Tree. The AllowedConversion defines the allowed conversion assets. The AllowedConversion Tree is a merkle hash tree stored in the ledger.

Trusted Setup

The Zcash Sapling trusted setup parameters cannot be completely reused for the MASP. Parameter location and hashes must be added to masp_proofs following a suitable MPC ceremony.

Security Warnings

These libraries are currently under development and have not been fully-reviewed.

Audits

The following audits have been done on the MASP protocol:

In addition, the original Zcash Sapling protocol was audited without the MASP extensions:

License

All code in this workspace is licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

masp's People

Contributors

a-manning avatar acentelles avatar adityapk00 avatar adrianbrink avatar adust09 avatar awasunyin avatar bitcartel avatar bmerge avatar cwgoes avatar daira avatar defuse avatar ebfull avatar grarco avatar gtank avatar jasondavies avatar jimpo avatar joebebel avatar juped avatar kobigurk avatar mariari avatar mmaker avatar murisi avatar naure avatar nikvolf avatar paracetamolo avatar rex4539 avatar str4d avatar therealyingtong avatar xuyangsong avatar zancas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

masp's Issues

Check for cases of i64/u64 overflow in note values

Unlike Zcash Sapling, notes are not limited to MAX_MONEY. The logic needs to be checked thoroughly, and tests written, to make sure that there are no overflow or other issues when the value is close to i64 or u64 limits.

Bundle proving and verifying key in binary

There is a feature "bundled-prover" which embeds the generated proving params into the binary using wagyu-zcash-parameters (obviously this will need to be updated with different parameters)

There should be a similar feature which bundles or embeds the verifying key in the binary (particularly WASM binaries).

There are two ways to do this: embed the small VerifyingKey (approximately 1.6kB per circuit), or serialize the PreparedVerifyingKey (approximately 40 kB per circuit).

Embedding the small VerifyingKey has the disadvantage that every time the binary is reloaded, the VerifyingKey must be "prepared" for pairing which may waste CPU, particularly in a WASM binary that is reloaded frequently.

However, embedding the PreparedVerifyingKey results in a larger binary, and requires some changes (visibility and serialization) in the upstream bellman crate.

Initial work is located at joe/embed-verifier and joe/embedded-verifier

Output params parse error

Is the test-output-params updated?
The hash check is failed and it will get a parse error when downloading the output-params

MASP visuals on GitHub

Mini task:

  1. Go to Settings of this repo
  2. Social Preview --> pick an image from this folder.
  3. Test this on e.g. Wire or Twitter (copy / paste the URL of this repo) and see how it looks like (take a screenshot)

`final_check` enforces msg to sign

Currently, final_check prepends the public key for signature verification to the sighash to construct the actual msg on which the signature should be verified. This is the correct logic for the single verifier but the batch one doesn't need this because it will reconstruct the correct message on its own. This lead to a signature verification error when using the batch verifier. We should change final_check to expect the correct msg and let the caller pass the correct value to support both verifications.

Refine circuit tests

Currently the circuit tests could be refined a little bit. Right now it tries many random inputs, which takes a long time and doesn't really test edge cases.

Deprecate libmasp crate?

libmasp is the forked crate of FFI bindings, which makes sense if calling from C/C++ or Ocaml, but not necessary for Rust.

Manage librustzcash dependency

Currently MASP depends directly on the latest librustzcash. The current principle behind this is that librustzcash is a mature, well tested implementation and the more code reuse that is possible, the more the MASP benefits from this. MASP depends on librustzcash in two ways:

  1. Directly as a dependency, and
  2. Source code forked from librustzcash, typically only with constants changed

In the long run, it would be nice to reduce (2) if librustzcash natively supports different constants.

There are some tasks which should be done:

  1. Pin the librustzcash dependency to a specific commit hash so breaking changes to librustzcash don't break MASP without warning
  2. Migrate code updates from librustzcash to masp_primitives and masp_proofs as necessary. In particular, most Sapling-related updates to the zcash_primitives and zcash_proofs crates should be analyzed if they are applicable to masp_primitives and masp_proofs as well

Write specifications, implementations, and testing for Convert circuit and incentive mechanism

The Convert circuit is prototyped, but there are some missing parts:

  • Formalize and complete all specifications for the in-circuit and out-of-circuit behavior of Convert
  • Implement building the out-of-circuit Merkle tree of allowed conversions
  • Include the Convert description in transaction building and verification
  • Implement an example incentive mechanism based on Convert
  • Write tests for all of the above and review for errors

the Convert circuit can be used to provide incentives in the following way. When asset type A is shielded during epoch i, the MASP asset name is defined to be A's address || i, essentially timestamping the shielding time. To distribute 1 unit of asset type B for every unit of asset A inside the shielded pool during the entire epoch i+1, then at the end of epoch i+1 (at the beginning of epoch i+2) an allowed conversion of the form: -1 units of A's address || i, 1 unit of A's address || i+1, 1 unit of B's address. This allows the conversion of the timestamp from epoch i to epoch i+1. When the asset A is unshielded, it can be converted to the newest epoch, avoiding the need to leak the original shielding epoch.

To prevent the need for sequentially Converting across many epochs, during fixed epoch j the allowed conversions are between A's address || i and A's address || j for all i < j, allowing direct conversion to the latest epoch in one transaction.

Mathematical question about value commitment

Hi!
Why does cv^{old} apply GroupHash instead of FindGroupHash?
スクリーンショット 2023-08-23 22 25 02

As shown below, FindGroupHash would be appropriate if following Sapling's protocol.
スクリーンショット 2023-08-23 16 03 07
Are FindGroupHash and GroupHash equivalent here?

I would also like to know why [v]FindGroupHash^{J(r)*} -> [v_{old} hJ]vb

Unify specifications

Currently, the specifications for MASP are divided among several places:

  1. The original Zcash Sapling specification
  2. The cryptographic MASP specification at https://github.com/anoma/masp/blob/main/docs/multi-asset-shielded-pool.pdf
  3. The MASP transaction format and validity predicate in the Anoma specifications at https://spec.anoma.network/master/architecture/namada/masp.html

This makes it a bit difficult to review the entire protocol. It may be useful to merge everything into a single comprehensive spec.

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.