Skip to content

Commit ba9048c

Browse files
committed
poseidon: stop using in-house FromBytes implementation
This is part of removing forks of dependencies.
1 parent 5667a1f commit ba9048c

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

poseidon/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ workspace = true
1010
ark-ff = { workspace = true }
1111
ark-serialize.workspace = true
1212
mina-curves = { workspace = true }
13+
o1-utils.workspace = true
1314
once_cell = "1"
1415
serde.workspace = true

poseidon/src/hash.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use ark_ff::{BigInt, BigInteger256, Field, FromBytes};
1+
use ark_ff::{BigInteger256, Field};
22
use mina_curves::pasta::Fp;
33

44
use crate::{PlonkSpongeConstantsKimchi, Sponge, SpongeParamsForField};
@@ -44,10 +44,9 @@ impl Item {
4444
Item::U8(v) => *v as u64,
4545
Item::U32(v) => *v as u64,
4646
Item::U48(v) => {
47-
let mut bytes = <[u8; 32]>::default();
47+
let mut bytes = [0u8; 8];
4848
bytes[..6].copy_from_slice(&v[..]);
49-
let value = FromBytes::read(&bytes[..]).expect("Must not go wrong");
50-
BigInteger256::new(value).0[0] // Never fail with only 6 bytes
49+
u64::from_le_bytes(bytes[..8].try_into().unwrap())
5150
}
5251
Item::U64(v) => *v,
5352
}
@@ -183,9 +182,7 @@ fn param_to_field_impl(param: &str, default: &[u8; 32]) -> Fp {
183182
let mut fp = *default;
184183
fp[..len].copy_from_slice(param_bytes);
185184

186-
let value = FromBytes::read(&fp[..]).expect("Error reading");
187-
let element = BigInt::new(value);
188-
Fp::new(element)
185+
Fp::from_random_bytes(&fp).expect("Must be a valid field element")
189186
}
190187

191188
pub fn param_to_field(param: &str) -> Fp {

0 commit comments

Comments
 (0)