Skip to content

Commit

Permalink
Merge pull request #2258 from AleoHQ/feat/parallelize-signature-deser…
Browse files Browse the repository at this point in the history
…ialization

Parallelize signature deserialization
  • Loading branch information
howardwu authored Dec 19, 2023
2 parents 488a31b + 0bc0295 commit 9743017
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 7 deletions.
1 change: 1 addition & 0 deletions console/account/src/compute_key/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ mod bytes;
mod from_bits;
mod serialize;
mod size_in_bits;
mod size_in_bytes;
mod to_address;
mod to_bits;
mod to_fields;
Expand Down
23 changes: 23 additions & 0 deletions console/account/src/compute_key/size_in_bytes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (C) 2019-2023 Aleo Systems Inc.
// This file is part of the snarkVM library.

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
// http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use super::*;

impl<N: Network> SizeInBytes for ComputeKey<N> {
/// Returns the compute key size in bytes.
#[inline]
fn size_in_bytes() -> usize {
Group::<N>::size_in_bytes() + Group::<N>::size_in_bytes()
}
}
1 change: 1 addition & 0 deletions console/account/src/signature/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ mod from_bits;
mod parse;
mod serialize;
mod size_in_bits;
mod size_in_bytes;
mod to_bits;
mod to_fields;
mod verify;
Expand Down
23 changes: 23 additions & 0 deletions console/account/src/signature/size_in_bytes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (C) 2019-2023 Aleo Systems Inc.
// This file is part of the snarkVM library.

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
// http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use super::*;

impl<N: Network> SizeInBytes for Signature<N> {
/// Returns the signature size in bytes.
#[inline]
fn size_in_bytes() -> usize {
Scalar::<N>::size_in_bytes() + Scalar::<N>::size_in_bytes() + ComputeKey::<N>::size_in_bytes()
}
}
1 change: 1 addition & 0 deletions console/network/environment/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub mod prelude {
pub use snarkvm_curves::{AffineCurve, MontgomeryParameters, ProjectiveCurve, TwistedEdwardsParameters};
pub use snarkvm_fields::{Field as _, PrimeField as _, SquareRootField as _, Zero as _};
pub use snarkvm_utilities::{
cfg_chunks,
cfg_find,
cfg_find_map,
cfg_into_iter,
Expand Down
13 changes: 6 additions & 7 deletions ledger/narwhal/batch-certificate/src/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,13 @@ impl<N: Network> FromBytes for BatchCertificate<N> {
Self::MAX_SIGNATURES
)));
}
// Read the signature bytes.
let mut signature_bytes = vec![0u8; num_signatures as usize * Signature::<N>::size_in_bytes()];
reader.read_exact(&mut signature_bytes)?;
// Read the signatures.
let mut signatures = IndexSet::with_capacity(num_signatures as usize);
for _ in 0..num_signatures {
// Read the signature.
let signature = Signature::read_le(&mut reader)?;
// Insert the signature.
signatures.insert(signature);
}
let signatures = cfg_chunks!(signature_bytes, Signature::<N>::size_in_bytes())
.map(Signature::read_le)
.collect::<Result<IndexSet<_>, _>>()?;
// Return the batch certificate.
Self::from(batch_header, signatures).map_err(error)
} else {
Expand Down

0 comments on commit 9743017

Please sign in to comment.