Skip to content

Commit bdd36bd

Browse files
authored
Merge pull request #939 from openmina/move-out-poseidon
Use faster field implementation in `wasm` target
2 parents 7551e20 + bc2758f commit bdd36bd

File tree

30 files changed

+215
-124
lines changed

30 files changed

+215
-124
lines changed

.github/workflows/ci.yaml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,40 @@ jobs:
4343
cd ledger
4444
cargo test --release -- -Z unstable-options --report-time
4545
46+
ledger-32x9-tests:
47+
runs-on: ubuntu-20.04
48+
steps:
49+
- name: Git checkout
50+
uses: actions/checkout@v4
51+
- name: Setup build dependencies
52+
run: |
53+
sudo apt update
54+
sudo apt install -y protobuf-compiler
55+
- name: Setup Rust
56+
run: |
57+
# Nightly to be able to use `--report-time` below
58+
rustup install nightly
59+
rustup override set nightly
60+
- name: Download circuits files
61+
run: |
62+
git clone --depth 1 https://github.com/openmina/circuit-blobs.git
63+
ln -s -b $PWD/circuit-blobs/* ledger/
64+
- name: Enable 32x9 fields implementation
65+
run: |
66+
cargo install sd
67+
sd '^mina-curves.*$' '' ./Cargo.toml
68+
sd '^ark-ff = \{ version .*$' '' ./Cargo.toml
69+
sd -F '# UNCOMMENTED_IN_CI ' '' ./Cargo.toml
70+
cat ./Cargo.toml
71+
- name: Build ledger tests
72+
run: |
73+
cd ledger
74+
cargo build --release --tests
75+
- name: Run ledger tests
76+
run: |
77+
cd ledger
78+
cargo test --release -- -Z unstable-options --report-time
79+
4680
tx-fuzzer-check:
4781
runs-on: ubuntu-20.04
4882
steps:

Cargo.lock

Lines changed: 17 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+
# UNCOMMENTED_IN_CI 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+
# UNCOMMENTED_IN_CI 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,

0 commit comments

Comments
 (0)