Skip to content

Commit 021ba70

Browse files
committed
Use faster field implementation in wasm target
1 parent 2a6b0a1 commit 021ba70

File tree

29 files changed

+182
-124
lines changed

29 files changed

+182
-124
lines changed

Cargo.lock

Lines changed: 18 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,16 @@ indexing_slicing = "warn"
4545
mina-p2p-messages = { path = "mina-p2p-messages" }
4646
poseidon = { path = "poseidon" }
4747
ledger = { path = "ledger", package = "mina-tree" }
48-
mina-hasher = { git = "https://github.com/openmina/proof-systems", rev = "d0cd63b" }
49-
mina-signer = { git = "https://github.com/openmina/proof-systems", rev = "d0cd63b" }
50-
mina-curves = { git = "https://github.com/openmina/proof-systems", rev = "d0cd63b" }
51-
o1-utils = { git = "https://github.com/openmina/proof-systems", rev = "d0cd63b" }
52-
kimchi = { git = "https://github.com/openmina/proof-systems", rev = "d0cd63b" }
53-
mina-poseidon = {git = "https://github.com/openmina/proof-systems", rev = "d0cd63b"}
54-
poly-commitment = {git = "https://github.com/openmina/proof-systems", rev = "d0cd63b"}
48+
49+
mina-hasher = { git = "https://github.com/openmina/proof-systems", rev = "c478b19" }
50+
mina-signer = { git = "https://github.com/openmina/proof-systems", rev = "c478b19" }
51+
mina-curves = { git = "https://github.com/openmina/proof-systems", rev = "c478b19" }
52+
# mina-curves = { git = "https://github.com/openmina/proof-systems", rev = "c478b19", features = [ "32x9" ] }
53+
o1-utils = { git = "https://github.com/openmina/proof-systems", rev = "c478b19" }
54+
kimchi = { git = "https://github.com/openmina/proof-systems", rev = "c478b19" }
55+
mina-poseidon = {git = "https://github.com/openmina/proof-systems", rev = "c478b19" }
56+
poly-commitment = {git = "https://github.com/openmina/proof-systems", rev = "c478b19" }
57+
5558
libp2p = { git = "https://github.com/openmina/rust-libp2p", rev = "5c44c7d9", default-features = false }
5659
vrf = { path = "vrf" }
5760
openmina-node-account = { path = "node/account" }
@@ -63,6 +66,9 @@ linkme = "0.3.22"
6366
static_assertions = "1.1.0"
6467
juniper = { version = "0.16" }
6568

69+
ark-ff = { version = "0.3.0", features = [ "parallel", "asm", "std" ] }
70+
# ark-ff = { version = "0.3.0", features = [ "parallel", "asm", "std", "32x9" ] }
71+
6672

6773
[profile.fuzz]
6874
inherits = "release"
@@ -76,10 +82,10 @@ incremental = false
7682
codegen-units = 1
7783

7884
[patch.crates-io]
79-
ark-ff = { git = "https://github.com/openmina/algebra", rev = "33a1de2" } # branch: fix-openmina
80-
ark-ec = { git = "https://github.com/openmina/algebra", rev = "33a1de2" } # branch: fix-openmina
81-
ark-poly = { git = "https://github.com/openmina/algebra", rev = "33a1de2" } # branch: fix-openmina
82-
ark-serialize = { git = "https://github.com/openmina/algebra", rev = "33a1de2" } # branch: fix-openmina
85+
ark-ff = { git = "https://github.com/openmina/algebra", rev = "f42a8ec" } # branch: fix-openmina-webnode
86+
ark-ec = { git = "https://github.com/openmina/algebra", rev = "f42a8ec" } # branch: fix-openmina-webnode
87+
ark-poly = { git = "https://github.com/openmina/algebra", rev = "f42a8ec" } # branch: fix-openmina-webnode
88+
ark-serialize = { git = "https://github.com/openmina/algebra", rev = "f42a8ec" } # branch: fix-openmina-webnode
8389

8490
[profile.test.package."*"]
8591
opt-level = 3

core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ mina-hasher = { workspace = true }
3131
mina-p2p-messages = { workspace = true }
3232
poseidon = { workspace = true }
3333
hex = "0.4.3"
34-
ark-ff = { version = "0.3.0", features = [ "parallel", "asm", "std" ] }
34+
ark-ff = { workspace = true }
3535

3636
[target.'cfg(not(target_family = "wasm"))'.dependencies]
3737
redux = { workspace = true, features=["serializable_callbacks"] }

ledger/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ libc = "0.2"
4646

4747
itertools = "0.10"
4848

49-
ark-ff = { version = "0.3.0", features = [ "parallel", "asm", "std" ] }
49+
ark-ff = { workspace = true }
5050
ark-ec = { version = "0.3.0", features = [ "std" ] }
5151
ark-serialize = { version = "0.3.0", features = [ "std" ] }
5252
ark-poly = { version = "0.3.0", features = [ "std" ] }

ledger/src/account/account.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1760,14 +1760,20 @@ mod tests {
17601760

17611761
#[test]
17621762
fn test_size_account() {
1763+
const SIZE_WITH_9LIMBS: usize = 296;
1764+
17631765
#[cfg(not(target_family = "wasm"))]
17641766
const SIZE: usize = 280;
17651767

17661768
// FIXME: was 2496bytes before zkapp got boxed, what should be the size now?
17671769
#[cfg(target_family = "wasm")]
17681770
const SIZE: usize = 280;
17691771

1770-
assert_eq!(std::mem::size_of::<Account>(), SIZE);
1772+
if std::mem::size_of::<BigInteger256>() == 9 * 4 {
1773+
assert_eq!(std::mem::size_of::<Account>(), SIZE_WITH_9LIMBS);
1774+
} else {
1775+
assert_eq!(std::mem::size_of::<Account>(), SIZE);
1776+
}
17711777
}
17721778

17731779
#[test]

ledger/src/port_ocaml/hash.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,15 @@ fn hash_field(f: &Fp) -> u32 {
9090
let mut acc = 0;
9191

9292
let bigint: BigInteger256 = (*f).into();
93-
let nignore: usize = bigint.0.iter().rev().take_while(|&b| *b == 0).count();
93+
let bigint = bigint.to_64x4();
94+
let nignore: usize = bigint.iter().rev().take_while(|&b| *b == 0).count();
9495

95-
for bigint in bigint.0.iter().take(BigInteger256::NUM_LIMBS - nignore) {
96+
for bigint in bigint.iter().take(BigInteger256::NUM_LIMBS - nignore) {
9697
acc = mix(acc, (bigint & 0xFFFF_FFFF) as u32);
9798
acc = mix(acc, (bigint >> 32) as u32);
9899
}
99100

100-
if bigint.0.last().unwrap() & 0x8000_0000_0000_0000 != 0 {
101+
if bigint.last().unwrap() & 0x8000_0000_0000_0000 != 0 {
101102
// TODO: Not sure if that condition is correct
102103
acc += 1;
103104
}

ledger/src/proofs/block.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -316,17 +316,17 @@ mod floating_point {
316316
}
317317

318318
const COEFFICIENTS: [(Sgn, BigInteger256); 11] = [
319-
(Sgn::Pos, BigInteger256::new([405058, 0, 0, 0])),
320-
(Sgn::Neg, BigInteger256::new([1007582, 0, 0, 0])),
321-
(Sgn::Pos, BigInteger256::new([465602, 0, 0, 0])),
322-
(Sgn::Neg, BigInteger256::new([161365, 0, 0, 0])),
323-
(Sgn::Pos, BigInteger256::new([44739, 0, 0, 0])),
324-
(Sgn::Neg, BigInteger256::new([10337, 0, 0, 0])),
325-
(Sgn::Pos, BigInteger256::new([2047, 0, 0, 0])),
326-
(Sgn::Neg, BigInteger256::new([354, 0, 0, 0])),
327-
(Sgn::Pos, BigInteger256::new([54, 0, 0, 0])),
328-
(Sgn::Neg, BigInteger256::new([7, 0, 0, 0])),
329-
(Sgn::Pos, BigInteger256::new([0, 0, 0, 0])),
319+
(Sgn::Pos, BigInteger256::from_64x4([405058, 0, 0, 0])),
320+
(Sgn::Neg, BigInteger256::from_64x4([1007582, 0, 0, 0])),
321+
(Sgn::Pos, BigInteger256::from_64x4([465602, 0, 0, 0])),
322+
(Sgn::Neg, BigInteger256::from_64x4([161365, 0, 0, 0])),
323+
(Sgn::Pos, BigInteger256::from_64x4([44739, 0, 0, 0])),
324+
(Sgn::Neg, BigInteger256::from_64x4([10337, 0, 0, 0])),
325+
(Sgn::Pos, BigInteger256::from_64x4([2047, 0, 0, 0])),
326+
(Sgn::Neg, BigInteger256::from_64x4([354, 0, 0, 0])),
327+
(Sgn::Pos, BigInteger256::from_64x4([54, 0, 0, 0])),
328+
(Sgn::Neg, BigInteger256::from_64x4([7, 0, 0, 0])),
329+
(Sgn::Pos, BigInteger256::from_64x4([0, 0, 0, 0])),
330330
];
331331

332332
pub struct Params {

ledger/src/proofs/group_map.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,10 @@ fn sqrt_exn<F: FieldWitness>(x: F, w: &mut Witness<F>) -> F {
109109
}
110110

111111
fn is_square<F: FieldWitness>(x: F) -> bool {
112-
let s = x.pow(F::Params::MODULUS_MINUS_ONE_DIV_TWO);
112+
use ark_ff::BigInteger;
113+
114+
let modulus_minus_one_div_two = F::Params::MODULUS_MINUS_ONE_DIV_TWO.to_64x4();
115+
let s = x.pow(modulus_minus_one_div_two);
113116
s.is_zero() || s.is_one()
114117
}
115118

ledger/src/proofs/numbers/currency.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use crate::ToInputs;
1414

1515
use super::common::{range_check, ForZkappCheck};
1616

17+
#[derive(Debug)]
1718
pub enum RangeCheckFlaggedKind {
1819
Add,
1920
Sub,

ledger/src/proofs/public_input/messages.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,15 @@ impl MessagesForNextWrapProof {
5858
let field: Fq = hash_fields(&fields);
5959

6060
let bigint: BigInteger256 = field.into_repr();
61-
bigint.0
61+
bigint.to_64x4()
6262
}
6363

6464
pub fn hash_checked(&self, w: &mut Witness<Fq>) -> [u64; 4] {
6565
let fields: Vec<Fq> = self.to_fields();
6666
let field: Fq = checked_hash2(&fields, w);
6767

6868
let bigint: BigInteger256 = field.into_repr();
69-
bigint.0
69+
bigint.to_64x4()
7070
}
7171

7272
// TODO: De-duplicate with above
@@ -75,7 +75,7 @@ impl MessagesForNextWrapProof {
7575
let field: Fq = crate::proofs::transaction::checked_hash3(&fields, w);
7676

7777
let bigint: BigInteger256 = field.into_repr();
78-
bigint.0
78+
bigint.to_64x4()
7979
}
8080

8181
/// Implementation of `to_field_elements`
@@ -152,7 +152,7 @@ where
152152
let field: Fp = hash_fields(&fields);
153153

154154
let bigint: BigInteger256 = field.into_repr();
155-
bigint.0
155+
bigint.to_64x4()
156156
}
157157

158158
/// Implementation of `to_field_elements`

0 commit comments

Comments
 (0)