Skip to content
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

Remove 0xf6 empty memo convention. #441

Merged
merged 1 commit into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ and this project adheres to Rust's notion of
- MSRV is now 1.70
- Migrated to `nonempty 0.11`, `incrementalmerkletree 0.8`, `shardtree 0.6`,
`zcash_spec 0.2`, `zip32 0.2`
- `orchard::builder::Builder::add_output` now takes a `[u8; 512]` for its
`memo` argument instead of an optional value.

## [0.10.1] - 2024-12-16

Expand Down
2 changes: 1 addition & 1 deletion benches/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fn criterion_benchmark(c: &mut Criterion) {
let mut builder = Builder::new(BundleType::DEFAULT, Anchor::from_bytes([0; 32]).unwrap());
for _ in 0..num_recipients {
builder
.add_output(None, recipient, NoteValue::from_raw(10), None)
.add_output(None, recipient, NoteValue::from_raw(10), [0; 512])
.unwrap();
}
let bundle: Bundle<_, i64> = builder.build(rng).unwrap().unwrap().0;
Expand Down
4 changes: 2 additions & 2 deletions benches/note_decryption.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ fn bench_note_decryption(c: &mut Criterion) {
// The builder pads to two actions, and shuffles their order. Add two recipients
// so the first action is always decryptable.
builder
.add_output(None, recipient, NoteValue::from_raw(10), None)
.add_output(None, recipient, NoteValue::from_raw(10), [0; 512])
.unwrap();
builder
.add_output(None, recipient, NoteValue::from_raw(10), None)
.add_output(None, recipient, NoteValue::from_raw(10), [0; 512])
.unwrap();
let bundle: Bundle<_, i64> = builder.build(rng).unwrap().unwrap().0;
bundle
Expand Down
16 changes: 6 additions & 10 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,17 +334,13 @@ impl OutputInfo {
ovk: Option<OutgoingViewingKey>,
recipient: Address,
value: NoteValue,
memo: Option<[u8; 512]>,
memo: [u8; 512],
) -> Self {
Self {
ovk,
recipient,
value,
memo: memo.unwrap_or_else(|| {
let mut memo = [0; 512];
memo[0] = 0xf6;
memo
}),
memo,
}
}

Expand All @@ -355,7 +351,7 @@ impl OutputInfo {
let fvk: FullViewingKey = (&SpendingKey::random(rng)).into();
let recipient = fvk.address_at(0u32, Scope::External);

Self::new(None, recipient, NoteValue::zero(), None)
Self::new(None, recipient, NoteValue::zero(), [0u8; 512])
Copy link
Contributor

@daira daira Dec 12, 2024

Choose a reason for hiding this comment

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

This technically changes the behaviour of this function. Since the FVK/IVK that could read the note plaintext is not available to any other party, it doesn't leak that a version of librustzcash past this PR is being used by the sender. Still a bit weird for something that is supposed to be a pure refactoring, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not a pure refactoring, strictly speaking; it is a behavior change. The alternative here would be to just inject random data? But since this then ends up encrypted to a random recipient, I don't think it matters.

Copy link
Contributor

Choose a reason for hiding this comment

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

The protocol spec says that for dummies, we encrypt a real dummy note to a random viewing key. So this is technically an observable change. But in practice that viewing key or its address is never persisted (particularly as we use ovk = None), and thus the information change here is private even to quantum adversaries.

}

/// Builds the output half of an action.
Expand Down Expand Up @@ -594,7 +590,7 @@ impl Builder {
ovk: Option<OutgoingViewingKey>,
recipient: Address,
value: NoteValue,
memo: Option<[u8; 512]>,
memo: [u8; 512],
) -> Result<(), OutputError> {
let flags = self.bundle_type.flags();
if !flags.outputs_enabled() {
Expand Down Expand Up @@ -1192,7 +1188,7 @@ pub mod testing {
let ovk = fvk.to_ovk(scope);

builder
.add_output(Some(ovk.clone()), addr, value, None)
.add_output(Some(ovk.clone()), addr, value, [0u8; 512])
.unwrap();
}

Expand Down Expand Up @@ -1305,7 +1301,7 @@ mod tests {
);

builder
.add_output(None, recipient, NoteValue::from_raw(5000), None)
.add_output(None, recipient, NoteValue::from_raw(5000), [0u8; 512])
.unwrap();
let balance: i64 = builder.value_balance().unwrap();
assert_eq!(balance, -5000);
Expand Down
6 changes: 3 additions & 3 deletions src/pczt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ mod tests {
EMPTY_ROOTS[MERKLE_DEPTH_ORCHARD].into(),
);
builder
.add_output(None, recipient, NoteValue::from_raw(5000), None)
.add_output(None, recipient, NoteValue::from_raw(5000), [0u8; 512])
.unwrap();
let balance: i64 = builder.value_balance().unwrap();
assert_eq!(balance, -5000);
Expand Down Expand Up @@ -442,14 +442,14 @@ mod tests {
.add_spend(fvk.clone(), note, merkle_path.into())
.unwrap();
builder
.add_output(None, recipient, NoteValue::from_raw(10_000), None)
.add_output(None, recipient, NoteValue::from_raw(10_000), [0u8; 512])
.unwrap();
builder
.add_output(
Some(fvk.to_ovk(Scope::Internal)),
fvk.address_at(0u32, Scope::Internal),
NoteValue::from_raw(5_000),
None,
[0u8; 512],
)
.unwrap();
let balance: i64 = builder.value_balance().unwrap();
Expand Down
4 changes: 2 additions & 2 deletions tests/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fn bundle_chain() {
);
let note_value = NoteValue::from_raw(5000);
assert_eq!(
builder.add_output(None, recipient, note_value, None),
builder.add_output(None, recipient, note_value, [0u8; 512]),
Ok(())
);
let (unauthorized, bundle_meta) = builder.build(&mut rng).unwrap().unwrap();
Expand Down Expand Up @@ -112,7 +112,7 @@ fn bundle_chain() {
let mut builder = Builder::new(BundleType::DEFAULT, root.into());
assert_eq!(builder.add_spend(fvk, note, merkle_path.into()), Ok(()));
assert_eq!(
builder.add_output(None, recipient, NoteValue::from_raw(5000), None),
builder.add_output(None, recipient, NoteValue::from_raw(5000), [0u8; 512]),
Ok(())
);
let (unauthorized, _) = builder.build(&mut rng).unwrap().unwrap();
Expand Down
Loading