verify_issue_bundle() cleanup (#25)

* improved `verify_issue_bundle()`
This commit is contained in:
Paul 2022-10-28 10:46:02 +03:00 committed by Paul
parent 355b5691ea
commit 9405f801cd
9 changed files with 33 additions and 27 deletions

View File

@ -16,7 +16,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: 1.56.1
toolchain: 1.61
override: true
- name: Run benchmark
run: cargo bench -- --output-format bencher | tee output.txt

View File

@ -14,7 +14,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: 1.56.1
toolchain: 1.61
override: true
- name: Run tests
uses: actions-rs/cargo@v1
@ -30,7 +30,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: 1.56.1
toolchain: 1.61
override: true
# Build benchmarks to prevent bitrot
- name: Build benchmarks
@ -46,7 +46,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: 1.56.1
toolchain: 1.61
override: true
- name: Setup mdBook
uses: peaceiris/actions-mdbook@v1
@ -90,7 +90,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: 1.56.1
toolchain: 1.61
override: true
- name: cargo fetch
uses: actions-rs/cargo@v1
@ -113,7 +113,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: 1.56.1
toolchain: 1.61
override: true
- run: rustup component add rustfmt
- uses: actions-rs/cargo@v1

View File

@ -5,19 +5,19 @@ on: pull_request
jobs:
clippy:
name: Clippy (1.56.1)
name: Clippy (1.61)
timeout-minutes: 30
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: 1.56.1
toolchain: 1.61
components: clippy
override: true
- name: Run Clippy
uses: actions-rs/clippy-check@v1
with:
name: Clippy (1.56.1)
name: Clippy (1.61)
token: ${{ secrets.GITHUB_TOKEN }}
args: --all-features --all-targets -- -D warnings

View File

@ -9,7 +9,7 @@ authors = [
"Kris Nuttycombe <kris@electriccoin.co>",
]
edition = "2021"
rust-version = "1.56.1"
rust-version = "1.61"
description = "The Orchard shielded transaction protocol"
license-file = "LICENSE-BOSL"
repository = "https://github.com/zcash/orchard"

View File

@ -1,6 +1,6 @@
# orchard [![Crates.io](https://img.shields.io/crates/v/orchard.svg)](https://crates.io/crates/orchard) #
Requires Rust 1.56.1+.
Requires Rust 1.61+.
## Documentation

View File

@ -1 +1 @@
1.56.1
1.61

View File

@ -335,32 +335,32 @@ impl IssueBundle<Signed> {
/// Validation for Orchard IssueBundles
///
/// A set of previously finalized asset types must be provided.
/// In case of success, `finalized` will contain a set of the provided **and** the newly finalized `NoteType`s
/// In case of success, `finalized` will contain a set of the provided **and** the newly finalized `AssetId`s
///
/// The following checks are performed:
/// * For the `IssueBundle`:
/// * the Signature on top of the provided `sighash` verifies correctly.
/// * For each `IssueAction`:
/// * Asset description size is collect.
/// * `NoteType` for the `IssueAction` has not been previously finalized.
/// * `AssetId` for the `IssueAction` has not been previously finalized.
/// * For each `Note` inside an `IssueAction`:
/// * All notes have the same, correct `NoteType`.
pub fn verify_issue_bundle(
bundle: &IssueBundle<Signed>,
sighash: [u8; 32],
finalized: &mut HashSet<AssetId>, // The current finalization set.
finalized: &mut HashSet<AssetId>, // The finalization set.
) -> Result<(), Error> {
if let Err(e) = bundle.ik.verify(&sighash, &bundle.authorization.signature) {
return Err(IssueBundleInvalidSignature(e));
};
let currently_finalized: &mut HashSet<AssetId> = &mut HashSet::new();
let s = &mut HashSet::<AssetId>::new();
// Any IssueAction could have just one properly derived NoteType.
let res = bundle
// An IssueAction could have just one properly derived AssetId.
let newly_finalized = bundle
.actions()
.iter()
.try_fold(currently_finalized, |acc, action| {
.try_fold(s, |newly_finalized, action| {
if !is_asset_desc_of_valid_size(action.asset_desc()) {
return Err(WrongAssetDescSize);
}
@ -368,21 +368,21 @@ pub fn verify_issue_bundle(
// Fail if any note in the IssueAction has incorrect note type.
let asset = action.are_note_asset_ids_derived_correctly(bundle.ik())?;
// Fail if the current asset was previously finalized.
if finalized.contains(&asset) || acc.contains(&asset) {
// Fail if the asset was previously finalized.
if finalized.contains(&asset) || newly_finalized.contains(&asset) {
return Err(IssueActionPreviouslyFinalizedNoteType(asset));
}
// Add to finalization set, if needed.
if action.is_finalized() {
acc.insert(asset);
newly_finalized.insert(asset);
}
// Proceed with the new asset finalization set.
Ok(acc)
// Proceed with the new finalization set.
Ok(newly_finalized)
})?;
finalized.extend(res.iter());
finalized.extend(newly_finalized.iter());
Ok(())
}

View File

@ -161,7 +161,13 @@ impl Note {
mut rng: impl RngCore,
) -> Self {
loop {
let note = Note::from_parts(recipient, value, asset, rho, RandomSeed::random(&mut rng, &rho));
let note = Note::from_parts(
recipient,
value,
asset,
rho,
RandomSeed::random(&mut rng, &rho),
);
if note.is_some().into() {
break note.unwrap();
}

View File

@ -13,7 +13,7 @@ use orchard::{
builder::Builder,
bundle::Flags,
circuit::{ProvingKey, VerifyingKey},
keys::{FullViewingKey, Scope, SpendAuthorizingKey, SpendingKey, PreparedIncomingViewingKey},
keys::{FullViewingKey, PreparedIncomingViewingKey, Scope, SpendAuthorizingKey, SpendingKey},
value::NoteValue,
Address, Anchor, Bundle, Note,
};