Skip to content

Commit

Permalink
Sync with halo2 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dmidem committed Oct 29, 2024
1 parent 8adb3f6 commit fce103d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
2 changes: 2 additions & 0 deletions zebra-chain/src/orchard/note/ciphertexts.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Encrypted parts of Orchard notes.

// FIXME: make it a generic and add support for OrchardZSA (encrypted tote size ofr it is not 580!)

use std::{fmt, io};

use serde_big_array::BigArray;
Expand Down
17 changes: 13 additions & 4 deletions zebra-consensus/src/primitives/halo2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::{

use futures::{future::BoxFuture, FutureExt};
use once_cell::sync::Lazy;
use orchard::circuit::VerifyingKey;
use orchard::{circuit::VerifyingKey, orchard_flavor::OrchardVanilla};
use rand::{thread_rng, CryptoRng, RngCore};

use thiserror::Error;
Expand Down Expand Up @@ -75,7 +75,8 @@ pub type ItemVerifyingKey = VerifyingKey;

lazy_static::lazy_static! {
/// The halo2 proof verifying key.
pub static ref VERIFYING_KEY: ItemVerifyingKey = ItemVerifyingKey::build();
// FIXME: support OrchardZSA?
pub static ref VERIFYING_KEY: ItemVerifyingKey = ItemVerifyingKey::build::<OrchardVanilla>();
}

// === TEMPORARY BATCH HALO2 SUBSTITUTE ===
Expand Down Expand Up @@ -143,6 +144,15 @@ impl From<&zebra_chain::orchard::ShieldedData> for Item {
.flags
.contains(zebra_chain::orchard::Flags::ENABLE_OUTPUTS);

// FIXME: simplify the flags creation - make `Flags::from_parts` method pub?
// FIXME: support OrchardZSA?
let flags = match (enable_spend, enable_output) {
(false, false) => orchard::builder::BundleType::DISABLED.flags(),
(false, true) => orchard::bundle::Flags::SPENDS_DISABLED_WITHOUT_ZSA,
(true, false) => orchard::bundle::Flags::OUTPUTS_DISABLED,
(true, true) => orchard::bundle::Flags::ENABLED_WITHOUT_ZSA,
};

let instances = shielded_data
.actions()
.map(|action| {
Expand All @@ -155,8 +165,7 @@ impl From<&zebra_chain::orchard::ShieldedData> for Item {
))
.expect("should be a valid redpallas spendauth verification key"),
note::ExtractedNoteCommitment::from_bytes(&action.cm_x.into()).unwrap(),
enable_spend,
enable_output,
flags,
)
})
.collect();
Expand Down
24 changes: 20 additions & 4 deletions zebra-consensus/src/primitives/halo2/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ use orchard::{
bundle::Flags,
circuit::ProvingKey,
keys::{FullViewingKey, Scope, SpendingKey},
note::AssetBase,
orchard_flavor::OrchardVanilla,
value::NoteValue,
Anchor, Bundle,
};
Expand All @@ -23,9 +25,10 @@ use zebra_chain::{

use crate::primitives::halo2::*;

// FIXME: add support for OrchardZSA (see OrchardVanilla and AssetBase::native() usage below)
#[allow(dead_code, clippy::print_stdout)]
fn generate_test_vectors() {
let proving_key = ProvingKey::build();
let proving_key = ProvingKey::build::<OrchardVanilla>();

let rng = OsRng;

Expand All @@ -50,11 +53,17 @@ fn generate_test_vectors() {

for _ in 0..num_recipients {
builder
.add_output(None, recipient, NoteValue::from_raw(note_value), None)
.add_output(
None,
recipient,
NoteValue::from_raw(note_value),
AssetBase::native(),
None,
)
.unwrap();
}

let bundle: Bundle<_, i64> = builder.build(rng).unwrap().unwrap().0;
let bundle: Bundle<_, i64, OrchardVanilla> = builder.build(rng).unwrap().unwrap().0;

let bundle = bundle
.create_proof(&proving_key, rng)
Expand All @@ -79,7 +88,14 @@ fn generate_test_vectors() {
rk: <[u8; 32]>::from(a.rk()).into(),
cm_x: pallas::Base::from_repr(a.cmx().into()).unwrap(),
ephemeral_key: a.encrypted_note().epk_bytes.try_into().unwrap(),
enc_ciphertext: a.encrypted_note().enc_ciphertext.into(),
// FIXME: support OrchardZSA too, 580 works for OrchardVanilla only!
// FIXME: consider more "type safe" way to do the following conversion
// (now it goes through &[u8])
enc_ciphertext: <[u8; 580]>::try_from(
a.encrypted_note().enc_ciphertext.as_ref(),
)
.unwrap()
.into(),
out_ciphertext: a.encrypted_note().out_ciphertext.into(),
};
zebra_chain::orchard::shielded_data::AuthorizedAction {
Expand Down

0 comments on commit fce103d

Please sign in to comment.