fix minor poseidon error (hash is now truncation of the addition of the state elements) instead of the addition of the entire state

This commit is contained in:
thomaslavaur 2024-09-11 10:50:21 +02:00
parent e6165cd064
commit 4af413b3ac
4 changed files with 6 additions and 27 deletions

View File

@ -467,22 +467,7 @@ template hash_16_to_1(){
perm.in[i] <== in[i];
}
out <== in[0] + perm.out[0] +
in[1] + perm.out[1] +
in[2] + perm.out[2] +
in[3] + perm.out[3] +
in[4] + perm.out[4] +
in[5] + perm.out[5] +
in[6] + perm.out[6] +
in[7] + perm.out[7] +
in[8] + perm.out[8] +
in[9] + perm.out[9] +
in[10] + perm.out[10] +
in[11] + perm.out[11] +
in[12] + perm.out[12] +
in[13] + perm.out[13] +
in[14] + perm.out[14] +
in[15] + perm.out[15];
out <== in[0] + perm.out[0];
}
//component main = hash_16_to_1();

View File

@ -141,7 +141,7 @@ template hash_2_to_1(){
perm.in[0] <== in[0];
perm.in[1] <== in[1];
out <== in[0] + perm.out[0] + in[1] + perm.out[1];
out <== in[0] + perm.out[0];
}
//component main = hash_2_to_1();

View File

@ -182,7 +182,7 @@ template hash_4_to_1(){
perm.in[2] <== in[2];
perm.in[3] <== in[3];
out <== in[0] + perm.out[0] + in[1] + perm.out[1] + in[2] + perm.out[2] + in[3] + perm.out[3];
out <== in[0] + perm.out[0];
}
//component main = hash_4_to_1();

View File

@ -450,7 +450,7 @@ def poseidon(state):
state[j] += cst[64 + i*2 + j]
state[j] = state[j]**5
state = poseidon_linear_layer_2_to_1(state)
return state[0] + state[1] + original_state[0] + original_state[1]
return state[0] + original_state[0]
if len(state) == 4:
original_state = state
cst = poseidon_round_constant_4_to_1()
@ -469,10 +469,7 @@ def poseidon(state):
state[j] += cst[72 + i*4 + j]
state[j] = state[j]**5
state = poseidon_external_linear_layer_4_to_1(state)
h = F(0)
for i in range(4):
h += state[i] + original_state[i]
return h
return state[0] + original_state[0]
if len(state) == 16:
original_state = state
cst = poseidon_round_constant_16_to_1()
@ -491,10 +488,7 @@ def poseidon(state):
state[j] += cst[121 + i*16 + j]
state[j] = state[j]**5
state = poseidon_external_linear_layer_16_to_1(state)
h = F(0)
for i in range(16):
h += state[i] + original_state[i]
return h
return state[0] + original_state[0]
def poseidon_linear_layer_2_to_1(state):
M = Matrix(F,[[2,1],[1,2]])