Commit Graph

1276 Commits

Author SHA1 Message Date
Vivek Arte f38d6b9e4c
Rename `sk_iss` to `isk`, the `IssuanceKey` struct to `IssuanceAuthorizingKey`, and move to a two key structure (#92)
This performs a consistent renaming of the issuance authorizing key to make it consistent with the ZIP.
It also reworks the `IssuanceAuthorizingKey` struct in place of the `IssuanceKey` and `IssuanceAuthorizingKey` structs, as part of using a two key structure for issuance, as specified in ZIP 227.
2023-11-07 17:06:30 +05:30
Dmitry Demin 7b943e197e
Adopt Orchard ZSA for Zebra (introduce zcash_note_encryption_zsa alias, minor enhancements) (#89)
This Pull Request introduces the `zcash_note_encryption_zsa` alias,
ensuring compatibility with the Zebra project. This alias is used to
prevent conflicts with the original `zcash_note_encryption` crate, which
is also used in Zebra through the original `orchard` crate that is used
in parallel with our `orchard` (Orchard ZSA) crate.
Additionally, this PR includes minor enhancements to ensure
compatibility with the Zebra project.

---------

Co-authored-by: Dmitry Demin <dmitry@qed-it.com>
2023-11-01 10:37:43 +01:00
Constance Beguier a680f410a4
Circuit: optimize ZEC/ZSA hash computations in note commitment (#87)
We optimized note_commitment evaluation by sharing a portion of the hash evaluation between ZEC and ZSA.
1. message_common_prefix = a || b || c || d || e || f || g
2. message_suffix_zec = h_zec
3. message_suffix_zsa = h_zsa || i || j
4. Q = if (is_native_asset == 0) {Q_ZSA} else {Q_ZEC}
5. common_hash = hash(Q, message_common_prefix) // this part is shared
6. hash_point_zec = hash(common_hash, message_suffix_zec)
7. hash_point_zsa = hash(common_hash, message_suffix_zsa)
8. hash_point = if (is_native_asset == 0) {hash_point_zsa} else {hash_point_zec}
2023-10-18 10:38:59 +02:00
Constance Beguier 2810365f93
Circuit: remove mutiplexer chip (#90)
Remove the multiplexer chip from this repo (this chip has been moved
into halo2 repo).
2023-10-17 10:11:00 +02:00
Constance Beguier 8b0560d645
Circuit: optimized short range check on 4 and 5 bits (#86)
Short range checks on 4 and 5 bits are now performed with only one
lookup (instead of 2).

With this optimization, we  could come back to k=11 in the circuit.
2023-10-16 11:54:09 +02:00
Dmitry Demin 7937e5b251
Enhance and cleanup ivk-to-bytes-visibility-downgrade branch (#81)
Added burn validation, fixes and minor additions. 
Bumped Rust version to 1.65

---------

Co-authored-by: alexeykoren <>
Co-authored-by: Dmitry Demin <dmitry@qed-it.com>
Co-authored-by: Paul <3682187+PaulLaux@users.noreply.github.com>
2023-10-04 12:23:57 +00:00
Constance Beguier 139ecca079
Circuit: Add enable_zsa flag (#79)
When enable_zsa flag is set to false, it is not possible to perform ZSA transactions (the circuit will fail).

Fix the version of reddsa (=0.5.0) because recent versions required rust version 1.65 or newer
Fix the version of tempfile (=3.5.0) because recent versions required rust version 1.63 or newer
Limit the version of flate2 (<1.0.27) because recent versions raise some clippy issues
2023-08-31 09:23:44 +02:00
Constance Beguier 081513b363
Circuit: Fix balance violation (#78)
To prevent balance violations, we have replaced the constraint
"(v_old = 0 and split_flag = 0) or (root = anchor)"
with the constraint "(v_old = 0 and is_native_asset = 1) or (root = anchor)".
Previously, an adversary could use a zero-valued ZSA note to violate
balance by setting v_old=0, v_new!=0, is_native_asset=0, split_flag=0.

Limit the version of dashmap (< 5.5) because recent dashmap versions
required rust version 1.64 or newer
Limit the version of hashbrown (<0.13) because recent hashbrown versions
required rust version 1.64 or newer
2023-07-24 16:53:10 +02:00
Constance Beguier ff2ac96b24
Circuit: Add constraints (#77)
Add the constraint: (split_flag=1) => (is_native_asset=0)

Replace the constraint: (v_old=0) or (root=anchor)
by the constraint: (v_old=0 and split_flag=0) or (root=anchor)

Limit the version of half (< 2.3) because recent half versions required
at least rust version 1.70.
2023-06-29 13:03:27 +02:00
Dmitry Demin 1a00c4af9a
Upgrade orchard to v0.5 and integrate corresponding librustzcash upgrade (new) (#75)
This pull request focuses on upgrading the `orchard` repository to
integrate it with a version of `librustzcash` repository compatible with
`orchard` v0.5.

The necessary changes have been made in the
`upgrade_librustzcash_for_orchard_v05` branch, and merge conflicts have
been resolved. `upgrade_librustzcash_for_orchard_v05` branch was created
from `librustzcash_980736806` branch that contains previous attempt of
upgading.
2023-06-23 18:35:17 +03:00
Dmitry Demin 62d4ae70ae Change tag name for zcash_note_encryption in root Cargo.toml 2023-06-23 14:08:36 +02:00
Dmitry Demin 21d7273e49 Use tag instead of branch for zcash_note_encryption (librustzcash) ref in root Cargo.toml 2023-06-23 13:06:48 +02:00
Dmitry Demin d4ff716bb8 Merge branch 'zsa1' into upgrade_librustzcash_for_orchard_v05_new 2023-06-23 13:06:22 +02:00
Constance Beguier 477f949bd2
Update random nullifier for split notes and circuit (#76)
To be secure against roadblock attacks, we update the process to obtain
a random nullifier for split notes.
Now we have the following formula to evaluate nf_old
- for non split_notes, nf_old = Extract_P([PRF^{nfOrchard}_{nk}(rho_old) + psi_nf) mod q_P] NullifierK + cm_old)
- for split notes, nf_old = Extract_P([PRF^{nfOrchard}_{nk}(rho_old) + psi_nf) mod q_P] NullifierK + cm_old + NullifierL)
where psi_nf is equal to
- psi_old for non split notes
- a random pallas Base element for split notes

The following constraints have been updated into the circuit
- nf_old = nf_old_pub for all notes
- derived_pk_d_old = pk_d_old for all notes
- if split_flag=0, then psi_old = psi_new
2023-06-23 09:40:27 +00:00
Vivek Arte daf6269e89
Preventing Asset Base from being the identity point on the Pallas curve (#71)
As in the title, this is done in two portions:
- A protection is added to `AssetBase::derive()`, which panics if the
output is going to be the identity point. This panic will occur with
negligible probability due to the properties of the hash.
- The `verify_supply()` function now returns an error if the Asset Base
of the notes involved is the identity point.
- A number of tests are added to ensure the `verify_supply`, `verify_issue_bundle` functions raise errors appropriately, and also to confirm that the issue bundle cannot be signed when the asset base is the identity point.

---------

Co-authored-by: Paul <3682187+PaulLaux@users.noreply.github.com>
2023-06-21 15:53:38 +05:30
Constance Beguier aa1d89561c
Fix issuance key derivation (#74)
Updated constants for master (extended) issuance key according to ZIP
227. Previously, we used the same personalization for the master
extended spending key and the master extended issuance key, as well as
the same purpose constant for the spending master key and the issuance
master key.

Now, the following updates have been made:
- Personalization for the master extended issuance key: ZIP32ZSAIssue_V1
- Purpose constant for the issuance master key: 227"
2023-06-20 20:35:57 +02:00
Dmitry Demin f49be89f35 Update code to refer to the upgraded version of librustzcash and reflect the corresponding changes 2023-06-19 10:01:51 +02:00
Constance Beguier 5b003f8b53
Merge branch main into zsa1 (#72)
For zcash_note_encryption, we have to use version 0.2 with QEDIT patch.
2023-06-13 11:35:12 +02:00
Constance 8bc18f724f Merge branch main into zsa1 2023-06-13 10:04:15 +02:00
Vivek Arte 950b80616d
Updates to TXID Digest and Authorizing Data Commitment (#66)
This updates the computation of the transaction digest and
authorizing data commitment for the issue bundle to be in line with the
specification in ZIP 227.
2023-06-13 13:12:08 +05:30
Constance Beguier 7ad2bacf5d
Fix IssueBundle and IssueAction structures (#70)
The vector of issue actions in an IssueBundle must not be empty.
The vector of notes in an IssueAction could be empty when `finalize` is set to true.

We could add some actions in an `IssueAction` even if `finalize` is set to true.
Only the next block is affected by the `finalize` flag, not the current block.
2023-06-12 17:20:20 +02:00
Kris Nuttycombe 2103db8290
Merge pull request #397 from zcash/release-0.5.0
orchard release version 0.5.0
2023-06-06 12:23:12 -06:00
Kris Nuttycombe ca55cadbad orchard release version 0.5.0 2023-06-06 11:10:49 -06:00
Constance Beguier 9965a6d06b
Add serialization of finalize flag (#68)
Add a function `flags` to serialize the `finalize` flag of an IssueAction to a byte.
This function will be used by the client.
2023-06-06 17:11:27 +02:00
Constance Beguier 02fa582c80
Global padding for bundle (#67)
Each bundle must contain at least two actions for privacy concerns.
Previously, we pad bundle to have at least two actions per asset.
Now, we pad bundle globally, and add dummy/split actions to have at least two actions per bundle.
2023-06-06 12:40:06 +02:00
Constance Beguier 32eee6e083
Do not create split notes with native asset (#65)
Due to privacy considerations, we might incorporate dummy or split notes while generating a bundle.
However, to maintain consistency with the previous version, we choose not to include split notes for native asset.

In addition, we use a new dummy/split notes for each extend in order to have different nullifiers.
2023-06-06 08:46:52 +02:00
Constance Beguier bedc732d6f
Circuit: Add tests for orchard circuit (#63)
Add some positive and negative tests for Orchard circuit
2023-06-01 10:15:24 +02:00
Kris Nuttycombe e9f556ead4
Merge pull request #396 from zcash/simplify_parse_note_plaintext_ovk_args
Update `zcash_note_encryption` to remove unused arguments from `parse_note_plaintext_without_memo_ovk`
2023-05-31 12:54:40 -06:00
Dmitry Demin 8e71fffc51
Protect bundle burn from adding assets with zero amount (#60)
Prevent the burning of assets with zero value.
2023-05-29 12:06:53 +00:00
Constance Beguier 95fcf88407
Circuit: Check pk_d_old = derived_pk_d_old only when split_flag = 0 (#64)
In the circuit derived_pk_d_old is evaluated from rivk, ak, nk and g_d_old.
rivk, ak and nk comes from the FullViewingKey stored in the spent note.
For split note, the FullViewingKey stored in the spent note is random in order to derive a random Nullifier nf_old.
Thus, the constraint pk_d_old = derived_pk_d_old must not be checked for split note (split_flag=1).
2023-05-29 10:06:30 +00:00
Kris Nuttycombe 2a4f27c937 Update `zcash_note_encryption` to remove unused arguments from parse_note_plaintext_without_memo_ovk. 2023-05-26 09:28:01 -06:00
Kris Nuttycombe 729def6c60
Merge pull request #394 from zcash/note-encryption-avoid-redundant-checks
Remove redundant checks during note encryption
2023-05-26 09:13:20 -06:00
Kris Nuttycombe 11b6858ac8
Merge pull request #395 from nuttycom/update_bridgetree
Update the `incrementalmerkletree` and `bridgetree` patch versions.
2023-05-25 11:38:40 -06:00
Constance Beguier b4f628133e
Circuit: Use nf_old_pub to evaluate new note commitment (with rho_new = nf_old_pub) (#62)
Currently, every new note commitment is calculated using
rho_new = nf_old = DeriveNullifier_nk(rho_old, psi_old, cm_old).
For split notes, we would like to evaluate the new note commitment with
rho_new = nf_old_pub (a random nullifier which is stored in the instance nf_old_pub).
For all remaining notes, nf_old = nf_old_pub.
As such, implementing rho_new = nf_old_pub for all notes will not affect
those remaining notes (and only affect split notes).
2023-05-25 16:01:50 +02:00
str4d f4a785adae
Merge pull request #393 from daira/book-notecommit-missing-paren
[book] Add a missing right parenthesis
2023-05-24 23:24:47 +01:00
Kris Nuttycombe 6cf6f15bf1 Update the `incrementalmerkletree` and `bridgetree` patch versions.
This also removes the `bridgetree` transitive dependency when building
using the `test-dependencies` feature flag, as the only use of it can be
satisfied just with `incrementalmerkletree`.
2023-05-24 15:36:25 -06:00
Constance Beguier aeb993403b
Circuit: Update note_commit to take into account asset (#56)
In the circuit, we update note_commit to take into account asset.
Previously, note_commit returns cm = hash(Q_ZEC, msg) + [rcm]R.
Now, note_commit returns
- cm = hash(Q_ZEC, msg) + [rcm]R for ZEC note
- cm = hash(Q_ZSA, msg || asset) + [rcm]R for ZSA note

We now evaluate note_commit with the following steps
1. evaluate **hash_zec = hash(Q_ZEC, msg)**
2. evaluate **hash_zsa = hash(Q_ZSA, msg || asset)**
3. select **hash = hash_zec if is_native_asset**
                         **= hash_zsa otherwise**
4. evaluate **cm = hash + [rcm]R**
5. check some constraints on msg and asset and their decompositions
6. return **cm**

The following modifications are required to update note_commit:
- add a is_native_asset witness (and check that it is a boolean and its
value is correct according to asset)
- add a MUX chip to evaluate a multiplexer on Pallas points

Warning: we increased the size of the Orchard circuit !
2023-05-23 13:03:56 +02:00
Jack Grigg 90e64cbac0 Remove redundant checks during note encryption
The consistency check between `esk` and `ephemeral_key` is checked
inside `zcash_note_encryption::try_output_recovery_with_ock`, and the
requirement to check it inside the `Domain` implementation is being
lifted in zcash/librustzcash#848.

Removing the check here improves performance, both because we avoid an
extra scalar multiplication from `esk.derive_public()`, and because we
avoid an unnecessary `spec::diversify_hash()` call which is expensive
for Orchard.
2023-05-19 16:43:17 +00:00
Constance Beguier c77d96c15c
Merge branch main into zsa1 (#59)
For zcash_note_encryption, we have to use version 0.2 with QEDIT patch.
2023-05-16 12:01:11 +02:00
Constance 4e1c616618 Merge branch 'main' into zsa1 2023-05-16 10:37:22 +02:00
Dmitry Demin 9a35108155
Add getter method for Bundle.burn field (#58)
- Add getter method for Bundle.burn field
2023-05-10 09:23:48 +02:00
Dmitry Demin ea0fd59ec7
Add tracking for supply info inside verify_issue_bundle (#55)
1. Added a new error, `ValueSumOverflow`, that occurs if the sum value overflows when adding new supply amounts.
2. Created a new `supply_info` module containing `SupplyInfo` and `AssetSupply` structures, with `add_supply` function and unit tests for it.
3. Renamed the `are_note_asset_ids_derived_correctly` function to `verify_supply`, changed its behavior to verify and compute asset supply, added unit tests for it.
4. Updated the `verify_issue_bundle` function to use the changes mentioned above, updated its description, and added new unit tests.
5. Renamed errors with `...NoteType` suffix in the name to `...AssetBase`.
6.  Added `update_finalization_set` method to `SupplyInfo` and use after the calls of `verify_issue_bundle function` (if needed), instead of mutating the finalization set inside `verify_issue_bundle`.
2023-05-04 14:40:14 +02:00
Daira Emma Hopwood a38bc537c9 [book] Add a missing right parenthesis. fixes #392
Signed-off-by: Daira Emma Hopwood <daira@jacaranda.org>
2023-05-02 14:53:09 +01:00
Constance Beguier 7d3b6dfe96
Constant-time note commitment for ZEC and ZSA (#54)
We would like to have a constant-time evaluation of the note commitment for both ZEC and ZSA.
ZEC_note_commitment=Extract_P(SinsemillaHashToPoint(zec_personalization, common_bits) + [rcm]R)
ZSA_note_commitment=Extract_P(SinsemillaHashToPoint(zsa_personalization, common_bits || asset) + [rcm]R)

R is the same constant for ZEC and ZSA note commitments.
2023-04-25 14:46:26 +02:00
Constance Beguier 563b4e5502
Circuit: Update value_commit_orchard to take into account asset (#50)
In the circuit, we update value_commit_orchard to take into account asset.
Previously, value_commit_orchard returns cv_net = [v_net] ValueCommitV + [rcv] ValueCommitR..
Now, value_commit_orchard returns cv_net = [v_net] asset + [rcv] ValueCommitR.
ValueCommitV and ValueCommitR are constants
v_net is equal to sign * magnitude where sign is in {-1, 1} and magnitude is an unsigned integer on 64 bits.

To evaluate [v_net] asset where v_net = sign * magnitude, we perform the following steps
1. verify that magnitude is on 64 bits
2. evaluate commitment=[magnitude]asset with the variable-base long-scalar multiplication
3. evaluate result=[sign]commitment with the new mul_sign gate
2023-04-21 14:34:50 +02:00
Vivek Arte f0b794896d
Making changes to the asset base derivation from the asset identifier (#49)
This PR updates the test-vectors from the updates to the zcash-test-vectors repository (see here).

The keys test is also updated to now use the asset base from the test vectors instead of just using the native asset.
2023-04-19 01:00:37 +05:30
Kris Nuttycombe 3619b86d1c
Merge pull request #373 from nuttycom/update_incrementalmerkletree
Update to development versions of incrementalmerkletree/bridgetree
2023-04-12 14:16:38 -06:00
Kris Nuttycombe 8bc53ecbde Update to development versions of incrementalmerkletree/bridgetree
This modifies the tests where required to use bridgetree checkpoint
identifiers.
2023-04-11 10:33:25 -06:00
str4d 7d4aa67eaa
Merge pull request #390 from zcash/release-0.4.0
Release 0.4.0
2023-04-11 14:02:47 +01:00
Jack Grigg 63ab47ecc9 orchard 0.4.0 2023-04-11 09:00:17 +00:00