Skip to content

Commit

Permalink
Remove 0xf6 empty memo convention.
Browse files Browse the repository at this point in the history
This is a standard convention for Zcash memos, but it doesn't have any
relevance to the general Orchard protocol and as such doesn't belong in
this crate.
  • Loading branch information
nuttycom committed Dec 12, 2024
1 parent 5c451be commit 867c33d
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 18 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ and this project adheres to Rust's notion of
- `ValueCommitTrapdoor::to_bytes`
- `impl Clone for orchard::tree::MerklePath`

### Changed
- `orchard::builder::Builder::add_output` now takes a `[u8; 512]` for its
`memo` argument instead of an optional value.

## [0.10.0] - 2024-10-02

### Changed
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 @@ -321,17 +321,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 @@ -342,7 +338,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])
}

/// Builds the output half of an action.
Expand Down Expand Up @@ -578,7 +574,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 @@ -1171,7 +1167,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 @@ -1284,7 +1280,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 @@ -320,7 +320,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 @@ -389,14 +389,14 @@ mod tests {
let mut builder = Builder::new(BundleType::DEFAULT, anchor);
builder.add_spend(fvk.clone(), note, merkle_path).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 @@ -106,7 +106,7 @@ fn bundle_chain() {
let mut builder = Builder::new(BundleType::DEFAULT, anchor);
assert_eq!(builder.add_spend(fvk, note, merkle_path), 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

0 comments on commit 867c33d

Please sign in to comment.