Skip to content

Commit

Permalink
fix: add take to powers of tau iterator to prevent infinite allocation
Browse files Browse the repository at this point in the history
Signed-off-by: Brandon H. Gomes <bhgomes@pm.me>
  • Loading branch information
bhgomes committed Jul 12, 2022
1 parent c499f2a commit 7a64cb5
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion manta-accounting/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ test = [

[dependencies]
bitflags = { version = "1.3.2", optional = true, default-features = false }
cocoon = { version = "0.3.0", optional = true, default-features = false }
cocoon = { version = "0.3.1", optional = true, default-features = false }
derivative = { version = "2.2.0", default-features = false, features = ["use_core"] }
derive_more = { version = "0.99.16", default-features = false, features = ["add", "add_assign", "display", "from", "sum"] }
futures = { version = "0.3.21", optional = true, default-features = false, features = ["alloc"] }
Expand Down
2 changes: 1 addition & 1 deletion manta-pay/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ ark-std = { version = "0.3.0", optional = true, default-features = false }
bip32 = { version = "0.3.0", optional = true, default-features = false, features = ["bip39", "secp256k1"] }
blake2 = { version = "0.10.4", default-features = false }
bs58 = { version = "0.4.0", optional = true, default-features = false, features = ["alloc"] }
clap = { version = "3.2.8", optional = true, default-features = false, features = ["color", "derive", "std", "suggestions", "unicode", "wrap_help"] }
clap = { version = "3.2.10", optional = true, default-features = false, features = ["color", "derive", "std", "suggestions", "unicode", "wrap_help"] }
derivative = { version = "2.2.0", default-features = false, features = ["use_core"] }
futures = { version = "0.3.21", optional = true, default-features = false }
indexmap = { version = "1.8.2", optional = true, default-features = false }
Expand Down
5 changes: 5 additions & 0 deletions manta-trusted-setup/src/groth16/kzg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,13 @@ use rayon::iter::{IndexedParallelIterator, ParallelIterator};
/// KZG Trusted Setup Size
pub trait Size {
/// Number of G1 Powers to Produce
///
/// The number of G1 powers must be greater than or equal to the number of G2 powers.
const G1_POWERS: usize;

/// Number of G2 Powers to Produce
///
/// The number of G2 powers must be smaller than or equal to the number of G1 powers.
const G2_POWERS: usize;
}

Expand Down Expand Up @@ -523,6 +527,7 @@ where
pub fn update(&mut self, contribution: &Contribution<C>) {
let mut tau_powers =
iter::successors(Some(C::Scalar::one()), |x| Some(x.mul(contribution.tau)))
.take(C::G1_POWERS)
.collect::<Vec<_>>();
let remaining_tau_powers = tau_powers.split_off(C::G2_POWERS);
cfg_iter_mut!(self.tau_powers_g1)
Expand Down
2 changes: 1 addition & 1 deletion manta-util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ std = ["alloc"]
[dependencies]
crossbeam-channel = { version = "0.5.4", optional = true, default-features = false }
rayon = { version = "1.5.3", optional = true, default-features = false }
serde = { version = "1.0.138", optional = true, default-features = false, features = ["derive"] }
serde = { version = "1.0.139", optional = true, default-features = false, features = ["derive"] }
serde_with = { version = "1.14.0", optional = true, default-features = false, features = ["macros"] }
workspace-hack = { version = "0.1.0", path = "../workspace-hack" }
8 changes: 4 additions & 4 deletions workspace-hack/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ anyhow = { version = "1.0.58", features = ["std"] }
bitflags = { version = "1.3.2" }
blake3 = { version = "1.3.1", default-features = false, features = ["digest", "std"] }
block-buffer = { version = "0.9.0", default-features = false, features = ["block-padding"] }
crypto-common = { version = "0.1.4", default-features = false, features = ["std"] }
crypto-common = { version = "0.1.5", default-features = false, features = ["std"] }
digest-93f6ce9d446188ac = { package = "digest", version = "0.10.3", features = ["alloc", "block-buffer", "core-api", "mac", "std", "subtle"] }
digest-274715c4dabd11b0 = { package = "digest", version = "0.9.0", default-features = false, features = ["alloc", "std"] }
futures = { version = "0.3.21", features = ["alloc", "async-await", "executor", "futures-executor", "std"] }
Expand All @@ -40,7 +40,7 @@ ppv-lite86 = { version = "0.2.16", default-features = false, features = ["simd",
rand = { version = "0.8.5", features = ["alloc", "getrandom", "libc", "rand_chacha", "std", "std_rng"] }
rand_chacha = { version = "0.3.1", default-features = false, features = ["std"] }
rand_core = { version = "0.6.3", default-features = false, features = ["alloc", "getrandom", "std"] }
serde = { version = "1.0.138", features = ["alloc", "derive", "serde_derive", "std"] }
serde = { version = "1.0.139", features = ["alloc", "derive", "serde_derive", "std"] }
serde_json = { version = "1.0.82", features = ["alloc", "std"] }
sha2 = { version = "0.9.9", features = ["std"] }
standback = { version = "0.2.17", default-features = false, features = ["std"] }
Expand All @@ -53,12 +53,12 @@ zeroize = { version = "1.5.6", default-features = false, features = ["alloc", "z
anyhow = { version = "1.0.58", features = ["std"] }
blake3 = { version = "1.3.1", default-features = false, features = ["digest", "std"] }
cc = { version = "1.0.73", default-features = false, features = ["jobserver", "parallel"] }
crypto-common = { version = "0.1.4", default-features = false, features = ["std"] }
crypto-common = { version = "0.1.5", default-features = false, features = ["std"] }
digest-93f6ce9d446188ac = { package = "digest", version = "0.10.3", features = ["alloc", "block-buffer", "core-api", "mac", "std", "subtle"] }
generic-array = { version = "0.14.5", default-features = false, features = ["more_lengths"] }
log = { version = "0.4.17", default-features = false, features = ["kv_unstable", "kv_unstable_std", "std", "value-bag"] }
num-traits = { version = "0.2.15", features = ["i128", "libm", "std"] }
serde = { version = "1.0.138", features = ["alloc", "derive", "serde_derive", "std"] }
serde = { version = "1.0.139", features = ["alloc", "derive", "serde_derive", "std"] }
standback = { version = "0.2.17", default-features = false, features = ["std"] }
subtle = { version = "2.4.1", default-features = false, features = ["i128"] }
syn = { version = "1.0.98", features = ["clone-impls", "derive", "extra-traits", "fold", "full", "parsing", "printing", "proc-macro", "quote", "visit", "visit-mut"] }
Expand Down

0 comments on commit 7a64cb5

Please sign in to comment.