Skip to content

Commit

Permalink
chore: use Noir implementation of pedersen that uses MSM instead of p…
Browse files Browse the repository at this point in the history
…edersen BBs
  • Loading branch information
dbanks12 authored and fcarreiro committed Sep 26, 2024
1 parent 5d4accf commit 3590265
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{hash::pedersen_hash, traits::ToField};
use crate::{hash::poseidon2_hash_with_separator, traits::ToField};

pub fn derive_storage_slot_in_map<K>(storage_slot: Field, key: K) -> Field where K: ToField {
pedersen_hash([storage_slot, key.to_field()], 0)
poseidon2_hash_with_separator([storage_slot, key.to_field()], 0)
}

mod test {
Expand Down
11 changes: 3 additions & 8 deletions noir/noir-repo/noir_stdlib/src/hash/mod.nr
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,11 @@ pub fn pedersen_commitment<let N: u32>(input: [Field; N]) -> EmbeddedCurvePoint
}

pub fn pedersen_hash_with_separator<let N: u32>(input: [Field; N], separator: u32) -> Field {
__pedersen_hash_with_separator(input, separator)
pedersen_hash_with_separator_noir(input, separator)
}

fn pedersen_commitment_with_separator<let N: u32>(input: [Field; N], separator: u32) -> EmbeddedCurvePoint {
let value = __pedersen_commitment_with_separator(input, separator);
if (value[0] == 0) & (value[1] == 0) {
EmbeddedCurvePoint { x: 0, y: 0, is_infinite: true }
} else {
EmbeddedCurvePoint { x: value[0], y: value[1], is_infinite: false }
}
pedersen_commitment_with_separator_noir(input, separator)
}

#[no_predicates]
Expand Down Expand Up @@ -78,7 +73,7 @@ fn pedersen_hash_with_separator_noir<let N: u32>(input: [Field; N], separator: u
pub fn pedersen_hash<let N: u32>(input: [Field; N]) -> Field
// docs:end:pedersen_hash
{
__pedersen_hash_with_separator(input, 0)
pedersen_hash_with_separator_noir(input, 0)
}

#[foreign(pedersen_hash)]
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/circuits.js/src/hash/map_slot.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { pedersenHash } from '@aztec/foundation/crypto';
import { poseidon2Hash } from '@aztec/foundation/crypto';
import { type Fr } from '@aztec/foundation/fields';

/**
Expand All @@ -14,5 +14,5 @@ export function deriveStorageSlotInMap(
toField: () => Fr;
},
): Fr {
return pedersenHash([mapSlot, key.toField()]);
return poseidon2Hash([mapSlot, key.toField()]);
}

0 comments on commit 3590265

Please sign in to comment.