Skip to content

Commit 7a4be5b

Browse files
authored
Merge pull request #106 from namada-net/bat/bellperson
Change zk backend to bellperson + blstrs
2 parents 5612ccf + 550d29a commit 7a4be5b

File tree

29 files changed

+1328
-921
lines changed

29 files changed

+1328
-921
lines changed

Cargo.lock

Lines changed: 713 additions & 436 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ members = [
88

99

1010
[workspace.package]
11-
version = "2.0.0"
11+
version = "3.0.5"
1212

1313
[profile.release]
1414
lto = true

masp_note_encryption/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ all-features = true
1919
rustdoc-args = ["--cfg", "docsrs"]
2020

2121
[dependencies]
22+
bls12_381 = {package = "nam-blstrs", version = "0.7.1-nam.0" }
2223
cipher = { version = "0.4", default-features = false }
2324
chacha20 = { version = "0.9", default-features = false }
2425
chacha20poly1305 = { version = "0.10", default-features = false }

masp_note_encryption/src/lib.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ enum NoteValidity {
122122
Invalid,
123123
}
124124

125+
pub type ExtractedCommitment = bls12_381::Scalar;
126+
pub type ExtractedCommitmentBytes = [u8; 32];
127+
125128
/// Trait that encapsulates protocol-specific note encryption types and logic.
126129
///
127130
/// This trait enables most of the note encryption logic to be shared between Sapling and
@@ -138,8 +141,6 @@ pub trait Domain {
138141
type IncomingViewingKey;
139142
type OutgoingViewingKey;
140143
type ValueCommitment;
141-
type ExtractedCommitment;
142-
type ExtractedCommitmentBytes: Eq + for<'a> From<&'a Self::ExtractedCommitment>;
143144
type Memo;
144145

145146
/// Derives the `EphemeralSecretKey` corresponding to this note.
@@ -209,7 +210,7 @@ pub trait Domain {
209210
fn derive_ock(
210211
ovk: &Self::OutgoingViewingKey,
211212
cv: &Self::ValueCommitment,
212-
cmstar_bytes: &Self::ExtractedCommitmentBytes,
213+
cmstar_bytes: &ExtractedCommitmentBytes,
213214
ephemeral_key: &EphemeralKeyBytes,
214215
) -> OutgoingCipherKey;
215216

@@ -229,7 +230,7 @@ pub trait Domain {
229230
fn epk(ephemeral_key: &EphemeralKeyBytes) -> Option<Self::EphemeralPublicKey>;
230231

231232
/// Derives the `ExtractedCommitment` for this note.
232-
fn cmstar(note: &Self::Note) -> Self::ExtractedCommitment;
233+
fn cmstar(note: &Self::Note) -> ExtractedCommitment;
233234

234235
/// Parses the given note plaintext from the recipient's perspective.
235236
///
@@ -349,7 +350,7 @@ pub trait ShieldedOutput<D: Domain, const CIPHERTEXT_SIZE: usize> {
349350
fn ephemeral_key(&self) -> EphemeralKeyBytes;
350351

351352
/// Exposes the `cmu_bytes` or `cmx_bytes` field of the output.
352-
fn cmstar_bytes(&self) -> D::ExtractedCommitmentBytes;
353+
fn cmstar_bytes(&self) -> ExtractedCommitmentBytes;
353354

354355
/// Exposes the note ciphertext of the output.
355356
fn enc_ciphertext(&self) -> &[u8; CIPHERTEXT_SIZE];
@@ -450,11 +451,11 @@ impl<D: Domain> NoteEncryption<D> {
450451
pub fn encrypt_outgoing_plaintext<R: RngCore>(
451452
&self,
452453
cv: &D::ValueCommitment,
453-
cmstar: &D::ExtractedCommitment,
454+
cmstar: &ExtractedCommitment,
454455
rng: &mut R,
455456
) -> [u8; OUT_CIPHERTEXT_SIZE] {
456457
let (ock, input) = if let Some(ovk) = &self.ovk {
457-
let ock = D::derive_ock(ovk, cv, &cmstar.into(), &D::epk_bytes(&self.epk));
458+
let ock = D::derive_ock(ovk, cv, &cmstar.to_bytes_le(), &D::epk_bytes(&self.epk));
458459
let input = D::outgoing_plaintext_bytes(&self.note, &self.esk);
459460

460461
(ock, input)
@@ -539,7 +540,7 @@ fn parse_note_plaintext_without_memo_ivk<D: Domain>(
539540
domain: &D,
540541
ivk: &D::IncomingViewingKey,
541542
ephemeral_key: &EphemeralKeyBytes,
542-
cmstar_bytes: &D::ExtractedCommitmentBytes,
543+
cmstar_bytes: &ExtractedCommitmentBytes,
543544
plaintext: &[u8],
544545
) -> Option<(D::Note, D::Recipient)> {
545546
let (note, to) = domain.parse_note_plaintext_without_memo_ivk(ivk, plaintext)?;
@@ -554,9 +555,9 @@ fn parse_note_plaintext_without_memo_ivk<D: Domain>(
554555
fn check_note_validity<D: Domain>(
555556
note: &D::Note,
556557
ephemeral_key: &EphemeralKeyBytes,
557-
cmstar_bytes: &D::ExtractedCommitmentBytes,
558+
cmstar_bytes: &ExtractedCommitmentBytes,
558559
) -> NoteValidity {
559-
if &D::ExtractedCommitmentBytes::from(&D::cmstar(note)) == cmstar_bytes {
560+
if &D::cmstar(note).to_bytes_le() == cmstar_bytes {
560561
if let Some(derived_esk) = D::derive_esk(note) {
561562
if D::epk_bytes(&D::ka_derive_public(note, &derived_esk))
562563
.ct_eq(ephemeral_key)

masp_primitives/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ num-traits = { package = "nam-num-traits", version = "0.2.20-nam.0" }
4343
subtle = "2.2.3"
4444

4545
# - Shielded protocols
46-
bls12_381 = { package = "nam-bls12_381", version = "0.8.1-nam.0" }
46+
bls12_381 = {package = "nam-blstrs", version = "0.7.1-nam.0" }
4747
ff = "0.13"
4848
group = { version = "0.13", features = ["wnaf-memuse"] }
4949
incrementalmerkletree = { version = "0.8.2", features = ["legacy-api"] }
50-
jubjub = { package = "nam-jubjub", version = "0.10.1-nam.0" }
50+
jubjub = { package = "nam-jubjub", version = "1.10.1-nam.1" }
5151
nonempty = "0.11"
5252

5353
# - Static constants
@@ -77,7 +77,7 @@ borsh = {version = "1.2.0", features = ["unstable__schema", "derive"]}
7777
arbitrary = {version = "1.3", features = ["derive"], optional = true }
7878

7979
[dependencies.masp_note_encryption]
80-
version = "2.0.0"
80+
version = "3.0.5"
8181
path = "../masp_note_encryption"
8282
features = ["pre-zip-212"]
8383

@@ -92,7 +92,7 @@ rand_xorshift = "0.3"
9292
transparent-inputs = []
9393
test-dependencies = ["proptest"]
9494
default = ["transparent-inputs"]
95-
arbitrary = ["dep:arbitrary", "masp_note_encryption/arbitrary", "bls12_381/arbitrary", "jubjub/arbitrary"]
95+
arbitrary = ["dep:arbitrary", "masp_note_encryption/arbitrary", "jubjub/arbitrary", "bls12_381/arbitrary"]
9696

9797
[badges]
9898
maintenance = { status = "actively-developed" }

0 commit comments

Comments
 (0)