From fce103d288935e857315da0ff8c7dea8b0be157f Mon Sep 17 00:00:00 2001 From: Dmitry Demin Date: Tue, 29 Oct 2024 12:58:39 +0100 Subject: [PATCH] Sync with halo2 changes --- zebra-chain/src/orchard/note/ciphertexts.rs | 2 ++ zebra-consensus/src/primitives/halo2.rs | 17 +++++++++---- zebra-consensus/src/primitives/halo2/tests.rs | 24 +++++++++++++++---- 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/zebra-chain/src/orchard/note/ciphertexts.rs b/zebra-chain/src/orchard/note/ciphertexts.rs index 8f857cf1444..b27ffbc53a1 100644 --- a/zebra-chain/src/orchard/note/ciphertexts.rs +++ b/zebra-chain/src/orchard/note/ciphertexts.rs @@ -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; diff --git a/zebra-consensus/src/primitives/halo2.rs b/zebra-consensus/src/primitives/halo2.rs index ffc58a5feb8..447d9bbd449 100644 --- a/zebra-consensus/src/primitives/halo2.rs +++ b/zebra-consensus/src/primitives/halo2.rs @@ -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; @@ -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::(); } // === TEMPORARY BATCH HALO2 SUBSTITUTE === @@ -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| { @@ -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(); diff --git a/zebra-consensus/src/primitives/halo2/tests.rs b/zebra-consensus/src/primitives/halo2/tests.rs index e654adcc546..9b5c367e640 100644 --- a/zebra-consensus/src/primitives/halo2/tests.rs +++ b/zebra-consensus/src/primitives/halo2/tests.rs @@ -11,6 +11,8 @@ use orchard::{ bundle::Flags, circuit::ProvingKey, keys::{FullViewingKey, Scope, SpendingKey}, + note::AssetBase, + orchard_flavor::OrchardVanilla, value::NoteValue, Anchor, Bundle, }; @@ -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::(); let rng = OsRng; @@ -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) @@ -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 {