diff --git a/Cargo.lock b/Cargo.lock index b6c468eb28..3dbc727905 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -258,7 +258,8 @@ dependencies = [ [[package]] name = "ark-ec" version = "0.5.0" -source = "git+https://github.com/openmina/algebra?branch=rebase-fix-openmina-webnode#0ee1798c746a0cf44b1336f943be138e491a7804" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43d68f2d516162846c1238e755a7c4d131b892b70cc70c471a8e3ca3ed818fce" dependencies = [ "ahash 0.8.8", "ark-ff", @@ -279,7 +280,8 @@ dependencies = [ [[package]] name = "ark-ff" version = "0.5.0" -source = "git+https://github.com/openmina/algebra?branch=rebase-fix-openmina-webnode#0ee1798c746a0cf44b1336f943be138e491a7804" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a177aba0ed1e0fbb62aa9f6d0502e9b46dad8c2eab04c14258a1212d2557ea70" dependencies = [ "ark-ff-asm", "ark-ff-macros", @@ -299,7 +301,8 @@ dependencies = [ [[package]] name = "ark-ff-asm" version = "0.5.0" -source = "git+https://github.com/openmina/algebra?branch=rebase-fix-openmina-webnode#0ee1798c746a0cf44b1336f943be138e491a7804" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62945a2f7e6de02a31fe400aa489f0e0f5b2502e69f95f853adb82a96c7a6b60" dependencies = [ "quote 1.0.35", "syn 2.0.96", @@ -308,7 +311,8 @@ dependencies = [ [[package]] name = "ark-ff-macros" version = "0.5.0" -source = "git+https://github.com/openmina/algebra?branch=rebase-fix-openmina-webnode#0ee1798c746a0cf44b1336f943be138e491a7804" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09be120733ee33f7693ceaa202ca41accd5653b779563608f1234f78ae07c4b3" dependencies = [ "num-bigint", "num-traits", @@ -320,7 +324,8 @@ dependencies = [ [[package]] name = "ark-poly" version = "0.5.0" -source = "git+https://github.com/openmina/algebra?branch=rebase-fix-openmina-webnode#0ee1798c746a0cf44b1336f943be138e491a7804" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "579305839da207f02b89cd1679e50e67b4331e2f9294a57693e5051b7703fe27" dependencies = [ "ahash 0.8.8", "ark-ff", @@ -346,7 +351,8 @@ dependencies = [ [[package]] name = "ark-serialize" version = "0.5.0" -source = "git+https://github.com/openmina/algebra?branch=rebase-fix-openmina-webnode#0ee1798c746a0cf44b1336f943be138e491a7804" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f4d068aaf107ebcd7dfb52bc748f8030e0fc930ac8e360146ca54c1203088f7" dependencies = [ "ark-serialize-derive", "ark-std 0.5.0", @@ -359,7 +365,8 @@ dependencies = [ [[package]] name = "ark-serialize-derive" version = "0.5.0" -source = "git+https://github.com/openmina/algebra?branch=rebase-fix-openmina-webnode#0ee1798c746a0cf44b1336f943be138e491a7804" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "213888f660fddcca0d257e88e54ac05bca01885f258ccdf695bafd77031bb69d" dependencies = [ "proc-macro2 1.0.95", "quote 1.0.35", @@ -3482,7 +3489,7 @@ dependencies = [ [[package]] name = "groupmap" version = "0.1.0" -source = "git+https://github.com/openmina/proof-systems?rev=d1912bca54d2609296b9af9d09ad1ef78702e203#d1912bca54d2609296b9af9d09ad1ef78702e203" +source = "git+https://github.com/o1-labs/proof-systems?rev=c513810dddec410c4065df359a66b1adfdf1aa23#c513810dddec410c4065df359a66b1adfdf1aa23" dependencies = [ "ark-ec", "ark-ff", @@ -4244,7 +4251,7 @@ dependencies = [ [[package]] name = "internal-tracing" version = "0.1.0" -source = "git+https://github.com/openmina/proof-systems?rev=d1912bca54d2609296b9af9d09ad1ef78702e203#d1912bca54d2609296b9af9d09ad1ef78702e203" +source = "git+https://github.com/o1-labs/proof-systems?rev=c513810dddec410c4065df359a66b1adfdf1aa23#c513810dddec410c4065df359a66b1adfdf1aa23" [[package]] name = "io-lifetimes" @@ -4414,7 +4421,7 @@ dependencies = [ [[package]] name = "kimchi" version = "0.1.0" -source = "git+https://github.com/openmina/proof-systems?rev=d1912bca54d2609296b9af9d09ad1ef78702e203#d1912bca54d2609296b9af9d09ad1ef78702e203" +source = "git+https://github.com/o1-labs/proof-systems?rev=c513810dddec410c4065df359a66b1adfdf1aa23#c513810dddec410c4065df359a66b1adfdf1aa23" dependencies = [ "ark-ec", "ark-ff", @@ -5193,7 +5200,7 @@ dependencies = [ [[package]] name = "mina-curves" version = "0.1.0" -source = "git+https://github.com/openmina/proof-systems?rev=d1912bca54d2609296b9af9d09ad1ef78702e203#d1912bca54d2609296b9af9d09ad1ef78702e203" +source = "git+https://github.com/o1-labs/proof-systems?rev=c513810dddec410c4065df359a66b1adfdf1aa23#c513810dddec410c4065df359a66b1adfdf1aa23" dependencies = [ "ark-bn254", "ark-ec", @@ -5229,7 +5236,7 @@ dependencies = [ [[package]] name = "mina-hasher" version = "0.1.0" -source = "git+https://github.com/openmina/proof-systems?rev=d1912bca54d2609296b9af9d09ad1ef78702e203#d1912bca54d2609296b9af9d09ad1ef78702e203" +source = "git+https://github.com/o1-labs/proof-systems?rev=c513810dddec410c4065df359a66b1adfdf1aa23#c513810dddec410c4065df359a66b1adfdf1aa23" dependencies = [ "ark-ff", "bitvec", @@ -5448,6 +5455,7 @@ dependencies = [ "alloc-test", "anyhow", "ark-ff", + "ark-serialize 0.5.0", "base64 0.22.1", "binprot", "binprot_derive", @@ -5464,7 +5472,7 @@ dependencies = [ "mina-hasher", "mina-macros", "mina-signer", - "num-bigint", + "num-bigint-generic", "o1-utils", "poseidon", "rsexp", @@ -5486,7 +5494,7 @@ dependencies = [ [[package]] name = "mina-poseidon" version = "0.1.0" -source = "git+https://github.com/openmina/proof-systems?rev=d1912bca54d2609296b9af9d09ad1ef78702e203#d1912bca54d2609296b9af9d09ad1ef78702e203" +source = "git+https://github.com/o1-labs/proof-systems?rev=c513810dddec410c4065df359a66b1adfdf1aa23#c513810dddec410c4065df359a66b1adfdf1aa23" dependencies = [ "ark-ec", "ark-ff", @@ -5528,7 +5536,7 @@ dependencies = [ [[package]] name = "mina-signer" version = "0.1.0" -source = "git+https://github.com/openmina/proof-systems?rev=d1912bca54d2609296b9af9d09ad1ef78702e203#d1912bca54d2609296b9af9d09ad1ef78702e203" +source = "git+https://github.com/o1-labs/proof-systems?rev=c513810dddec410c4065df359a66b1adfdf1aa23#c513810dddec410c4065df359a66b1adfdf1aa23" dependencies = [ "ark-ec", "ark-ff", @@ -5538,6 +5546,7 @@ dependencies = [ "hex", "mina-curves", "mina-hasher", + "num-bigint", "o1-utils", "rand", "sha2 0.10.8", @@ -6023,13 +6032,13 @@ dependencies = [ [[package]] name = "num-bigint" version = "0.4.6" -source = "git+https://github.com/openmina/num-bigint?branch=rebase-onstack#5b79c7beecd32fd91ae2332b77d079f748eeacf5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" dependencies = [ "num-integer", "num-traits", "rand", "serde", - "tinyvec", ] [[package]] @@ -6051,7 +6060,7 @@ dependencies = [ [[package]] name = "num-bigint-generic" -version = "0.4.6" +version = "0.4.4" dependencies = [ "arbitrary", "num-integer", @@ -6101,7 +6110,8 @@ dependencies = [ [[package]] name = "num-rational" version = "0.4.2" -source = "git+https://github.com/openmina/num-rational?branch=rebase-onstack#be8f2bfa63191b3819739cbe286507cda88ce607" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f83d14da390562dca69fc84082e73e548e1ad308d24accdedd2720017cb37824" dependencies = [ "num-bigint", "num-integer", @@ -6193,7 +6203,7 @@ dependencies = [ [[package]] name = "o1-utils" version = "0.1.0" -source = "git+https://github.com/openmina/proof-systems?rev=d1912bca54d2609296b9af9d09ad1ef78702e203#d1912bca54d2609296b9af9d09ad1ef78702e203" +source = "git+https://github.com/o1-labs/proof-systems?rev=c513810dddec410c4065df359a66b1adfdf1aa23#c513810dddec410c4065df359a66b1adfdf1aa23" dependencies = [ "ark-ec", "ark-ff", @@ -6868,7 +6878,7 @@ dependencies = [ [[package]] name = "poly-commitment" version = "0.1.0" -source = "git+https://github.com/openmina/proof-systems?rev=d1912bca54d2609296b9af9d09ad1ef78702e203#d1912bca54d2609296b9af9d09ad1ef78702e203" +source = "git+https://github.com/o1-labs/proof-systems?rev=c513810dddec410c4065df359a66b1adfdf1aa23#c513810dddec410c4065df359a66b1adfdf1aa23" dependencies = [ "ark-ec", "ark-ff", @@ -6951,6 +6961,7 @@ dependencies = [ "ark-ff", "ark-serialize 0.5.0", "mina-curves", + "o1-utils", "once_cell", "serde", ] @@ -9846,7 +9857,7 @@ dependencies = [ [[package]] name = "turshi" version = "0.1.0" -source = "git+https://github.com/openmina/proof-systems?rev=d1912bca54d2609296b9af9d09ad1ef78702e203#d1912bca54d2609296b9af9d09ad1ef78702e203" +source = "git+https://github.com/o1-labs/proof-systems?rev=c513810dddec410c4065df359a66b1adfdf1aa23#c513810dddec410c4065df359a66b1adfdf1aa23" dependencies = [ "ark-ff", "hex", @@ -10116,6 +10127,9 @@ dependencies = [ "mina-signer", "mina-tree", "num", + "num-bigint-generic", + "num-rational-generic", + "num-traits", "o1-utils", "poseidon", "rand", diff --git a/Cargo.toml b/Cargo.toml index 7a1ed095dc..a313915204 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,31 +48,36 @@ arithmetic_side_effects = "warn" indexing_slicing = "warn" [workspace.dependencies] -ledger = { path = "ledger", package = "mina-tree" } -mina-p2p-messages = { path = "mina-p2p-messages" } -poseidon = { path = "poseidon" } - # UNCOMMENTED_IN_CI mina-curves = { git = "https://github.com/openmina/proof-systems", rev = "d1912bca54d2609296b9af9d09ad1ef78702e203", features = [ "32x9" ] } -kimchi = { git = "https://github.com/openmina/proof-systems", rev = "d1912bca54d2609296b9af9d09ad1ef78702e203" } -mina-curves = { git = "https://github.com/openmina/proof-systems", rev = "d1912bca54d2609296b9af9d09ad1ef78702e203" } -mina-hasher = { git = "https://github.com/openmina/proof-systems", rev = "d1912bca54d2609296b9af9d09ad1ef78702e203" } -mina-poseidon = { git = "https://github.com/openmina/proof-systems", rev = "d1912bca54d2609296b9af9d09ad1ef78702e203" } -mina-signer = { git = "https://github.com/openmina/proof-systems", rev = "d1912bca54d2609296b9af9d09ad1ef78702e203" } -o1-utils = { git = "https://github.com/openmina/proof-systems", rev = "d1912bca54d2609296b9af9d09ad1ef78702e203" } -poly-commitment = { git = "https://github.com/openmina/proof-systems", rev = "d1912bca54d2609296b9af9d09ad1ef78702e203" } - -# kimchi.path = "../deps/proof-systems/kimchi" -# mina-curves.path = "../deps/proof-systems/curves" -# mina-hasher.path = "../deps/proof-systems/hasher" -# mina-poseidon.path = "../deps/proof-systems/poseidon" -# mina-signer.path = "../deps/proof-systems/signer" -# o1-utils.path = "../deps/proof-systems/utils" -# poly-commitment.path = "../deps/proof-systems/poly-commitment" +# UNCOMMENTED_IN_CI ark-ff = { git = "https://github.com/openmina/algebra", branch = "rebase-fix-openmina-webnode", features = ["parallel", "asm", "std", "32x9" ] } +ark-ec = { version = "0.5", features = ["std"] } +ark-ff = { version = "0.5", features = ["parallel", "asm", "std"] } +ark-poly = { version = "0.5" } +ark-serialize = { version = "0.5", features = ["std"] } +graphannis-malloc_size_of = { git = "https://github.com/openmina/graphannis-malloc_size_of.git", rev = "f7da9f6" } +graphannis-malloc_size_of_derive = { git = "https://github.com/openmina/graphannis-malloc_size_of_derive.git" } juniper = { version = "0.16" } +kimchi = { git = "https://github.com/o1-labs/proof-systems", rev = "c513810dddec410c4065df359a66b1adfdf1aa23" } +ledger = { path = "ledger", package = "mina-tree" } libp2p = { git = "https://github.com/openmina/rust-libp2p", rev = "5c44c7d9", default-features = false } linkme = "0.3.22" +mina-curves = { git = "https://github.com/o1-labs/proof-systems", rev = "c513810dddec410c4065df359a66b1adfdf1aa23" } +mina-hasher = { git = "https://github.com/o1-labs/proof-systems", rev = "c513810dddec410c4065df359a66b1adfdf1aa23" } mina-node-account = { path = "node/account" } +mina-p2p-messages = { path = "mina-p2p-messages" } +mina-poseidon = { git = "https://github.com/o1-labs/proof-systems", rev = "c513810dddec410c4065df359a66b1adfdf1aa23" } +mina-producer-dashboard = { path = "producer-dashboard" } +mina-signer = { git = "https://github.com/o1-labs/proof-systems", rev = "c513810dddec410c4065df359a66b1adfdf1aa23" } +num-bigint = { version = "0.4.6" } +num-bigint-generic = { path = "./vendor/num-bigint-generic" } +num-rational-generic = { path = "./vendor/num-rational-generic", features = [ + "num-bigint-generic", +] } +num-traits = "0.2" +o1-utils = { git = "https://github.com/o1-labs/proof-systems", rev = "c513810dddec410c4065df359a66b1adfdf1aa23" } +poly-commitment = { git = "https://github.com/o1-labs/proof-systems", rev = "c513810dddec410c4065df359a66b1adfdf1aa23" } +poseidon = { path = "poseidon" } redux = { git = "https://github.com/o1-labs/redux-rs.git", rev = "06c8366", features = [ "serde", ] } @@ -82,29 +87,6 @@ serde_with = { version = "3.7.0", features = ["hex"] } static_assertions = "1.1.0" vrf = { path = "vrf" } - -ark-ec = { git = "https://github.com/openmina/algebra", branch = "rebase-fix-openmina-webnode", features = [ - "std", -] } -ark-ff = { git = "https://github.com/openmina/algebra", branch = "rebase-fix-openmina-webnode", features = [ - "parallel", - "asm", - "std", -] } -ark-poly = { git = "https://github.com/openmina/algebra", branch = "rebase-fix-openmina-webnode" } -ark-serialize = { git = "https://github.com/openmina/algebra", branch = "rebase-fix-openmina-webnode", features = [ - "std", -] } - -num-bigint = { git = "https://github.com/openmina/num-bigint", branch = "rebase-onstack" } # branch: rebase-onstack - -# UNCOMMENTED_IN_CI ark-ff = { git = "https://github.com/openmina/algebra", branch = "rebase-fix-openmina-webnode", features = ["parallel", "asm", "std", "32x9" ] } - -graphannis-malloc_size_of = { git = "https://github.com/openmina/graphannis-malloc_size_of.git", rev = "f7da9f6" } -graphannis-malloc_size_of_derive = { git = "https://github.com/openmina/graphannis-malloc_size_of_derive.git" } - -mina-producer-dashboard = { path = "producer-dashboard" } - [profile.fuzz] inherits = "release" opt-level = 3 @@ -116,15 +98,6 @@ panic = "abort" incremental = false codegen-units = 1 -[patch.crates-io] -ark-ff = { git = "https://github.com/openmina/algebra", branch = "rebase-fix-openmina-webnode" } -ark-ec = { git = "https://github.com/openmina/algebra", branch = "rebase-fix-openmina-webnode" } -ark-poly = { git = "https://github.com/openmina/algebra", branch = "rebase-fix-openmina-webnode" } -ark-serialize = { git = "https://github.com/openmina/algebra", branch = "rebase-fix-openmina-webnode" } - -num-bigint = { git = "https://github.com/openmina/num-bigint", branch = "rebase-onstack" } # branch: rebase-onstack -num-rational = { git = "https://github.com/openmina/num-rational", branch = "rebase-onstack" } # branch: rebase-onstack - [profile.test.package."*"] opt-level = 3 debug-assertions = true diff --git a/core/src/block/block_with_hash.rs b/core/src/block/block_with_hash.rs index 14108cc35a..68a7e130c6 100644 --- a/core/src/block/block_with_hash.rs +++ b/core/src/block/block_with_hash.rs @@ -1,5 +1,4 @@ -use ark_ff::fields::arithmetic::InvalidBigInt; -use mina_p2p_messages::v2; +use mina_p2p_messages::{bigint::InvalidBigInt, v2}; use redux::Timestamp; use serde::{Deserialize, Serialize}; diff --git a/core/src/block/genesis.rs b/core/src/block/genesis.rs index 0a3fdfc9ce..1d69c5b429 100644 --- a/core/src/block/genesis.rs +++ b/core/src/block/genesis.rs @@ -1,5 +1,7 @@ -use ark_ff::fields::arithmetic::InvalidBigInt; -use mina_p2p_messages::v2::{self, StateHash}; +use mina_p2p_messages::{ + bigint::InvalidBigInt, + v2::{self, StateHash}, +}; use crate::constants::{constraint_constants, slots_per_window}; diff --git a/ledger/src/account/account.rs b/ledger/src/account/account.rs index 786c384a04..e354c196ae 100644 --- a/ledger/src/account/account.rs +++ b/ledger/src/account/account.rs @@ -121,14 +121,12 @@ impl TokenSymbol { } pub fn to_field(&self) -> F { - use ark_ff::FromBytes; - let mut s = <[u8; 32]>::default(); self.to_bytes(&mut s); - let value = FromBytes::read(&s[..]).expect("Shoudn't fail"); - let bigint = BigInteger256::new(value); - F::from(bigint) // Never fail, `self` contain 6 bytes at most + // There is an assumption that a token symbol is on 6 bytes, therefore + // it will be smaller than the order + F::from_le_bytes_mod_order(&s) } } diff --git a/ledger/src/account/conv.rs b/ledger/src/account/conv.rs index 7a434d5e63..d9e82d851c 100644 --- a/ledger/src/account/conv.rs +++ b/ledger/src/account/conv.rs @@ -1,10 +1,10 @@ #![allow(clippy::type_complexity)] use ark_ec::short_weierstrass::Affine; -use ark_ff::{fields::arithmetic::InvalidBigInt, Field, PrimeField}; +use ark_ff::{Field, PrimeField}; use mina_curves::pasta::Fp; use mina_p2p_messages::{ - bigint::BigInt, + bigint::{BigInt, InvalidBigInt}, binprot, pseq::PaddedSeq, v2::{ diff --git a/ledger/src/proofs/accumulator_check.rs b/ledger/src/proofs/accumulator_check.rs index a3a1e3e3dc..b3171d2d92 100644 --- a/ledger/src/proofs/accumulator_check.rs +++ b/ledger/src/proofs/accumulator_check.rs @@ -1,6 +1,8 @@ -use ark_ff::fields::arithmetic::InvalidBigInt; use mina_curves::pasta::{Fp, Vesta}; -use mina_p2p_messages::{bigint::BigInt, v2::PicklesProofProofsVerified2ReprStableV2}; +use mina_p2p_messages::{ + bigint::{BigInt, InvalidBigInt}, + v2::PicklesProofProofsVerified2ReprStableV2, +}; use poly_commitment::{commitment::CommitmentCurve, ipa::SRS}; use super::{public_input::scalar_challenge::ScalarChallenge, urs_utils}; diff --git a/ledger/src/proofs/block.rs b/ledger/src/proofs/block.rs index a8d2e34078..adbfd0c4e1 100644 --- a/ledger/src/proofs/block.rs +++ b/ledger/src/proofs/block.rs @@ -1,11 +1,10 @@ use std::{rc::Rc, sync::Arc}; use anyhow::Context; -use ark_ff::fields::arithmetic::InvalidBigInt; use consensus::ConsensusState; use mina_core::constants::{constraint_constants, ForkConstants}; use mina_curves::pasta::{Fp, Fq}; -use mina_p2p_messages::v2; +use mina_p2p_messages::{bigint::InvalidBigInt, v2}; use poseidon::hash::{ params::{MINA_PROTO_STATE, MINA_PROTO_STATE_BODY}, Inputs, diff --git a/ledger/src/proofs/caching.rs b/ledger/src/proofs/caching.rs index c7a268f88e..1fec48a318 100644 --- a/ledger/src/proofs/caching.rs +++ b/ledger/src/proofs/caching.rs @@ -5,7 +5,6 @@ use std::{ }; use ark_ec::{short_weierstrass::Affine, AffineRepr, CurveConfig}; -use ark_ff::fields::arithmetic::InvalidBigInt; use ark_poly::{univariate::DensePolynomial, Radix2EvaluationDomain}; use kimchi::{ alphas::Alphas, @@ -21,7 +20,7 @@ use kimchi::{ verifier_index::LookupVerifierIndex, }; use mina_curves::pasta::Fq; -use mina_p2p_messages::bigint::BigInt; +use mina_p2p_messages::bigint::{BigInt, InvalidBigInt}; use once_cell::sync::OnceCell; use poly_commitment::{ commitment::CommitmentCurve, hash_map_cache::HashMapCache, ipa::SRS, PolyComm, diff --git a/ledger/src/proofs/conv.rs b/ledger/src/proofs/conv.rs index 5c6d5007de..ae70bd043e 100644 --- a/ledger/src/proofs/conv.rs +++ b/ledger/src/proofs/conv.rs @@ -1,6 +1,5 @@ -use ark_ff::fields::arithmetic::InvalidBigInt; use mina_curves::pasta::Fp; -use mina_p2p_messages::v2; +use mina_p2p_messages::{bigint::InvalidBigInt, v2}; use crate::scan_state::{ currency::{self, Length, Slot}, diff --git a/ledger/src/proofs/merge.rs b/ledger/src/proofs/merge.rs index d8cc41521b..de724caec1 100644 --- a/ledger/src/proofs/merge.rs +++ b/ledger/src/proofs/merge.rs @@ -6,9 +6,8 @@ use crate::proofs::{ util::sha256_sum, wrap::{wrap, WrapParams}, }; -use ark_ff::fields::arithmetic::InvalidBigInt; use mina_curves::pasta::{Fp, Fq}; -use mina_p2p_messages::v2; +use mina_p2p_messages::{bigint::InvalidBigInt, v2}; use crate::{ proofs::transaction::transaction_snark::assert_equal_local_state, diff --git a/ledger/src/proofs/public_input/scalars.rs b/ledger/src/proofs/public_input/scalars.rs index f310824b7e..9efd257b44 100644 --- a/ledger/src/proofs/public_input/scalars.rs +++ b/ledger/src/proofs/public_input/scalars.rs @@ -1,6 +1,7 @@ -use ark_ff::{BigInteger256, Field, FromBytes}; +use ark_ff::{BigInteger256, Field}; use kimchi::proof::ProofEvaluations; use mina_curves::pasta::{Fp, Fq}; +use o1_utils::field_helpers::FieldHelpers; use crate::proofs::field::FieldWitness; @@ -44,13 +45,7 @@ where s = &s[2..]; } - let mut bytes = <[u8; 32]>::default(); - hex::decode_to_slice(s, &mut bytes).unwrap(); - bytes.reverse(); - - let value = FromBytes::read(&bytes[..]).expect("Should not fail"); - let bigint = BigInteger256::new(value); - F::from(bigint) // Never fail, we hardcode them with string literals + F::from_hex(s).expect("Must not fail") } fn field(s: &str) -> F { diff --git a/ledger/src/proofs/step.rs b/ledger/src/proofs/step.rs index adcb459fc8..b72eb740e6 100644 --- a/ledger/src/proofs/step.rs +++ b/ledger/src/proofs/step.rs @@ -18,13 +18,13 @@ use crate::{ verifier::{get_srs, get_srs_mut}, }; use anyhow::Context; -use ark_ff::{fields::arithmetic::InvalidBigInt, BigInteger256, One, Zero}; +use ark_ff::{BigInteger256, One, Zero}; use ark_poly::{ univariate::DensePolynomial, DenseUVPolynomial, EvaluationDomain, Radix2EvaluationDomain, }; use kimchi::proof::{PointEvaluations, ProverCommitments, RecursionChallenge}; use mina_curves::pasta::{Fp, Fq, Pallas}; -use mina_p2p_messages::v2; +use mina_p2p_messages::{bigint::InvalidBigInt, v2}; use poly_commitment::{commitment::b_poly_coefficients, ipa::OpeningProof}; use crate::proofs::{ diff --git a/ledger/src/proofs/transaction.rs b/ledger/src/proofs/transaction.rs index b650ca1b3c..e68bcf8bdb 100644 --- a/ledger/src/proofs/transaction.rs +++ b/ledger/src/proofs/transaction.rs @@ -2,28 +2,32 @@ use std::{collections::HashMap, rc::Rc, str::FromStr, sync::Arc}; use anyhow::Context; use ark_ec::{short_weierstrass::Projective, AffineRepr, CurveGroup, PrimeGroup}; -use ark_ff::{fields::arithmetic::InvalidBigInt, AdditiveGroup, BigInteger256, Field, PrimeField}; +use ark_ff::{AdditiveGroup, BigInteger256, Field, PrimeField}; use kimchi::{ circuits::{gate::CircuitGate, wires::COLUMNS}, - groupmap::GroupMap, + groupmap::{BWParameters, GroupMap}, proof::RecursionChallenge, }; use mina_curves::pasta::{Fp, Fq}; -use mina_p2p_messages::v2::{ - self, ConsensusProofOfStakeDataEpochDataNextValueVersionedValueStableV1, - ConsensusProofOfStakeDataEpochDataStakingValueVersionedValueStableV1, CurrencyAmountStableV1, - MinaBaseEpochLedgerValueStableV1, MinaBaseFeeExcessStableV1, - MinaBaseProtocolConstantsCheckedValueStableV1, MinaNumbersGlobalSlotSinceGenesisMStableV1, - MinaNumbersGlobalSlotSinceHardForkMStableV1, - MinaStateBlockchainStateValueStableV2LedgerProofStatement, - MinaStateBlockchainStateValueStableV2LedgerProofStatementSource, - MinaStateBlockchainStateValueStableV2SignedAmount, - MinaTransactionLogicZkappCommandLogicLocalStateValueStableV1, SgnStableV1, SignedAmount, - TokenFeeExcess, UnsignedExtendedUInt32StableV1, - UnsignedExtendedUInt64Int64ForVersionTagsStableV1, +use mina_p2p_messages::{ + bigint::InvalidBigInt, + v2::{ + self, ConsensusProofOfStakeDataEpochDataNextValueVersionedValueStableV1, + ConsensusProofOfStakeDataEpochDataStakingValueVersionedValueStableV1, + CurrencyAmountStableV1, MinaBaseEpochLedgerValueStableV1, MinaBaseFeeExcessStableV1, + MinaBaseProtocolConstantsCheckedValueStableV1, MinaNumbersGlobalSlotSinceGenesisMStableV1, + MinaNumbersGlobalSlotSinceHardForkMStableV1, + MinaStateBlockchainStateValueStableV2LedgerProofStatement, + MinaStateBlockchainStateValueStableV2LedgerProofStatementSource, + MinaStateBlockchainStateValueStableV2SignedAmount, + MinaTransactionLogicZkappCommandLogicLocalStateValueStableV1, SgnStableV1, SignedAmount, + TokenFeeExcess, UnsignedExtendedUInt32StableV1, + UnsignedExtendedUInt64Int64ForVersionTagsStableV1, + }, }; use mina_poseidon::constants::PlonkSpongeConstantsKimchi; use mina_signer::{CompressedPubKey, PubKey}; +use poly_commitment::commitment::CommitmentCurve; use crate::{ decompress_pk, gen_keypair, @@ -3996,8 +4000,7 @@ pub(super) fn create_proof( let mut rng = get_rng(); let now = redux::Instant::now(); - let group_map = - kimchi::groupmap::GroupMap::<::Scalar>::setup(); + let group_map = ::Map::setup(); let proof = kimchi::proof::ProverProof::create_recursive::, _>( &group_map, computed_witness, @@ -4011,7 +4014,23 @@ pub(super) fn create_proof( let prev_challenges_hash = debug::hash_prev_challenge::(&prev_challenges); let witness_primary_hash = debug::hash_slice(&w.primary); let witness_aux_hash = debug::hash_slice(w.aux()); - let group_map_hash = debug::hash_slice(&group_map.composition()); + let group_map_hash = { + // Recreating the same value to access the field. + // We should find a way to bypass the type-checker to reuse + // the value group_map defined above. + // As it is only in the case of errors, the additional cost of + // creating a new value can be ignored. + let group_map_for_debug = + BWParameters::<<::Scalar as FieldWitness>::Parameters>::setup(); + let d = vec![ + group_map_for_debug.u, + group_map_for_debug.fu, + group_map_for_debug.sqrt_neg_three_u_squared_minus_u_over_2, + group_map_for_debug.sqrt_neg_three_u_squared, + group_map_for_debug.inv_three_u_squared, + ]; + debug::hash_slice(&d) + }; dbg!( &prev_challenges_hash, diff --git a/ledger/src/proofs/unfinalized.rs b/ledger/src/proofs/unfinalized.rs index 9334bc7aff..b504d3cd43 100644 --- a/ledger/src/proofs/unfinalized.rs +++ b/ledger/src/proofs/unfinalized.rs @@ -1,7 +1,6 @@ -use ark_ff::fields::arithmetic::InvalidBigInt; use kimchi::proof::{PointEvaluations, ProofEvaluations}; use mina_curves::pasta::{Fp, Fq}; -use mina_p2p_messages::v2; +use mina_p2p_messages::{bigint::InvalidBigInt, v2}; use crate::proofs::{ field::FieldWitness, public_input::plonk_checks::derive_plonk, step::FeatureFlags, diff --git a/ledger/src/proofs/util.rs b/ledger/src/proofs/util.rs index 060fe4fa24..ee114f2301 100644 --- a/ledger/src/proofs/util.rs +++ b/ledger/src/proofs/util.rs @@ -1,9 +1,10 @@ use std::fmt::Debug; -use ark_ff::{fields::arithmetic::InvalidBigInt, BigInteger256, Field}; +use ark_ff::{BigInteger256, Field}; use kimchi::proof::{PointEvaluations, ProofEvaluations}; use mina_p2p_messages::{ - bigint::BigInt, pseq::PaddedSeq, + bigint::{BigInt, InvalidBigInt}, + pseq::PaddedSeq, v2::PicklesReducedMessagesForNextProofOverSameFieldWrapChallengesVectorStableV2A, }; diff --git a/ledger/src/proofs/verification.rs b/ledger/src/proofs/verification.rs index 277cf0f8cf..351c3ac340 100644 --- a/ledger/src/proofs/verification.rs +++ b/ledger/src/proofs/verification.rs @@ -1,9 +1,9 @@ use std::rc::Rc; -use ark_ff::fields::arithmetic::InvalidBigInt; use ark_poly::{EvaluationDomain, Radix2EvaluationDomain}; use ark_serialize::Write; use itertools::Itertools; +use mina_p2p_messages::bigint::InvalidBigInt; use poly_commitment::ipa::SRS; use crate::{ diff --git a/ledger/src/proofs/wrap.rs b/ledger/src/proofs/wrap.rs index 553f25c430..9bf2eb0b13 100644 --- a/ledger/src/proofs/wrap.rs +++ b/ledger/src/proofs/wrap.rs @@ -1,6 +1,6 @@ use std::{borrow::Cow, ops::Neg, rc::Rc}; -use ark_ff::{fields::arithmetic::InvalidBigInt, BigInteger256, One, Zero}; +use ark_ff::{BigInteger256, One, Zero}; use ark_poly::{univariate::DensePolynomial, DenseUVPolynomial, EvaluationDomain}; use kimchi::{ circuits::{expr::RowOffset, scalars::RandomOracles, wires::COLUMNS}, @@ -8,9 +8,12 @@ use kimchi::{ proof::{PointEvaluations, ProofEvaluations, RecursionChallenge}, }; use mina_curves::pasta::{Fp, Fq, Pallas, Vesta}; -use mina_p2p_messages::v2::{ - CompositionTypesBranchDataDomainLog2StableV1, CompositionTypesBranchDataStableV1, - PicklesBaseProofsVerifiedStableV1, +use mina_p2p_messages::{ + bigint::InvalidBigInt, + v2::{ + CompositionTypesBranchDataDomainLog2StableV1, CompositionTypesBranchDataStableV1, + PicklesBaseProofsVerifiedStableV1, + }, }; use mina_poseidon::{sponge::ScalarChallenge, FqSponge}; use poly_commitment::{commitment::b_poly_coefficients, ipa::OpeningProof, PolyComm, SRS}; diff --git a/ledger/src/proofs/zkapp.rs b/ledger/src/proofs/zkapp.rs index cd46d48847..55c49daca8 100644 --- a/ledger/src/proofs/zkapp.rs +++ b/ledger/src/proofs/zkapp.rs @@ -1,9 +1,9 @@ use std::{cell::RefCell, rc::Rc}; -use ark_ff::{fields::arithmetic::InvalidBigInt, BigInteger256, Zero}; +use ark_ff::{BigInteger256, Zero}; use kimchi::proof::PointEvaluations; use mina_curves::pasta::{Fp, Fq}; -use mina_p2p_messages::v2; +use mina_p2p_messages::{bigint::InvalidBigInt, v2}; use poly_commitment::ipa::OpeningProof; use poseidon::hash::{ hash_with_kimchi, diff --git a/ledger/src/scan_state/conv.rs b/ledger/src/scan_state/conv.rs index a91c2ee778..0dc3724ea6 100644 --- a/ledger/src/scan_state/conv.rs +++ b/ledger/src/scan_state/conv.rs @@ -2,9 +2,9 @@ use std::sync::Arc; -use ark_ff::fields::arithmetic::InvalidBigInt; use mina_curves::pasta::Fp; use mina_p2p_messages::{ + bigint::InvalidBigInt, binprot, list::List, pseq::PaddedSeq, diff --git a/ledger/src/scan_state/pending_coinbase.rs b/ledger/src/scan_state/pending_coinbase.rs index 1dd49d242c..0f883a9cf3 100644 --- a/ledger/src/scan_state/pending_coinbase.rs +++ b/ledger/src/scan_state/pending_coinbase.rs @@ -20,9 +20,10 @@ /// Stack operations are done for transaction snarks and tree operations are done for the blockchain snark*) use std::{collections::HashMap, fmt::Write, marker::PhantomData}; -use ark_ff::{fields::arithmetic::InvalidBigInt, Zero}; +use ark_ff::Zero; use mina_core::constants::constraint_constants; use mina_curves::pasta::Fp; +use mina_p2p_messages::bigint::InvalidBigInt; use mina_signer::CompressedPubKey; use poseidon::hash::{ hash_noinputs, hash_with_kimchi, diff --git a/ledger/src/scan_state/scan_state.rs b/ledger/src/scan_state/scan_state.rs index 8e275bf624..e429d3cb8e 100644 --- a/ledger/src/scan_state/scan_state.rs +++ b/ledger/src/scan_state/scan_state.rs @@ -531,7 +531,7 @@ pub mod transaction_snark { } pub mod work { - use ark_ff::fields::arithmetic::InvalidBigInt; + use mina_p2p_messages::bigint::InvalidBigInt; use super::*; diff --git a/ledger/src/scan_state/transaction_logic.rs b/ledger/src/scan_state/transaction_logic.rs index 63ddc4d2d1..434f4c6a4e 100644 --- a/ledger/src/scan_state/transaction_logic.rs +++ b/ledger/src/scan_state/transaction_logic.rs @@ -3,12 +3,13 @@ use std::{ fmt::Display, }; -use ark_ff::{fields::arithmetic::InvalidBigInt, Zero}; +use ark_ff::Zero; use itertools::{FoldWhile, Itertools}; use mina_core::constants::ConstraintConstants; use mina_hasher::{Fp, Hashable, ROInput}; use mina_macros::SerdeYojsonEnum; use mina_p2p_messages::{ + bigint::InvalidBigInt, binprot, v2::{MinaBaseUserCommandStableV2, MinaTransactionTransactionStableV2}, }; diff --git a/ledger/src/sparse_ledger/sparse_ledger.rs b/ledger/src/sparse_ledger/sparse_ledger.rs index e4f49991f0..994e3b0f5b 100644 --- a/ledger/src/sparse_ledger/sparse_ledger.rs +++ b/ledger/src/sparse_ledger/sparse_ledger.rs @@ -3,9 +3,10 @@ use std::{ sync::{Arc, Mutex}, }; -use ark_ff::{fields::arithmetic::InvalidBigInt, Zero}; +use ark_ff::Zero; use mina_core::constants::constraint_constants; use mina_curves::pasta::Fp; +use mina_p2p_messages::bigint::InvalidBigInt; use crate::{ scan_state::{ diff --git a/ledger/src/staged_ledger/hash.rs b/ledger/src/staged_ledger/hash.rs index 238110d37b..424d176220 100644 --- a/ledger/src/staged_ledger/hash.rs +++ b/ledger/src/staged_ledger/hash.rs @@ -1,4 +1,4 @@ -use ark_ff::{PrimeField, ToBytes}; +use ark_ff::PrimeField; use mina_curves::pasta::Fp; use poseidon::hash::Inputs; use sha2::{Digest, Sha256}; @@ -159,10 +159,11 @@ impl NonStark { let mut ledger_hash_bytes: [u8; 32] = <[u8; 32]>::default(); let ledger_hash = ledger_hash.into_bigint(); - ledger_hash - .0 - .write(ledger_hash_bytes.as_mut_slice()) - .unwrap(); + // Convert [u64; 4] to bytes in little-endian + for (i, &word) in ledger_hash.0.iter().enumerate() { + let bytes = word.to_le_bytes(); + ledger_hash_bytes[i * 8..(i + 1) * 8].copy_from_slice(&bytes); + } ledger_hash_bytes.reverse(); sha.update(ledger_hash_bytes.as_slice()); diff --git a/ledger/src/staged_ledger/staged_ledger.rs b/ledger/src/staged_ledger/staged_ledger.rs index bc58d248b4..cc0e9465b6 100644 --- a/ledger/src/staged_ledger/staged_ledger.rs +++ b/ledger/src/staged_ledger/staged_ledger.rs @@ -2387,7 +2387,7 @@ mod tests_ocaml { let mut signer = mina_signer::create_legacy(mina_signer::NetworkId::TESTNET); - signer.sign(sender_pk, &payload_to_sign) + signer.sign(sender_pk, &payload_to_sign, false) } }; @@ -5585,7 +5585,7 @@ mod tests_ocaml { let payload_to_sign = TransactionUnionPayload::of_user_command_payload(&payload); let mut signer = mina_signer::create_legacy(mina_signer::NetworkId::TESTNET); - let signature = signer.sign(kp, &payload_to_sign); + let signature = signer.sign(kp, &payload_to_sign, false); let signed_command = SignedCommand { payload, @@ -5681,7 +5681,7 @@ mod tests_ocaml { let payload_to_sign = TransactionUnionPayload::of_user_command_payload(&payload); let mut signer = mina_signer::create_legacy(mina_signer::NetworkId::TESTNET); - let signature = signer.sign(&kp, &payload_to_sign); + let signature = signer.sign(&kp, &payload_to_sign, false); let signed_command = SignedCommand { payload, diff --git a/mina-p2p-messages/Cargo.toml b/mina-p2p-messages/Cargo.toml index 62bafbf939..5ba35be098 100644 --- a/mina-p2p-messages/Cargo.toml +++ b/mina-p2p-messages/Cargo.toml @@ -15,7 +15,7 @@ bs58 = { version = "0.4", features = ["check"] } derive_more = "0.99.17" hex = "0.4.3" lazy_static = "1.4.0" -num-bigint = "0.4.6" +num-bigint-generic = { workspace = true } serde = { workspace = true } serde_bytes = "0.11" serde_json = { version = "1.0.83" } @@ -34,6 +34,7 @@ o1-utils = { workspace = true } poseidon = { workspace = true } ark-ff = { workspace = true } +ark-serialize = { workspace = true } rsexp = "0.2.3" rsexp-derive = "0.2.3" diff --git a/mina-p2p-messages/src/bigint.rs b/mina-p2p-messages/src/bigint.rs index 0d26766eff..fbb441b223 100644 --- a/mina-p2p-messages/src/bigint.rs +++ b/mina-p2p-messages/src/bigint.rs @@ -1,8 +1,30 @@ -use ark_ff::{fields::arithmetic::InvalidBigInt, BigInteger256}; +use ark_ff::BigInteger256; +use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; use malloc_size_of::MallocSizeOf; use rsexp::{OfSexp, SexpOf}; use serde::{Deserialize, Serialize}; +// --- +// This has been imported from a fork of arkworks/ff +// We should probably revisit this structure in the future +#[derive(Clone, Debug)] +pub struct InvalidBigInt; + +impl core::fmt::Display for InvalidBigInt { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + write!(f, "InvalidBigInt") + } +} + +impl From for String { + fn from(_: InvalidBigInt) -> Self { + "InvalidBigInt".to_string() + } +} + +impl std::error::Error for InvalidBigInt {} +// --- + #[derive(Clone, Default, PartialEq, Eq, PartialOrd, Ord, derive_more::From, derive_more::Into)] pub struct BigInt(BigInteger256); @@ -42,20 +64,18 @@ impl BigInt { } pub fn to_bytes(&self) -> [u8; 32] { - use ark_ff::ToBytes; - let mut bytes = std::io::Cursor::new([0u8; 32]); - self.0 .0.write(&mut bytes).unwrap(); // Never fail, there is 32 bytes - bytes.into_inner() + let mut bytes = Vec::with_capacity(32); + self.0.serialize_uncompressed(&mut bytes).unwrap(); // Never fail, there is 32 bytes + bytes.try_into().unwrap() } pub fn from_bytes(bytes: [u8; 32]) -> Self { - use ark_ff::FromBytes; - let value = FromBytes::read(&bytes[..]).expect("Don't fail"); - Self(BigInteger256::new(value)) // Never fail, we read from 32 bytes + let value = BigInteger256::deserialize_uncompressed(&bytes[..]).expect("Don't fail"); + Self(value) // Never fail, we read from 32 bytes } pub fn from_decimal(s: &str) -> Result { - num_bigint::BigInt::<4>::parse_bytes(s.as_bytes(), 10) + num_bigint_generic::BigInt::<4>::parse_bytes(s.as_bytes(), 10) .map(|num| { let mut bytes = num.to_bytes_be().1; bytes.reverse(); @@ -66,8 +86,7 @@ impl BigInt { } pub fn to_decimal(&self) -> String { - let bigint: num_bigint::BigUint = self.0.into(); - bigint.to_string() + self.0.to_string() } } @@ -190,17 +209,15 @@ impl binprot::BinProtRead for BigInt { where Self: Sized, { - use ark_ff::FromBytes; - let value = FromBytes::read(r)?; - Ok(Self(BigInteger256::new(value))) + let mut bytes = [0u8; 32]; + r.read_exact(&mut bytes)?; + Ok(Self::from_bytes(bytes)) } } impl binprot::BinProtWrite for BigInt { fn binprot_write(&self, w: &mut W) -> std::io::Result<()> { - use ark_ff::ToBytes; - let Self(biginteger) = self; - biginteger.0.write(w) + w.write_all(&self.to_bytes()) } } @@ -247,7 +264,7 @@ impl<'de> Deserialize<'de> for BigInt { }), None => { // Try to parse as a decimal number - num_bigint::BigInt::<4>::parse_bytes(v.as_bytes(), 10) + num_bigint_generic::BigInt::<4>::parse_bytes(v.as_bytes(), 10) .map(|num| { let mut bytes = num.to_bytes_be().1; bytes.reverse(); diff --git a/mina-p2p-messages/src/hash.rs b/mina-p2p-messages/src/hash.rs index 4c2cad0ff3..d9dd16a0df 100644 --- a/mina-p2p-messages/src/hash.rs +++ b/mina-p2p-messages/src/hash.rs @@ -1,6 +1,7 @@ -use ark_ff::fields::arithmetic::InvalidBigInt; use mina_curves::pasta::Fp; +use crate::bigint::InvalidBigInt; + pub trait MinaHash { fn try_hash(&self) -> Result; } diff --git a/mina-p2p-messages/src/hash_input.rs b/mina-p2p-messages/src/hash_input.rs index b11e58bf37..0fd27c8591 100644 --- a/mina-p2p-messages/src/hash_input.rs +++ b/mina-p2p-messages/src/hash_input.rs @@ -1,10 +1,9 @@ use std::ops::Deref; -use ark_ff::fields::arithmetic::InvalidBigInt; use poseidon::hash::Inputs; use crate::{ - bigint::BigInt, + bigint::{BigInt, InvalidBigInt}, list::List, number::{Int32, Int64, UInt32, UInt64}, string::{ByteString, ZkAppUri}, diff --git a/mina-p2p-messages/src/keys.rs b/mina-p2p-messages/src/keys.rs index 365dd4d877..2dbbc37e05 100644 --- a/mina-p2p-messages/src/keys.rs +++ b/mina-p2p-messages/src/keys.rs @@ -1,4 +1,4 @@ -use ark_ff::fields::arithmetic::InvalidBigInt; +use crate::bigint::InvalidBigInt; impl TryFrom for mina_signer::CompressedPubKey { type Error = InvalidBigInt; diff --git a/mina-p2p-messages/src/v2/hashing.rs b/mina-p2p-messages/src/v2/hashing.rs index 0c16e73267..7d66398691 100644 --- a/mina-p2p-messages/src/v2/hashing.rs +++ b/mina-p2p-messages/src/v2/hashing.rs @@ -1,6 +1,5 @@ use std::{fmt, io, sync::Arc}; -use ark_ff::fields::arithmetic::InvalidBigInt; use binprot::{BinProtRead, BinProtWrite}; use generated::MinaStateBlockchainStateValueStableV2; use mina_curves::pasta::Fp; @@ -15,7 +14,11 @@ use sha2::{ Digest, Sha256, }; -use crate::{bigint::BigInt, hash::MinaHash, hash_input::FailableToInputs}; +use crate::{ + bigint::{BigInt, InvalidBigInt}, + hash::MinaHash, + hash_input::FailableToInputs, +}; use super::{ generated, ConsensusBodyReferenceStableV1, ConsensusGlobalSlotStableV1, diff --git a/poseidon/Cargo.toml b/poseidon/Cargo.toml index 98647c56f2..c3fde88e03 100644 --- a/poseidon/Cargo.toml +++ b/poseidon/Cargo.toml @@ -10,5 +10,6 @@ workspace = true ark-ff = { workspace = true } ark-serialize.workspace = true mina-curves = { workspace = true } +o1-utils.workspace = true once_cell = "1" serde.workspace = true diff --git a/poseidon/src/hash.rs b/poseidon/src/hash.rs index 8acb39a02a..da1ebd685f 100644 --- a/poseidon/src/hash.rs +++ b/poseidon/src/hash.rs @@ -1,4 +1,4 @@ -use ark_ff::{BigInt, BigInteger256, Field, FromBytes}; +use ark_ff::{BigInteger256, Field}; use mina_curves::pasta::Fp; use crate::{PlonkSpongeConstantsKimchi, Sponge, SpongeParamsForField}; @@ -44,10 +44,9 @@ impl Item { Item::U8(v) => *v as u64, Item::U32(v) => *v as u64, Item::U48(v) => { - let mut bytes = <[u8; 32]>::default(); + let mut bytes = [0u8; 8]; bytes[..6].copy_from_slice(&v[..]); - let value = FromBytes::read(&bytes[..]).expect("Must not go wrong"); - BigInteger256::new(value).0[0] // Never fail with only 6 bytes + u64::from_le_bytes(bytes[..8].try_into().unwrap()) } Item::U64(v) => *v, } @@ -183,9 +182,7 @@ fn param_to_field_impl(param: &str, default: &[u8; 32]) -> Fp { let mut fp = *default; fp[..len].copy_from_slice(param_bytes); - let value = FromBytes::read(&fp[..]).expect("Error reading"); - let element = BigInt::new(value); - Fp::new(element) + Fp::from_random_bytes(&fp).expect("Must be a valid field element") } pub fn param_to_field(param: &str) -> Fp { diff --git a/producer-dashboard/Cargo.toml b/producer-dashboard/Cargo.toml index a4f40916b5..d9f89c70a1 100644 --- a/producer-dashboard/Cargo.toml +++ b/producer-dashboard/Cargo.toml @@ -15,8 +15,8 @@ dotenvy = "0.15" graphql_client = { version = "0.14", features = ["reqwest"] } mina-node-account = { workspace = true } mina-p2p-messages = { workspace = true } -num-bigint = "0.4" -num-traits = "0.2" +num-bigint = { workspace = true } +num-traits = { workspace = true } reqwest = { version = "0.11", features = ["json"] } serde = { version = "1.0", features = ["derive"] } serde_json = { version = "1.0.83" } diff --git a/snark/Cargo.toml b/snark/Cargo.toml index 0e4dd721f6..8d46e9a99d 100644 --- a/snark/Cargo.toml +++ b/snark/Cargo.toml @@ -20,7 +20,7 @@ derive_more = "0.99.17" hex = "0.4" ledger = { workspace = true } mina-p2p-messages = { workspace = true } -num-bigint = "0.4" +num-bigint = { workspace = true } once_cell = "1" poseidon = { workspace = true } rand = "0.8" diff --git a/snark/src/merkle_path/mod.rs b/snark/src/merkle_path/mod.rs index 8cef150771..f30ffd200d 100644 --- a/snark/src/merkle_path/mod.rs +++ b/snark/src/merkle_path/mod.rs @@ -9,8 +9,10 @@ //! This is commonly used in transaction verification (ensuring account exists). //! It uses the Poseidon hash function, as specified in the Mina protocol. -use ark_ff::fields::arithmetic::InvalidBigInt; -use mina_p2p_messages::{bigint::BigInt, v2::MerkleTreeNode}; +use mina_p2p_messages::{ + bigint::{BigInt, InvalidBigInt}, + v2::MerkleTreeNode, +}; use poseidon::hash::params::get_merkle_param_for_height; /// Computes the root hash of the merkle tree with an account and its merkle path diff --git a/tools/fuzzing/Cargo.toml b/tools/fuzzing/Cargo.toml index 79624f5246..2c299e6d8e 100644 --- a/tools/fuzzing/Cargo.toml +++ b/tools/fuzzing/Cargo.toml @@ -31,7 +31,7 @@ serde_json = "1.0" #ark-ff = { git = "https://github.com/openmina/algebra", branch = "openmina", features = [ "parallel", "asm", "std" ] } #ark-ec = { git = "https://github.com/openmina/algebra", branch = "openmina", features = [ "std" ] } itertools = "0.12.0" -num-bigint = "0.4.0" +num-bigint = { workspace = true } once_cell = "1.18.0" text-diff = "0.4.0" tuple-map = "0.4.0" diff --git a/vendor/num-bigint-generic/Cargo.toml b/vendor/num-bigint-generic/Cargo.toml index e6d670f629..f5b48def72 100644 --- a/vendor/num-bigint-generic/Cargo.toml +++ b/vendor/num-bigint-generic/Cargo.toml @@ -8,7 +8,7 @@ categories = ["algorithms", "data-structures", "science"] license = "MIT OR Apache-2.0" name = "num-bigint-generic" repository = "https://github.com/rust-num/num-bigint" -version = "0.4.6" +version = "0.4.4" readme = "README.md" exclude = ["/ci/*", "/.github/*"] edition = "2021" diff --git a/vendor/num-bigint-generic/src/bigint.rs b/vendor/num-bigint-generic/src/bigint.rs index ac1c8d918f..b84848b323 100644 --- a/vendor/num-bigint-generic/src/bigint.rs +++ b/vendor/num-bigint-generic/src/bigint.rs @@ -56,10 +56,10 @@ impl Neg for Sign { } impl BigInt { - pub fn to_digits(&self) -> BigInt { + pub fn to_nlimbs(&self) -> BigInt { BigInt { sign: self.sign, - data: self.data.to_digits(), + data: self.data.to_nlimbs(), } } } diff --git a/vendor/num-bigint-generic/src/biguint.rs b/vendor/num-bigint-generic/src/biguint.rs index e450dedbcc..e511adeada 100644 --- a/vendor/num-bigint-generic/src/biguint.rs +++ b/vendor/num-bigint-generic/src/biguint.rs @@ -32,7 +32,7 @@ pub struct BigUint { } impl BigUint { - pub fn to_digits(&self) -> BigUint { + pub fn to_nlimbs(&self) -> BigUint { BigUint { data: self.data.iter().copied().collect(), } diff --git a/vendor/num-rational-generic/Cargo.toml b/vendor/num-rational-generic/Cargo.toml index 0d6492668e..0c65b9ef9e 100644 --- a/vendor/num-rational-generic/Cargo.toml +++ b/vendor/num-rational-generic/Cargo.toml @@ -15,7 +15,7 @@ edition = "2021" rust-version = "1.60" [package.metadata.docs.rs] -features = ["std", "num-bigint-std", "serde"] +features = ["std", "num-bigint-generic-std", "serde"] [dependencies] diff --git a/vendor/num-rational-generic/README.md b/vendor/num-rational-generic/README.md index c1fbc6f3af..3ffcef0bc3 100644 --- a/vendor/num-rational-generic/README.md +++ b/vendor/num-rational-generic/README.md @@ -1,4 +1,4 @@ -# num-rational +# num-rational-generic [![crate](https://img.shields.io/crates/v/num-rational.svg)](https://crates.io/crates/num-rational) [![documentation](https://docs.rs/num-rational/badge.svg)](https://docs.rs/num-rational) @@ -13,7 +13,7 @@ Add this to your `Cargo.toml`: ```toml [dependencies] -num-rational = "0.4" +num-rational-generic = "0.4" ``` ## Features @@ -22,7 +22,7 @@ This crate can be used without the standard library (`#![no_std]`) by disabling the default `std` feature. Use this in `Cargo.toml`: ```toml -[dependencies.num-rational] +[dependencies.num-rational-gneric] version = "0.4" default-features = false ``` @@ -33,7 +33,7 @@ Release notes are available in [RELEASES.md](RELEASES.md). ## Compatibility -The `num-rational` crate is tested for rustc 1.60 and greater. +The `num-rational-generic` crate is tested for rustc 1.60 and greater. ## License diff --git a/vendor/num-rational-generic/benchmarks/Cargo.toml b/vendor/num-rational-generic/benchmarks/Cargo.toml index e890e3095b..1670fc3753 100644 --- a/vendor/num-rational-generic/benchmarks/Cargo.toml +++ b/vendor/num-rational-generic/benchmarks/Cargo.toml @@ -7,12 +7,12 @@ edition = "2021" [dependencies] -[dependencies.num-rational] +[dependencies.num-rational-generic] default-features = false -features = ["num-bigint"] +features = ["num-bigint-generic"] path = "../.." -[dependencies.num-bigint] +[dependencies.num-bigint-generic] default-features = false version = "0.4.0" diff --git a/vendor/num-rational-generic/ci/benchmarks/Cargo.toml b/vendor/num-rational-generic/ci/benchmarks/Cargo.toml index e890e3095b..1670fc3753 100644 --- a/vendor/num-rational-generic/ci/benchmarks/Cargo.toml +++ b/vendor/num-rational-generic/ci/benchmarks/Cargo.toml @@ -7,12 +7,12 @@ edition = "2021" [dependencies] -[dependencies.num-rational] +[dependencies.num-rational-generic] default-features = false -features = ["num-bigint"] +features = ["num-bigint-generic"] path = "../.." -[dependencies.num-bigint] +[dependencies.num-bigint-generic] default-features = false version = "0.4.0" diff --git a/vendor/num-rational-generic/lib.rs b/vendor/num-rational-generic/lib.rs index f838f7f6e7..33ad3d9b24 100644 --- a/vendor/num-rational-generic/lib.rs +++ b/vendor/num-rational-generic/lib.rs @@ -33,7 +33,7 @@ use core::str::FromStr; #[cfg(feature = "std")] use std::error::Error; -#[cfg(feature = "num-bigint")] +#[cfg(feature = "num-bigint-generic")] use num_bigint::{BigInt, BigUint, Sign, ToBigInt}; use num_integer::Integer; @@ -55,7 +55,7 @@ pub struct Ratio { denom: T, } -#[cfg(feature = "num-bigint")] +#[cfg(feature = "num-bigint-generic")] impl Ratio> { pub fn to_nlimbs(&self) -> Ratio> { let Self { numer, denom } = self; @@ -74,7 +74,7 @@ pub type Rational32 = Ratio; /// Alias for a `Ratio` of 64-bit-sized integers. pub type Rational64 = Ratio; -#[cfg(feature = "num-bigint")] +#[cfg(feature = "num-bigint-generic")] /// Alias for arbitrary precision rationals. pub type BigRational = Ratio>; @@ -289,7 +289,7 @@ impl Ratio { } } -#[cfg(feature = "num-bigint")] +#[cfg(feature = "num-bigint-generic")] impl Ratio { /// Converts a float into a rational number. pub fn from_float(f: T) -> Option { @@ -1226,7 +1226,7 @@ impl RatioErrorKind { } } -#[cfg(feature = "num-bigint")] +#[cfg(feature = "num-bigint-generic")] impl FromPrimitive for Ratio { fn from_i64(n: i64) -> Option { Some(Ratio::from_integer(n.into())) @@ -1424,7 +1424,7 @@ where Some(Ratio::new(n1, d1)) } -#[cfg(not(feature = "num-bigint"))] +#[cfg(not(feature = "num-bigint-generic"))] macro_rules! to_primitive_small { ($($type_name:ty)*) => ($( impl ToPrimitive for Ratio<$type_name> { @@ -1456,13 +1456,13 @@ macro_rules! to_primitive_small { )*) } -#[cfg(not(feature = "num-bigint"))] +#[cfg(not(feature = "num-bigint-generic"))] to_primitive_small!(u8 i8 u16 i16 u32 i32); -#[cfg(all(target_pointer_width = "32", not(feature = "num-bigint")))] +#[cfg(all(target_pointer_width = "32", not(feature = "num-bigint-generic")))] to_primitive_small!(usize isize); -#[cfg(not(feature = "num-bigint"))] +#[cfg(not(feature = "num-bigint-generic"))] macro_rules! to_primitive_64 { ($($type_name:ty)*) => ($( impl ToPrimitive for Ratio<$type_name> { @@ -1497,13 +1497,13 @@ macro_rules! to_primitive_64 { )*) } -#[cfg(not(feature = "num-bigint"))] +#[cfg(not(feature = "num-bigint-generic"))] to_primitive_64!(u64 i64); -#[cfg(all(target_pointer_width = "64", not(feature = "num-bigint")))] +#[cfg(all(target_pointer_width = "64", not(feature = "num-bigint-generic")))] to_primitive_64!(usize isize); -#[cfg(feature = "num-bigint")] +#[cfg(feature = "num-bigint-generic")] impl ToPrimitive for Ratio { fn to_i64(&self) -> Option { self.to_integer().to_i64() @@ -1545,14 +1545,14 @@ trait Bits { fn bits(&self) -> u64; } -#[cfg(feature = "num-bigint")] +#[cfg(feature = "num-bigint-generic")] impl Bits for BigInt { fn bits(&self) -> u64 { self.bits() } } -#[cfg(feature = "num-bigint")] +#[cfg(feature = "num-bigint-generic")] impl Bits for BigInt<32> { fn bits(&self) -> u64 { self.bits() @@ -1742,7 +1742,7 @@ fn hash(x: &T) -> u64 { #[cfg(test)] mod test { use super::ldexp; - #[cfg(feature = "num-bigint")] + #[cfg(feature = "num-bigint-generic")] use super::{BigInt, BigRational}; use super::{Ratio, Rational64}; @@ -1826,14 +1826,14 @@ mod test { denom: 1, }; - #[cfg(feature = "num-bigint")] + #[cfg(feature = "num-bigint-generic")] pub fn to_big(n: Rational64) -> BigRational { Ratio::new( FromPrimitive::from_i64(n.numer).unwrap(), FromPrimitive::from_i64(n.denom).unwrap(), ) } - #[cfg(not(feature = "num-bigint"))] + #[cfg(not(feature = "num-bigint-generic"))] pub fn to_big(n: Rational64) -> Rational64 { Ratio::new( FromPrimitive::from_i64(n.numer).unwrap(), @@ -2754,11 +2754,11 @@ mod test { assert_eq!(Pow::pow(r, &e), expected); assert_eq!(Pow::pow(&r, e), expected); assert_eq!(Pow::pow(&r, &e), expected); - #[cfg(feature = "num-bigint")] + #[cfg(feature = "num-bigint-generic")] test_big(r, e, expected); } - #[cfg(feature = "num-bigint")] + #[cfg(feature = "num-bigint-generic")] fn test_big(r: Rational64, e: i32, expected: Rational64) { let r = BigRational::<4>::new_raw(r.numer.into(), r.denom.into()); let expected = BigRational::new_raw(expected.numer.into(), expected.denom.into()); @@ -2809,7 +2809,7 @@ mod test { } } - #[cfg(feature = "num-bigint")] + #[cfg(feature = "num-bigint-generic")] #[test] fn test_from_float() { use num_traits::float::FloatCore; @@ -2856,7 +2856,7 @@ mod test { ); } - #[cfg(feature = "num-bigint")] + #[cfg(feature = "num-bigint-generic")] #[test] fn test_from_float_fail() { use core::{f32, f64}; @@ -3017,7 +3017,7 @@ mod test { } #[test] - #[cfg(feature = "num-bigint")] + #[cfg(feature = "num-bigint-generic")] fn test_ratio_to_i128() { assert_eq!( 1i128 << 70, @@ -3028,7 +3028,7 @@ mod test { } #[test] - #[cfg(feature = "num-bigint")] + #[cfg(feature = "num-bigint-generic")] fn test_big_ratio_to_f64() { assert_eq!( BigRational::<4>::new( diff --git a/vendor/num-rational-generic/pow.rs b/vendor/num-rational-generic/pow.rs index 33253320e7..e73fde260b 100644 --- a/vendor/num-rational-generic/pow.rs +++ b/vendor/num-rational-generic/pow.rs @@ -112,7 +112,7 @@ pow_signed_impl!(i64, u64); pow_signed_impl!(i128, u128); pow_signed_impl!(isize, usize); -#[cfg(feature = "num-bigint")] +#[cfg(feature = "num-bigint-generic")] mod bigint { use super::*; use num_bigint::{BigInt, BigUint, Sign}; diff --git a/vendor/num-rational-generic/src/lib.rs b/vendor/num-rational-generic/src/lib.rs index 5a9ffbb53f..cc08ed1060 100644 --- a/vendor/num-rational-generic/src/lib.rs +++ b/vendor/num-rational-generic/src/lib.rs @@ -59,7 +59,7 @@ pub struct Ratio { impl Ratio> { pub fn to_nlimbs(&self) -> Ratio> { let Self { numer, denom } = self; - Ratio::new(numer.to_digits(), denom.to_digits()) + Ratio::new(numer.to_nlimbs(), denom.to_nlimbs()) } } @@ -76,7 +76,7 @@ pub type Rational64 = Ratio; #[cfg(feature = "num-bigint-generic")] /// Alias for arbitrary precision rationals. -pub type BigRational = Ratio>; +pub type BigRational = Ratio; /// These method are `const`. impl Ratio { @@ -2746,7 +2746,7 @@ mod test { #[cfg(feature = "num-bigint-generic")] fn test_big(r: Rational64, e: i32, expected: Rational64) { - let r = BigRational::<4>::new_raw(r.numer.into(), r.denom.into()); + let r = BigRational::new_raw(r.numer.into(), r.denom.into()); let expected = BigRational::new_raw(expected.numer.into(), expected.denom.into()); assert_eq!(r.clone().pow(e), expected.clone()); assert_eq!(Pow::pow(r.clone(), e), expected); diff --git a/vrf/Cargo.toml b/vrf/Cargo.toml index 5e9893a844..4a3828ec06 100644 --- a/vrf/Cargo.toml +++ b/vrf/Cargo.toml @@ -17,10 +17,13 @@ mina-node-account = { workspace = true } mina-p2p-messages = { workspace = true } mina-signer = { workspace = true } num = { version = "0.4", features = ["std"] } +num-bigint-generic = { workspace = true } +num-rational-generic = { workspace = true, features = ["num-bigint-generic"] } +num-traits = { workspace = true, features = ["std"] } o1-utils = { workspace = true } poseidon = { workspace = true } redux = { workspace = true } -serde = "1.0.147" +serde = { workspace = true } serde_json = { version = "1.0.82", features = [ "unbounded_depth", "arbitrary_precision", diff --git a/vrf/src/lib.rs b/vrf/src/lib.rs index e49cd75756..0b2f67d938 100644 --- a/vrf/src/lib.rs +++ b/vrf/src/lib.rs @@ -1,10 +1,12 @@ use ark_ec::{AffineRepr, CurveGroup}; -use ark_ff::PrimeField; +use ark_ff::{self, PrimeField}; use ledger::AccountIndex; use message::VrfMessage; use mina_node_account::AccountPublicKey; use mina_p2p_messages::v2::EpochSeed; -use num::{rational::Ratio, BigInt, ToPrimitive}; +use num_bigint_generic::BigInt; +use num_rational_generic::Ratio; +use num_traits::ToPrimitive; use output::VrfOutput; use serde::{Deserialize, Serialize}; use thiserror::Error; @@ -28,7 +30,7 @@ pub enum VrfError { HexDecodeError(#[from] hex::FromHexError), #[error("Failed to parse decimal big integer from string: {0}")] - BigIntParseError(#[from] num::bigint::ParseBigIntError), + BigIntParseError(#[from] num_bigint_generic::ParseBigIntError), #[error("Field conversion error: {0}")] FieldHelpersError(#[from] o1_utils::field_helpers::FieldHelpersError), @@ -53,14 +55,14 @@ pub enum VrfError { } /// 256 bits -pub(crate) type BigInt256 = BigInt<4>; +pub(crate) type BigInt256 = num_bigint_generic::BigInt<4>; /// 2048 bits -pub(crate) type BigInt2048 = BigInt<32>; +pub(crate) type BigInt2048 = num_bigint_generic::BigInt<32>; pub(crate) type BigRational2048 = Ratio; /// 4096 bits -pub(crate) type BigInt4096 = BigInt<64>; +pub(crate) type BigInt4096 = num_bigint_generic::BigInt<64>; pub(crate) type BigRational4096 = Ratio; #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] @@ -175,7 +177,7 @@ mod test { use std::str::FromStr; use ledger::AccountIndex; - use num::BigInt; + use num_bigint_generic::BigInt; use mina_node_account::AccountSecretKey; use mina_p2p_messages::{ diff --git a/vrf/src/output.rs b/vrf/src/output.rs index 74554d48a0..c108147a6f 100644 --- a/vrf/src/output.rs +++ b/vrf/src/output.rs @@ -2,13 +2,15 @@ use ark_ec::short_weierstrass::Affine; use ark_ff::{BigInteger, BigInteger256, PrimeField}; use ledger::{proofs::transaction::field_to_bits, AppendToInputs, ToInputs}; use mina_p2p_messages::v2::ConsensusVrfOutputTruncatedStableV1; -use num::{BigInt, BigRational, One, ToPrimitive}; +use num_bigint_generic::{BigInt}; +use num_traits::{One, ToPrimitive}; +use num_rational_generic::BigRational; use o1_utils::FieldHelpers; use poseidon::hash::params::MINA_VRF_OUTPUT; use serde::{Deserialize, Serialize}; use sha2::{Digest, Sha256}; -use crate::{BaseField, BigInt2048, ScalarField}; +use crate::{BaseField, BigInt2048, BigRational2048, ScalarField}; use super::serialize::{ark_deserialize, ark_serialize}; @@ -87,14 +89,14 @@ impl VrfOutput { // ocaml: Bignum_bigint.(shift_left one length_in_bits)) // where: length_in_bits = Int.min 256 (Field.size_in_bits - 2) // Field.size_in_bits = 255 - let two_tpo_256 = BigInt::one() << 253u32; + let two_tpo_256 = BigInt2048::one() << 253u32; let vrf_out: BigInt2048 = BigInt2048::from_bytes_be( - num::bigint::Sign::Plus, + num_bigint_generic::Sign::Plus, &self.truncated().into_bigint().to_bytes_be(), ); - BigRational::new(vrf_out, two_tpo_256).to_f64().unwrap() + BigRational2048::new(vrf_out, two_tpo_256).to_f64().unwrap() } pub fn to_base_58(&self) -> String { diff --git a/vrf/src/threshold.rs b/vrf/src/threshold.rs index 784e9441b2..f3c37c4c6f 100644 --- a/vrf/src/threshold.rs +++ b/vrf/src/threshold.rs @@ -1,6 +1,8 @@ -use ark_ff::{BigInteger, BigInteger256, One, Zero}; +use ark_ff::{self, BigInteger, BigInteger256, One, Zero}; use itertools::unfold; -use num::{rational::Ratio, BigInt, FromPrimitive, Signed}; +use num_bigint_generic::{BigInt, Sign}; +use num_rational_generic::Ratio; +use num_traits::{FromPrimitive, Signed}; use crate::{BigInt2048, BigInt256, BigInt4096, BigRational2048, BigRational4096}; @@ -20,7 +22,10 @@ impl Threshold { // 1. set up parameters to calculate threshold // Note: IMO all these parameters can be represented as constants. They do not change. The calculation is most likely in the // code to adjust them in the future. We could create an utility that generates these params using f and log terms - let f = BigRational2048::new(BigInt::from_u8(3).unwrap(), BigInt::from_u8(4).unwrap()); + let f = BigRational2048::new( + BigInt2048::from_u8(3).unwrap(), + BigInt2048::from_u8(4).unwrap(), + ); let base = BigRational2048::one() - f; @@ -29,15 +34,15 @@ impl Threshold { let (per_term_precission, terms_needed, _) = Self::bit_params(&abs_log_base); let terms_needed: i32 = terms_needed.try_into().unwrap(); - let mut linear_term_integer_part = BigInt::zero(); + let mut linear_term_integer_part = BigInt4096::zero(); let abs_log_base: BigRational4096 = abs_log_base.to_nlimbs::<64>(); let coefficients = (1..terms_needed).map(|x| { let c = abs_log_base.pow(x) / Self::factorial(x.into()); let c_frac = if x == 1 { - let c_whole = c.to_integer(); - let c_frac = c - bigint_to_bigrational(&c_whole); + let c_whole: BigInt4096 = c.to_integer(); + let c_frac = c - bigint_to_bigrational::<64>(&c_whole); linear_term_integer_part = c_whole; c_frac } else { @@ -62,7 +67,7 @@ impl Threshold { let input = BigRational4096::new(numer.to_nlimbs(), two_tpo_per_term_precission.to_nlimbs()); - let denom = BigInt::one() << per_term_precission; + let denom = BigInt4096::one() << per_term_precission; let (res, _) = coefficients.into_iter().fold( (BigRational4096::zero(), BigRational4096::one()), @@ -90,8 +95,8 @@ impl Threshold { } fn terms_needed(log_base: &BigRational2048, bits_of_precission: u32) -> i32 { - let two = BigInt4096::one() + BigInt::one(); - let lower_bound = bigint_to_bigrational(&two.pow(bits_of_precission)); + let two: BigInt4096 = BigInt4096::one() + BigInt4096::one(); + let lower_bound: BigRational4096 = bigint_to_bigrational(&two.pow(bits_of_precission)); let mut n = 0; let log_base: BigRational4096 = log_base.to_nlimbs(); @@ -107,15 +112,17 @@ impl Threshold { } } - fn factorial(n: BigInt) -> BigInt { - if n == BigInt::::zero() { - return BigInt::::one(); + fn factorial( + n: num_bigint_generic::BigInt, + ) -> num_bigint_generic::BigInt { + if n == num_bigint_generic::BigInt::::zero() { + return num_bigint_generic::BigInt::::one(); } let mut res = n.clone(); - let mut i = n - BigInt::::one(); - while i != BigInt::::zero() { + let mut i = n - num_bigint_generic::BigInt::::one(); + while i != num_bigint_generic::BigInt::::zero() { res *= i.clone(); - i -= BigInt::::one(); + i -= num_bigint_generic::BigInt::::one(); } res @@ -188,20 +195,22 @@ pub fn get_fractional(vrf_out: BigInteger256) -> Ratio { // Field.size_in_bits = 255 let two_tpo_256 = BigInt2048::one() << 253u32; - let vrf_out = BigInt2048::from_bytes_be(num::bigint::Sign::Plus, &vrf_out.to_bytes_be()); + let vrf_out = BigInt2048::from_bytes_be(Sign::Plus, &vrf_out.to_bytes_be()); Ratio::new(vrf_out, two_tpo_256) } // TODO: is there a fn like this? -pub fn bigint_to_bigrational(x: &BigInt) -> Ratio> { - Ratio::new(x.clone(), BigInt::one()) +pub fn bigint_to_bigrational( + x: &num_bigint_generic::BigInt, +) -> Ratio> { + Ratio::new(x.clone(), num_bigint_generic::BigInt::one()) } pub fn bigrational_as_fixed_point( - c: Ratio>, + c: Ratio>, per_term_precission: usize, -) -> BigInt { +) -> num_bigint_generic::BigInt { let numer = c.numer(); let denom = c.denom(); @@ -221,16 +230,18 @@ mod test { use std::str::FromStr; use ark_ff::{One, Zero}; - use num::{BigInt, BigRational, ToPrimitive}; + use num_bigint_generic::BigInt; + use num_rational_generic::BigRational; + use num_traits::ToPrimitive; use super::*; // TODO: move to regular fns, rework step - fn first_non_zero(stake: BigInt, total_currency: BigInt, step: BigInt) -> BigInt { - let ten = BigInt::from_str("10").unwrap(); + fn first_non_zero(stake: BigInt<4>, total_currency: BigInt<4>, step: BigInt<4>) -> BigInt { + let ten = BigInt::<4>::from_str("10").unwrap(); let mut stake = stake; - if step == BigInt::zero() { - stake + BigInt::one() + if step == BigInt::<4>::zero() { + stake + BigInt::<4>::one() } else { loop { let thrs = Threshold::new(stake.clone(), total_currency.clone());