-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ZSA bundle enum #78
base: zsa1
Are you sure you want to change the base?
ZSA bundle enum #78
Conversation
PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here. PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here. PR Code Suggestions ✨Explore these optional code suggestions:
|
dfb4fe8
to
1c6529c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please update the branches (especially Orchard with regard to QED-it/orchard#119)
Cargo.toml
Outdated
@@ -58,7 +58,7 @@ sapling = { package = "sapling-crypto", version = "0.1.3" } | |||
|
|||
# - Orchard | |||
nonempty = "0.7" | |||
orchard = { version = "0.8.0", default-features = false, git = "https://github.com/QED-it/orchard", branch = "zsa1" } | |||
orchard = { version = "0.8.0", default-features = false, git = "https://github.com/QED-it/orchard", branch = "spendauth_clone" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need the related PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, there is an open PR in Orchard
QED-it/orchard#125
.github/workflows/ci.yml
Outdated
# strategy: | ||
# matrix: | ||
# target: | ||
# - wasm32-wasi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why?
It worked this far: https://github.com/QED-it/librustzcash/actions/runs/11270263928/job/31340598915
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've brought it back, let's see
Cargo.toml
Outdated
@@ -127,4 +127,4 @@ codegen-units = 1 | |||
[patch.crates-io] | |||
zcash_note_encryption = { version = "0.4", git = "https://github.com/QED-it/zcash_note_encryption", branch = "zsa1" } | |||
sapling = { package = "sapling-crypto", version = "0.1.3", git = "https://github.com/QED-it/sapling-crypto", branch = "zsa1" } | |||
orchard = { version = "0.8.0", git = "https://github.com/QED-it/orchard", branch = "zsa1" } | |||
orchard = { version = "0.8.0", default-features = false, git = "https://github.com/QED-it/orchard", branch = "spendauth_clone" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't follow, shouldn't we use the branch from QED-it/orchard#119 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is based on the one you mention
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the one i mentioned is remove_circuit_param. But I prefer zsa1
and a commit hash
&self.orchard_saks, | ||
) | ||
}) | ||
.unwrap(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do not ignore the possibility of error here: (x2)
let orchard_bundle: Option<OrchardBundle<_>> = match unauthed_tx.orchard_bundle {
Some(OrchardBundle::OrchardVanilla(b)) => {
Some(OrchardBundle::OrchardVanilla(Box::new(
b.create_proof(
&orchard::circuit::ProvingKey::build::<OrchardVanilla>(),
&mut rng,
)
.and_then(|b| {
b.apply_signatures(
&mut rng,
*shielded_sig_commitment.as_ref(),
&self.orchard_saks,
)
})
.map_err(Error::OrchardBuild)?,
)))
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
7bac6f1
to
387c5d8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks much better! waiting for the test vectors.
This reverts commit f33189f.
205bc9f
to
9f947f8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in transaction/mod.rs
, pub fn vanilla_bundle(&self)
should be
pub fn as_vanilla_bundle(&self) -> &Bundle<A, Amount, OrchardVanilla> {
match self {
OrchardBundle::OrchardVanilla(b) => b,
// #[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )]
OrchardBundle::OrchardZSA(_) => panic!("Wrong bundle type"),
}
}
and have a as_orchard_zsa()
function for symmetry.
_ => Err(Box::leak( | ||
format!("Unknown consensus branch ID: {:08x}", value).into_boxed_str(), | ||
)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wow
try
type Error = String;
fn try_from(value: u32) -> Result<Self, Self::Error> {
match value {
0 => Ok(BranchId::Sprout),
...
_=> Err(format!("Unknown consensus branch ID: {:08x}", value)),
}
and update the caller to &e
, if you really want this.
Also note and fix the format of the caller: "Unknown consensus branch ID:" is already there (their mistake, but still)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed that, that was my debug code, that leaked to production
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
much better, added comments.
Also, for OrchardBundle
remove the Boxes, it is not needed now.
@@ -879,12 +877,12 @@ impl<'a, P: consensus::Parameters, U: sapling::builder::ProverProgress> Builder< | |||
{ | |||
let (bundle, meta) = builder.build(&mut rng).map_err(Error::OrchardBuild)?; | |||
|
|||
unproven_orchard_zsa_bundle = Some(bundle); | |||
unproven_orchard_bundle = Some(OrchardBundle::OrchardZSA(Box::new(bundle))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as mentioned, boxes should be removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed
.and_then(|b| { | ||
b.apply_signatures( | ||
&mut rng, | ||
*shielded_sig_commitment.as_ref(), | ||
&self.orchard_saks, | ||
) | ||
}) | ||
.map_err(Error::OrchardBuild)?, | ||
))) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider
fn prove_and_sign<B>(
bundle: B,
rng: &mut impl RngCore,
proving_key: &orchard::circuit::ProvingKey<B>,
shielded_sig_commitment: &[u8; 32],
orchard_saks: &Vec<orchard::keys::SpendingKey>,
) -> Result<B, Error<FE>>
where
B: orchard::bundle::Bundle + Sized,
{
bundle
.create_proof(proving_key, rng)
.and_then(|b| b.apply_signatures(rng, *shielded_sig_commitment, orchard_saks))
.map_err(Error::OrchardBuild)
}
instead of repeating the same logic twice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good idea
writer.write_all(&<[u8; 64]>::from( | ||
bundle.authorization().binding_signature(), | ||
))?; | ||
match bundle { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if let Some(bundle) = bundle {
(bundle is already a ref)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
} else { | ||
CompactSize::write(&mut writer, 0)?; | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
/// Writes an [`Bundle`] in the appropriate transaction format. | ||
pub fn write_orchard_vanilla_bundle<W: Write>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please make sure that the diff between upstream and us is just a rename from write_v5_bundle()
and nothing more. (not the content of the function)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've synced them, there is only small difference in writing 0 if dundle is None, I do it one layer higher. Everything related to actual write of non-empty bundle is identical
// overwrite the value balance, as we can't guarantee that the | ||
// value doesn't exceed the MAX_MONEY bounds. | ||
bundle.try_map_value_balance::<_, (), _>(|_| Ok(orchard_value_balance)).unwrap() | ||
let _bundle: Bundle<_, _, OrchardZSA> = bundle.try_map_value_balance::<_, (), _>(|_| Ok(orchard_value_balance)).unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
: Bundle<_, _, OrchardZSA>
is redundent, so is the _bundle
var
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
orchard_bundle, | ||
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )] | ||
orchard_zsa_bundle: None, | ||
orchard_bundle: orchard_bundle.map(|b| OrchardBundle::OrchardVanilla(Box::new(b))), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
orchard_bundle: orchard_bundle.map(OrchardBundle::OrchardVanilla),
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -942,8 +928,7 @@ impl Transaction { | |||
transparent_bundle, | |||
sprout_bundle: None, | |||
sapling_bundle, | |||
orchard_bundle: None, | |||
orchard_zsa_bundle, | |||
orchard_bundle: orchard_zsa_bundle.map(|b| OrchardBundle::OrchardZSA(Box::new(b))), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
orchard_bundle: orchard_zsa_bundle.map(OrchardBundle::OrchardZSA),
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
use crate::{ | ||
consensus::BranchId, legacy::Script, transaction::components::amount::NonNegativeAmount, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should not move existing unrelated imports
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved back
orchard_bundle.map(|b| b.commitment().0) | ||
orchard_bundle.map(|b| { | ||
match b { | ||
OrchardBundle::OrchardVanilla(vanilla_bundle) => vanilla_bundle.commitment().0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reduce boilerplate
OrchardVanilla(b) => b.commitment().0,
(import + rename) (x2)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what we reduce here. Just var name length? Then it's shadowing which is also not very nice
) -> Self::OrchardDigest { | ||
orchard_bundle.map_or_else(bundle::commitments::hash_bundle_auth_empty, |b| { | ||
b.authorizing_commitment().0 | ||
match b { | ||
OrchardBundle::OrchardVanilla(vanilla_bundle) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same OrchardVanilla(b) => b.authorizing_commitment().0,
(x2)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
User description
Replace 2 separate Orchard bundle with a single enum
PR Type
enhancement
Description
OrchardBundle
enum to consolidate the handling of Orchard bundles, replacing separate variables for different bundle types.BuildBundle
trait for constructingOrchardVanilla
andOrchardZSA
bundles.OrchardBundle
enum, simplifying the code and removing redundancy.orchard
dependency branch inCargo.toml
tospendauth_clone
.Changes walkthrough 📝
builder.rs
Consolidate Orchard bundle handling with `OrchardBundle` enum
zcash_primitives/src/transaction/builder.rs
OrchardBundle
enum.
OrchardBundle
enum types.unproven_orchard_zsa_bundle
variable.orchard.rs
Implement `BuildBundle` trait and update bundle handling
zcash_primitives/src/transaction/components/orchard.rs
BuildBundle
trait for constructing bundles.BuildBundle
forOrchardVanilla
andOrchardZSA
.OrchardBundle
.mod.rs
Unify Orchard bundle handling with `OrchardBundle` enum
zcash_primitives/src/transaction/mod.rs
OrchardBundle
enum to unify bundle handling.OrchardBundle
.OrchardZSA
bundles.txid.rs
Update transaction digest logic for `OrchardBundle`
zcash_primitives/src/transaction/txid.rs
OrchardBundle
.OrchardZSA
.tests.rs
Update tests for unified `OrchardBundle` handling
zcash_primitives/src/transaction/tests.rs
OrchardBundle
handling.OrchardZSA
.Cargo.toml
Update `orchard` dependency branch
Cargo.toml
orchard
dependency branch tospendauth_clone
.