Skip to content

Commit

Permalink
Merge badeb32 into 66244b6
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench authored Jul 9, 2024
2 parents 66244b6 + badeb32 commit b999507
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions noir_stdlib/src/hash/mod.nr
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub fn blake3<let N: u32>(input: [u8; N]) -> [u8; 32]
// docs:end:blake3
{}

#[no_predicates]
// docs:start:pedersen_commitment
pub fn pedersen_commitment<let N: u32>(input: [Field; N]) -> EmbeddedCurvePoint {
// docs:end:pedersen_commitment
Expand All @@ -46,6 +47,7 @@ fn pedersen_commitment_with_separator_noir<let N: u32>(input: [Field; N], separa
EmbeddedCurvePoint { x: values[0], y: values[1], is_infinite: values[2] as bool }
}

#[no_predicates]
pub fn pedersen_commitment_with_separator<let N: u32>(input: [Field; N], separator: u32) -> EmbeddedCurvePoint {
let values = __pedersen_commitment_with_separator(input, separator);
EmbeddedCurvePoint { x: values[0], y: values[1], is_infinite: false }
Expand Down
16 changes: 16 additions & 0 deletions noir_stdlib/src/hash/poseidon/bn254.nr
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub fn sponge<let N: u32>(msg: [Field; N]) -> Field {

// Various instances of the Poseidon hash function
// Consistent with Circom's implementation
#[no_predicates]
pub fn hash_1(input: [Field; 1]) -> Field {
let mut state = [0; 2];
for i in 0..input.len() {
Expand All @@ -21,6 +22,7 @@ pub fn hash_1(input: [Field; 1]) -> Field {
perm::x5_2(state)[0]
}

#[no_predicates]
pub fn hash_2(input: [Field; 2]) -> Field {
let mut state = [0; 3];
for i in 0..input.len() {
Expand All @@ -30,6 +32,7 @@ pub fn hash_2(input: [Field; 2]) -> Field {
perm::x5_3(state)[0]
}

#[no_predicates]
pub fn hash_3(input: [Field; 3]) -> Field {
let mut state = [0; 4];
for i in 0..input.len() {
Expand All @@ -39,6 +42,7 @@ pub fn hash_3(input: [Field; 3]) -> Field {
perm::x5_4(state)[0]
}

#[no_predicates]
pub fn hash_4(input: [Field; 4]) -> Field {
let mut state = [0; 5];
for i in 0..input.len() {
Expand All @@ -48,6 +52,7 @@ pub fn hash_4(input: [Field; 4]) -> Field {
perm::x5_5(state)[0]
}

#[no_predicates]
pub fn hash_5(input: [Field; 5]) -> Field {
let mut state = [0; 6];
for i in 0..input.len() {
Expand All @@ -57,6 +62,7 @@ pub fn hash_5(input: [Field; 5]) -> Field {
perm::x5_6(state)[0]
}

#[no_predicates]
pub fn hash_6(input: [Field; 6]) -> Field {
let mut state = [0; 7];
for i in 0..input.len() {
Expand All @@ -66,6 +72,7 @@ pub fn hash_6(input: [Field; 6]) -> Field {
perm::x5_7(state)[0]
}

#[no_predicates]
pub fn hash_7(input: [Field; 7]) -> Field {
let mut state = [0; 8];
for i in 0..input.len() {
Expand All @@ -75,6 +82,7 @@ pub fn hash_7(input: [Field; 7]) -> Field {
perm::x5_8(state)[0]
}

#[no_predicates]
pub fn hash_8(input: [Field; 8]) -> Field {
let mut state = [0; 9];
for i in 0..input.len() {
Expand All @@ -84,6 +92,7 @@ pub fn hash_8(input: [Field; 8]) -> Field {
perm::x5_9(state)[0]
}

#[no_predicates]
pub fn hash_9(input: [Field; 9]) -> Field {
let mut state = [0; 10];
for i in 0..input.len() {
Expand All @@ -93,6 +102,7 @@ pub fn hash_9(input: [Field; 9]) -> Field {
perm::x5_10(state)[0]
}

#[no_predicates]
pub fn hash_10(input: [Field; 10]) -> Field {
let mut state = [0; 11];
for i in 0..input.len() {
Expand All @@ -102,6 +112,7 @@ pub fn hash_10(input: [Field; 10]) -> Field {
perm::x5_11(state)[0]
}

#[no_predicates]
pub fn hash_11(input: [Field; 11]) -> Field {
let mut state = [0; 12];
for i in 0..input.len() {
Expand All @@ -111,6 +122,7 @@ pub fn hash_11(input: [Field; 11]) -> Field {
perm::x5_12(state)[0]
}

#[no_predicates]
pub fn hash_12(input: [Field; 12]) -> Field {
let mut state = [0; 13];
for i in 0..input.len() {
Expand All @@ -120,6 +132,7 @@ pub fn hash_12(input: [Field; 12]) -> Field {
perm::x5_13(state)[0]
}

#[no_predicates]
pub fn hash_13(input: [Field; 13]) -> Field {
let mut state = [0; 14];
for i in 0..input.len() {
Expand All @@ -129,6 +142,7 @@ pub fn hash_13(input: [Field; 13]) -> Field {
perm::x5_14(state)[0]
}

#[no_predicates]
pub fn hash_14(input: [Field; 14]) -> Field {
let mut state = [0; 15];
for i in 0..input.len() {
Expand All @@ -138,6 +152,7 @@ pub fn hash_14(input: [Field; 14]) -> Field {
perm::x5_15(state)[0]
}

#[no_predicates]
pub fn hash_15(input: [Field; 15]) -> Field {
let mut state = [0; 16];
for i in 0..input.len() {
Expand All @@ -147,6 +162,7 @@ pub fn hash_15(input: [Field; 15]) -> Field {
perm::x5_16(state)[0]
}

#[no_predicates]
pub fn hash_16(input: [Field; 16]) -> Field {
let mut state = [0; 17];
for i in 0..input.len() {
Expand Down
1 change: 1 addition & 0 deletions noir_stdlib/src/hash/poseidon2.nr
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ struct Poseidon2 {
}

impl Poseidon2 {
#[no_predicates]
pub fn hash<let N: u32>(input: [Field; N], message_size: u32) -> Field {
if message_size == N {
Poseidon2::hash_internal(input, N, false)
Expand Down
2 changes: 2 additions & 0 deletions noir_stdlib/src/sha256.nr
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ fn msg_u8_to_u32(msg: [u8; 64]) -> [u32; 16] {

msg32
}

// SHA-256 hash function
#[no_predicates]
pub fn digest<let N: u32>(msg: [u8; N]) -> [u8; 32] {
sha256_var(msg, N as u64)
}
Expand Down
2 changes: 2 additions & 0 deletions noir_stdlib/src/sha512.nr
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ fn sha_w(msg: [u64; 16]) -> [u64; 80] // Expanded message blocks
}
w
}

// SHA-512 compression function
#[no_predicates]
fn sha_c(msg: [u64; 16], hash: [u64; 8]) -> [u64; 8] {
// noir-fmt:ignore
let K: [u64; 80] = [4794697086780616226, 8158064640168781261, 13096744586834688815, 16840607885511220156, 4131703408338449720, 6480981068601479193, 10538285296894168987, 12329834152419229976, 15566598209576043074, 1334009975649890238, 2608012711638119052, 6128411473006802146, 8268148722764581231, 9286055187155687089, 11230858885718282805, 13951009754708518548, 16472876342353939154, 17275323862435702243, 1135362057144423861, 2597628984639134821, 3308224258029322869, 5365058923640841347, 6679025012923562964, 8573033837759648693, 10970295158949994411, 12119686244451234320, 12683024718118986047, 13788192230050041572, 14330467153632333762, 15395433587784984357, 489312712824947311, 1452737877330783856, 2861767655752347644, 3322285676063803686, 5560940570517711597, 5996557281743188959, 7280758554555802590, 8532644243296465576, 9350256976987008742, 10552545826968843579, 11727347734174303076, 12113106623233404929, 14000437183269869457, 14369950271660146224, 15101387698204529176, 15463397548674623760, 17586052441742319658, 1182934255886127544, 1847814050463011016, 2177327727835720531, 2830643537854262169, 3796741975233480872, 4115178125766777443, 5681478168544905931, 6601373596472566643, 7507060721942968483, 8399075790359081724, 8693463985226723168, 9568029438360202098, 10144078919501101548, 10430055236837252648, 11840083180663258601, 13761210420658862357, 14299343276471374635, 14566680578165727644, 15097957966210449927, 16922976911328602910, 17689382322260857208, 500013540394364858, 748580250866718886, 1242879168328830382, 1977374033974150939, 2944078676154940804, 3659926193048069267, 4368137639120453308, 4836135668995329356, 5532061633213252278, 6448918945643986474, 6902733635092675308, 7801388544844847127]; // first 64 bits of fractional parts of cube roots of first 80 primes
Expand Down

0 comments on commit b999507

Please sign in to comment.