Skip to content

Sapling note encryption#69

Merged
str4d merged 25 commits into
zcash:masterfrom
str4d:sapling-note-encryption
Jun 6, 2019
Merged

Sapling note encryption#69
str4d merged 25 commits into
zcash:masterfrom
str4d:sapling-note-encryption

Conversation

@str4d
Copy link
Copy Markdown
Contributor

@str4d str4d commented Mar 7, 2019

Implements full trial decryption (per the protocol spec) as well as compact trial decryption (per ZIP 307).

Comment thread zcash_primitives/src/keys.rs Outdated
Comment thread zcash_primitives/src/note_encryption.rs Outdated
Comment thread zcash_primitives/src/note_encryption.rs Outdated
Comment thread zcash_primitives/src/note_encryption.rs Outdated
Comment thread zcash_primitives/src/note_encryption.rs Outdated
Comment thread zcash_primitives/src/note_encryption.rs Outdated
Comment thread zcash_primitives/src/note_encryption.rs Outdated
Comment thread zcash_primitives/src/note_encryption.rs Outdated
@str4d
Copy link
Copy Markdown
Contributor Author

str4d commented Mar 23, 2019

Addressed @ebfull's comments.

@str4d str4d force-pushed the sapling-note-encryption branch from d4e6a66 to e17e4b1 Compare April 5, 2019 20:08
@str4d str4d requested a review from ebfull April 5, 2019 20:08
@str4d
Copy link
Copy Markdown
Contributor Author

str4d commented Apr 5, 2019

Rebased on master to address merge conflicts.

str4d added 2 commits April 11, 2019 06:33
This crate exposes both the ChaCha20Poly1305 IETF construction, and the
underlying ChaCha20 IETF primitive, removing the need for depending on
our own fork of the previous chacha20-poly1305-aead crate.
The crypto_api_chachapoly uses two new features introduced in 1.32:

- Self struct constructors
- u64::to_le_bytes()
@str4d
Copy link
Copy Markdown
Contributor Author

str4d commented Apr 11, 2019

In the last month, a new crate has been published that exposes both the ChaCha20Poly1305 IETF construction and the underlying ChaCha20 IETF primitive. I've pushed a commit that switches us from our own fork of an implementation (which would inhibit us publishing crates) to this new crate. The previous test vectors all pass.

Note that this requires raising our minimum Rust version to 1.32. Incidentally, by doing this we should be able to replace our own usage of the byteorder crate with conversion functions on the inbuilt primitives.

@str4d str4d force-pushed the sapling-note-encryption branch from 9207b35 to edf7bc1 Compare April 11, 2019 23:13
@str4d str4d mentioned this pull request Apr 16, 2019
bitcartel pushed a commit to bitcartel/librustzcash that referenced this pull request May 16, 2019
Copy link
Copy Markdown
Contributor

@Eirik0 Eirik0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just had a couple of minor nits. I requested changes.

Comment thread zcash_primitives/src/note_encryption.rs Outdated
Comment thread zcash_primitives/src/note_encryption.rs
Comment thread zcash_primitives/src/note_encryption.rs
Comment thread zcash_primitives/src/note_encryption.rs
@daira
Copy link
Copy Markdown
Contributor

daira commented May 28, 2019

Please note that merging this also blocks on reviewing the crypto_api and crypto_api_chachapoly crates. We shouldn't switch to them without verifying that they have identical behaviour on all inputs.

@str4d
Copy link
Copy Markdown
Contributor Author

str4d commented May 29, 2019

@daira we don't yet depend on any Chacha20Poly1305 implementation in the Rust codebase. When I said "switch", I meant that this PR originally added a dependency on (a fork of) one implementation, and it now adds a dependency on a different implementation. I agree that we should still be happy that the dependency is solid for our usage.

Copy link
Copy Markdown
Contributor

@Eirik0 Eirik0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK modulo @daira's comment

@mms710 mms710 requested a review from daira May 30, 2019 17:08
@daira
Copy link
Copy Markdown
Contributor

daira commented May 30, 2019

@defuse, @str4d and I reviewed the crypto_api_chachapoly AEAD implementation. I initially thought that there was a problem with this implementation when the AAD (which we don't use) or the plaintext is not a multiple of 16 bytes — but I was mistaken. The necessary padding is implemented correctly in poly1305_update here:
https://github.com/KizzyCode/crypto_api_chachapoly/blob/933944e01d83064907613f7964044f333828e9de/src/poly1305.rs#L41-L57
and the is_last flag is used correctly by the caller here:
https://github.com/KizzyCode/crypto_api_chachapoly/blob/933944e01d83064907613f7964044f333828e9de/src/poly1305.rs#L134-L147

I have not yet reviewed the PR itself.

@str4d
Copy link
Copy Markdown
Contributor Author

str4d commented Jun 4, 2019

Two issues were opened on crypto_api_chachapoly as a result of the review, which do not affect this PR:

Copy link
Copy Markdown
Contributor

@daira daira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some changes needed.

Comment thread zcash_primitives/src/keys.rs
Comment thread zcash_primitives/src/keys.rs
Comment thread zcash_primitives/src/note_encryption.rs
Comment thread zcash_primitives/src/note_encryption.rs Outdated
Comment thread zcash_primitives/src/note_encryption.rs Outdated

let pk_d = edwards::Point::<Bls12, _>::read(&op[0..32], &JUBJUB)
.ok()?
.as_prime_order(&JUBJUB)?;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as_prime_order does not check that the point is of prime order (in KASapling.PublicPrimeOrder which is J(r)∗), as required by section 4.17.3. It only checks that it is in the prime-order subgroup J(r).

Misleading method name as_prime_order noted at zcash/sapling-crypto#97 (comment) .

Comment thread zcash_primitives/src/note_encryption.rs
Comment thread zcash_primitives/src/note_encryption.rs
assert_eq!(&ne.encrypt_outgoing_plaintext(&cv, &cmu)[..], &tv.c_out[..]);
}
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Despite my nitpicking, these are excellent tests! 👍

}

pub(crate) fn make_test_vectors() -> Vec<TestVector> {
// From https://github.com/zcash-hackworks/zcash-test-vectors/blob/master/sapling_note_encryption.py
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not checked that these match the source.

@str4d
Copy link
Copy Markdown
Contributor Author

str4d commented Jun 6, 2019

Addressed @daira's comments. I also replaced all uses of Vec with fixed-length arrays.

@str4d str4d requested a review from daira June 6, 2019 12:58
Copy link
Copy Markdown
Contributor

@daira daira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ut(ACK+cov) modulo one unaddressed comment (the missing spec reference).

Comment thread Cargo.lock
"checksum constant_time_eq 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8ff012e225ce166d4422e0e78419d901719760f62ae2b7969ca6b564d1b54a9e"
"checksum crossbeam 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "24ce9782d4d5c53674646a6a4c1863a21a8fc0cb649b3c94dfc16e45071dea19"
"checksum crypto_api 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2f855e87e75a4799e18b8529178adcde6fd4f97c1449ff4821e747ff728bb102"
"checksum crypto_api_chachapoly 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9ee35dbace0831b5fe7cb9b43eb029aa14a10f594a115025d4628a2baa63ab"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not checked these hashes.

Comment thread zcash_primitives/src/keys.rs
NOTE_PLAINTEXT_SIZE
);

// Check note plaintext version
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@str4d
Copy link
Copy Markdown
Contributor Author

str4d commented Jun 6, 2019

@daira the comment was added to the top of the file in 23aa869.

@str4d str4d merged commit 3b6f5e3 into zcash:master Jun 6, 2019
@str4d str4d deleted the sapling-note-encryption branch June 6, 2019 19:50
KizzyCode added a commit to KizzyCode/crypto_api_chachapoly that referenced this pull request Jun 6, 2019
@str4d str4d mentioned this pull request Aug 5, 2019
@str4d str4d added this to the v0.1.0 milestone Aug 22, 2019
greg0x pushed a commit to valargroup/librustzcash that referenced this pull request Mar 12, 2026
…cash#69)

* Ballot scaling in ZKP #1: convert zatoshi to ballot count

Replace the minimum-weight check (condition 8) with ballot scaling
that floor-divides v_total by 12,500,000 to produce num_ballots.
Condition 7 now hashes num_ballots into the VAN commitment instead
of the raw v_total.

Circuit constraints for condition 8:
- num_ballots * BALLOT_DIVISOR + remainder == v_total
- remainder < 2^24 (via shift-by-2^6 into 30-bit lookup check)
- 0 < num_ballots <= 2^30 (via nb_minus_one 30-bit range check)

Adds MulChip (c = a * b gate) used for the reconstruction constraint
and the remainder bit-shift.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Apply ballot scaling to VAN hashes in ZKP #2 and librustvoting

ZKP #1 now hashes num_ballots (not raw zatoshi) into VAN commitments.
Update all downstream VAN hash callers to match:
- vote_proof/builder.rs: convert total_note_value to num_ballots before
  VAN integrity hashing and share splitting
- governance.rs: construct_van now divides total_weight by BALLOT_DIVISOR
- Update test values to use weights >= 12,500,000 (one ballot minimum)
- Freeze new known-answer VAN test vector

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants