diff --git a/CHANGELOG.md b/CHANGELOG.md index e312672ee7..9c2ce9a6ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -106,6 +106,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ([#1230](https://github.com/o1-labs/openmina/pull/1230)) - bump itertools from 0.10.5 to 0.12.0 #1228 ([#1228](https://github.com/o1-labs/openmina/pull/1228)) +- Remove OpenMina forks of arkworks and proof-systems + ([#1383](https://github.com/o1-labs/mina-rust/pull/1383)) ### Other diff --git a/Cargo.lock b/Cargo.lock index d2877a7920..94db0d3513 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -252,7 +252,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", @@ -273,7 +274,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", @@ -293,7 +295,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", @@ -302,7 +305,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", @@ -314,7 +318,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", @@ -340,7 +345,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", @@ -353,7 +359,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", @@ -3476,7 +3483,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=0b0fd5fe73964d2a3628c788e40ead819a8a806d#0b0fd5fe73964d2a3628c788e40ead819a8a806d" dependencies = [ "ark-ec", "ark-ff", @@ -4238,7 +4245,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=0b0fd5fe73964d2a3628c788e40ead819a8a806d#0b0fd5fe73964d2a3628c788e40ead819a8a806d" [[package]] name = "io-lifetimes" @@ -4408,7 +4415,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=0b0fd5fe73964d2a3628c788e40ead819a8a806d#0b0fd5fe73964d2a3628c788e40ead819a8a806d" dependencies = [ "ark-ec", "ark-ff", @@ -5187,7 +5194,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=0b0fd5fe73964d2a3628c788e40ead819a8a806d#0b0fd5fe73964d2a3628c788e40ead819a8a806d" dependencies = [ "ark-bn254", "ark-ec", @@ -5223,7 +5230,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=0b0fd5fe73964d2a3628c788e40ead819a8a806d#0b0fd5fe73964d2a3628c788e40ead819a8a806d" dependencies = [ "ark-ff", "bitvec", @@ -5442,6 +5449,7 @@ dependencies = [ "alloc-test", "anyhow", "ark-ff", + "ark-serialize 0.5.0", "base64 0.22.1", "binprot", "binprot_derive", @@ -5480,7 +5488,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=0b0fd5fe73964d2a3628c788e40ead819a8a806d#0b0fd5fe73964d2a3628c788e40ead819a8a806d" dependencies = [ "ark-ec", "ark-ff", @@ -5522,7 +5530,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=0b0fd5fe73964d2a3628c788e40ead819a8a806d#0b0fd5fe73964d2a3628c788e40ead819a8a806d" dependencies = [ "ark-ec", "ark-ff", @@ -5532,6 +5540,7 @@ dependencies = [ "hex", "mina-curves", "mina-hasher", + "num-bigint", "o1-utils", "rand", "sha2 0.10.8", @@ -6164,7 +6173,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=0b0fd5fe73964d2a3628c788e40ead819a8a806d#0b0fd5fe73964d2a3628c788e40ead819a8a806d" dependencies = [ "ark-ec", "ark-ff", @@ -6839,7 +6848,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=0b0fd5fe73964d2a3628c788e40ead819a8a806d#0b0fd5fe73964d2a3628c788e40ead819a8a806d" dependencies = [ "ark-ec", "ark-ff", @@ -6922,6 +6931,7 @@ dependencies = [ "ark-ff", "ark-serialize 0.5.0", "mina-curves", + "o1-utils", "once_cell", "serde", ] @@ -9808,7 +9818,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=0b0fd5fe73964d2a3628c788e40ead819a8a806d#0b0fd5fe73964d2a3628c788e40ead819a8a806d" dependencies = [ "ark-ff", "hex", diff --git a/Cargo.toml b/Cargo.toml index ead3c17d2c..79785e8601 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -46,31 +46,28 @@ 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" - +ark-ec = { version = "0.5.0", features = ["std"] } +ark-ff = { version = "0.5.0", features = ["parallel", "asm", "std"] } +ark-poly = { version = "0.5.0" } +ark-serialize = { version = "0.5.0", 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 = "0b0fd5fe73964d2a3628c788e40ead819a8a806d" } +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 = "0b0fd5fe73964d2a3628c788e40ead819a8a806d" } +mina-hasher = { git = "https://github.com/o1-labs/proof-systems", rev = "0b0fd5fe73964d2a3628c788e40ead819a8a806d" } mina-node-account = { path = "node/account" } +mina-p2p-messages = { path = "mina-p2p-messages" } +mina-poseidon = { git = "https://github.com/o1-labs/proof-systems", rev = "0b0fd5fe73964d2a3628c788e40ead819a8a806d" } +mina-producer-dashboard = { path = "producer-dashboard" } +mina-signer = { git = "https://github.com/o1-labs/proof-systems", rev = "0b0fd5fe73964d2a3628c788e40ead819a8a806d" } +num-bigint = { git = "https://github.com/openmina/num-bigint", branch = "rebase-onstack" } # branch: rebase-onstack +o1-utils = { git = "https://github.com/o1-labs/proof-systems", rev = "0b0fd5fe73964d2a3628c788e40ead819a8a806d" } +poly-commitment = { git = "https://github.com/o1-labs/proof-systems", rev = "0b0fd5fe73964d2a3628c788e40ead819a8a806d" } +poseidon = { path = "poseidon" } redux = { git = "https://github.com/o1-labs/redux-rs.git", rev = "06c8366", features = [ "serde", ] } @@ -80,29 +77,9 @@ 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 mina-curves = { git = "https://github.com/o1-labs/proof-systems", rev = "d1912bca54d2609296b9af9d09ad1ef78702e203", features = [ "32x9" ] } # 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 @@ -115,11 +92,6 @@ 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 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..93ecfeaaa4 100644 --- a/mina-p2p-messages/Cargo.toml +++ b/mina-p2p-messages/Cargo.toml @@ -7,6 +7,7 @@ license = "Apache-2.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +ark-serialize = { workspace = true } base64 = "0.22" binprot = { git = "https://github.com/openmina/binprot-rs", rev = "400b52c" } binprot_derive = { git = "https://github.com/openmina/binprot-rs", rev = "400b52c" } diff --git a/mina-p2p-messages/src/bigint.rs b/mina-p2p-messages/src/bigint.rs index 0d26766eff..7c21b54203 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,16 +64,14 @@ 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 { @@ -190,17 +210,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()) } } 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/node/common/src/service/snarks.rs b/node/common/src/service/snarks.rs index d450973b56..eade9df85f 100644 --- a/node/common/src/service/snarks.rs +++ b/node/common/src/service/snarks.rs @@ -1,6 +1,5 @@ use std::sync::Arc; -use ark_ff::fields::arithmetic::InvalidBigInt; use ledger::{ scan_state::{ scan_state::transaction_snark::{SokDigest, Statement}, @@ -8,7 +7,7 @@ use ledger::{ }, transaction_pool::{TransactionError, TransactionPoolErrors}, }; -use mina_p2p_messages::v2; +use mina_p2p_messages::{bigint::InvalidBigInt, v2}; use node::{ core::{ channels::mpsc, diff --git a/node/src/ledger/ledger_service.rs b/node/src/ledger/ledger_service.rs index 570881816a..7fe5c881cb 100644 --- a/node/src/ledger/ledger_service.rs +++ b/node/src/ledger/ledger_service.rs @@ -24,7 +24,6 @@ use crate::{ }, }, }; -use ark_ff::fields::arithmetic::InvalidBigInt; use ledger::{ scan_state::{ currency::Slot, @@ -56,6 +55,7 @@ use mina_core::{ }; use mina_curves::pasta::Fp; use mina_p2p_messages::{ + bigint::InvalidBigInt, binprot::BinProtRead, list::List, v2::{ diff --git a/node/src/ledger/mod.rs b/node/src/ledger/mod.rs index b2fe47a648..0671bdf319 100644 --- a/node/src/ledger/mod.rs +++ b/node/src/ledger/mod.rs @@ -2,8 +2,8 @@ pub mod read; pub mod write; mod ledger_config; -use ark_ff::fields::arithmetic::InvalidBigInt; pub use ledger_config::*; +use mina_p2p_messages::bigint::InvalidBigInt; mod ledger_event; pub use ledger_event::*; diff --git a/node/src/p2p/callbacks/p2p_callbacks_reducer.rs b/node/src/p2p/callbacks/p2p_callbacks_reducer.rs index 95e8540788..c13b0c6e90 100644 --- a/node/src/p2p/callbacks/p2p_callbacks_reducer.rs +++ b/node/src/p2p/callbacks/p2p_callbacks_reducer.rs @@ -1,10 +1,10 @@ -use ark_ff::fields::arithmetic::InvalidBigInt; use mina_core::{ block::{prevalidate::BlockPrevalidationError, BlockWithHash}, bug_condition, log, transaction::TransactionWithHash, }; use mina_p2p_messages::{ + bigint::InvalidBigInt, gossip::GossipNetMessageV2, v2::{MinaLedgerSyncLedgerAnswerStableV2, StateHash}, }; diff --git a/node/src/rpc/heartbeat.rs b/node/src/rpc/heartbeat.rs index 3cd13c2461..79cdaa320e 100644 --- a/node/src/rpc/heartbeat.rs +++ b/node/src/rpc/heartbeat.rs @@ -196,7 +196,7 @@ impl NodeHeartbeat { ); let kp = Keypair::from(secret_key.clone()); - let signature = signer.sign(&kp, &digest); + let signature = signer.sign(&kp, &digest, false); signature.into() }; diff --git a/node/src/rpc/mod.rs b/node/src/rpc/mod.rs index 7fe0d5047e..848b93e6fa 100644 --- a/node/src/rpc/mod.rs +++ b/node/src/rpc/mod.rs @@ -1,7 +1,6 @@ mod rpc_state; use std::{collections::BTreeMap, str::FromStr}; -use ark_ff::fields::arithmetic::InvalidBigInt; use ledger::{ scan_state::{ currency::{Amount, Balance, Fee, Nonce, Slot}, @@ -16,7 +15,7 @@ use mina_core::{ }; use mina_node_account::AccountPublicKey; use mina_p2p_messages::{ - bigint::BigInt, + bigint::{BigInt, InvalidBigInt}, v2::{ LedgerHash, MinaBaseSignedCommandPayloadBodyStableV2, MinaBaseSignedCommandStableV2, MinaBaseTransactionStatusStableV2, MinaBaseUserCommandStableV2, diff --git a/node/src/transition_frontier/genesis/transition_frontier_genesis_config.rs b/node/src/transition_frontier/genesis/transition_frontier_genesis_config.rs index a6fc7d55b2..29fc4d76d8 100644 --- a/node/src/transition_frontier/genesis/transition_frontier_genesis_config.rs +++ b/node/src/transition_frontier/genesis/transition_frontier_genesis_config.rs @@ -7,7 +7,6 @@ use std::{ }; use crate::{account::AccountSecretKey, daemon_json::EpochData}; -use ark_ff::fields::arithmetic::InvalidBigInt; use ledger::{ proofs::caching::{ensure_path_exists, mina_cache_path}, scan_state::currency::Balance, @@ -16,6 +15,7 @@ use ledger::{ use mina_core::constants::{constraint_constants, DEFAULT_GENESIS_TIMESTAMP_MILLISECONDS}; use mina_curves::pasta::Fp; use mina_p2p_messages::{ + bigint::InvalidBigInt, binprot::{ self, macros::{BinProtRead, BinProtWrite}, diff --git a/node/src/transition_frontier/sync/ledger/staged/mod.rs b/node/src/transition_frontier/sync/ledger/staged/mod.rs index 81803af7af..417499809e 100644 --- a/node/src/transition_frontier/sync/ledger/staged/mod.rs +++ b/node/src/transition_frontier/sync/ledger/staged/mod.rs @@ -1,6 +1,6 @@ mod transition_frontier_sync_ledger_staged_state; -use ark_ff::fields::arithmetic::InvalidBigInt; use mina_curves::pasta::Fp; +use mina_p2p_messages::bigint::InvalidBigInt; pub use transition_frontier_sync_ledger_staged_state::*; mod transition_frontier_sync_ledger_staged_actions; diff --git a/node/src/watched_accounts/mod.rs b/node/src/watched_accounts/mod.rs index 152d49e5dd..8017b4e86f 100644 --- a/node/src/watched_accounts/mod.rs +++ b/node/src/watched_accounts/mod.rs @@ -6,10 +6,12 @@ pub use watched_accounts_actions::*; mod watched_accounts_reducer; -use ark_ff::fields::arithmetic::InvalidBigInt; -use mina_p2p_messages::v2::{ - NonZeroCurvePoint, NonZeroCurvePointUncompressedStableV1, StagedLedgerDiffDiffDiffStableV2, - StagedLedgerDiffDiffPreDiffWithAtMostTwoCoinbaseStableV2B, +use mina_p2p_messages::{ + bigint::InvalidBigInt, + v2::{ + NonZeroCurvePoint, NonZeroCurvePointUncompressedStableV1, StagedLedgerDiffDiffDiffStableV2, + StagedLedgerDiffDiffPreDiffWithAtMostTwoCoinbaseStableV2B, + }, }; pub fn is_transaction_affecting_account( 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/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/src/transaction_fuzzer/context.rs b/tools/fuzzing/src/transaction_fuzzer/context.rs index 59dc79e9b5..618f34b8d6 100644 --- a/tools/fuzzing/src/transaction_fuzzer/context.rs +++ b/tools/fuzzing/src/transaction_fuzzer/context.rs @@ -4,7 +4,7 @@ use crate::transaction_fuzzer::{ mutator::Mutator, serialize, }; -use ark_ff::{fields::arithmetic::InvalidBigInt, Zero}; +use ark_ff::Zero; use ledger::{ dummy, scan_state::{ @@ -27,7 +27,9 @@ use ledger::{ use mina_core::{consensus::ConsensusConstants, constants::ConstraintConstants, NetworkConfig}; use mina_curves::pasta::{Fp, Fq}; use mina_p2p_messages::{ - bigint, binprot, + bigint, + bigint::InvalidBigInt, + binprot, binprot::SmallString1k, v2::{ MinaTransactionLogicTransactionAppliedStableV2, diff --git a/tools/fuzzing/src/transaction_fuzzer/generator.rs b/tools/fuzzing/src/transaction_fuzzer/generator.rs index 1745be1c04..48f8e9b075 100644 --- a/tools/fuzzing/src/transaction_fuzzer/generator.rs +++ b/tools/fuzzing/src/transaction_fuzzer/generator.rs @@ -1887,7 +1887,7 @@ pub fn sign_account_updates( true => full_txn_commitment, false => txn_commitment, }; - Some(signer.sign(&kp, input)) + Some(signer.sign(&kp, input, false)) } _ => None, }; @@ -1923,7 +1923,7 @@ impl Generator for FuzzerCtx { Some(keypair) => keypair.clone(), None => self.gen(), }; - zkapp_command.fee_payer.authorization = signer.sign(&keypair, &full_txn_commitment); + zkapp_command.fee_payer.authorization = signer.sign(&keypair, &full_txn_commitment, false); sign_account_updates( self, @@ -1974,7 +1974,7 @@ impl Generator for FuzzerCtx { fn sign_payload(keypair: &Keypair, payload: &SignedCommandPayload) -> Signature { let tx = TransactionUnionPayload::of_user_command_payload(payload); let mut signer = mina_signer::create_legacy(NetworkId::TESTNET); - signer.sign(keypair, &tx) + signer.sign(keypair, &tx, false) } impl Generator for FuzzerCtx { diff --git a/tools/fuzzing/src/transaction_fuzzer/mutator.rs b/tools/fuzzing/src/transaction_fuzzer/mutator.rs index b609814050..ee5181a36d 100644 --- a/tools/fuzzing/src/transaction_fuzzer/mutator.rs +++ b/tools/fuzzing/src/transaction_fuzzer/mutator.rs @@ -741,7 +741,7 @@ impl Mutator for FuzzerCtx { if self.gen.rng.gen_bool(0.9) { if let Some(keypair) = self.find_keypair(&t.fee_payer.body.public_key) { - t.fee_payer.authorization = signer.sign(keypair, &full_txn_commitment); + t.fee_payer.authorization = signer.sign(keypair, &full_txn_commitment, false); } } diff --git a/vrf/Cargo.toml b/vrf/Cargo.toml index 5e9893a844..c7a8409756 100644 --- a/vrf/Cargo.toml +++ b/vrf/Cargo.toml @@ -20,7 +20,7 @@ num = { version = "0.4", 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",