8000 keccak-air `generate_trace_rows_for_perm` uses a non-standard `state` · Issue #672 · Plonky3/Plonky3 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

keccak-air generate_trace_rows_for_perm uses a non-standard state #672

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jonathanpwang opened this issue Feb 17, 2025 · 4 comments
Open

Comments

@jonathanpwang
Copy link
Contributor

let mut current_state: [[u64; 5]; 5] = unsafe { transmute(input) };

array::from_fn(|y| array::from_fn(|x| u64_to_16_bit_limbs(current_state[x][y])));

After #621, the generate_trace_rows_for_perm now takes state: [u64;25] and considers it as a [x][y] 5x5 matrix where index = x * 5 + y. You then set preimage[y][x] = state[x][y], so that preimage[y][x] = state[x * 5 + y]. However in the official keccak spec (https://keccak.team/keccak_specs_summary.html), the absorb is done using state[x + 5 * y].

This does not change the correctness of the keccak-f AIR, since you are still permuting a state correctly, but it does affect the overall API and compatibility with usage of this AIR in any implementation of the full keccak hash function. (I discovered this in trying to update OpenVM's keccak256 AIR to the new commit.)

I have checked and believe that tiny-keccak's keccakf(state: [u64;25]) function does take the indexing via state[x + 5 * y]. I suggest that the generate_trace_rows_for_perm API is changed to match tiny-keccak: the fix is simple, just change the ordering in L53.

Moreover from this I noticed that there are no unit tests of the keccak-air on the trace generation's outputs against either known test vectors or against a known implementation such as tiny-keccak. I would suggest adding such unit tests so these issues are caught more easily (and also to show the expected API).

@SyxtonPrime
Copy link
Contributor

Hmm, happy to try and fix this (And I agree adding some unit tests would be good).

Would it be enough to just add a transpose to current_state after the transmute?

@jonathanpwang
Copy link
Contributor Author

I believe all you need to do is change in

array::from_fn(|y| array::from_fn(|x| u64_to_16_bit_limbs(current_state[x][y])));
the current_state[x][y] to current_state[y][x].

I can make the change, but I wouldn't be able to immediately have time to add the code for unit tests.

@0xKarl98
Copy link
0xKarl98 commented Apr 9, 2025

Hi , i've just saw this issue and have checked this line :

array::from_fn(|y| array::from_fn(|x| u64_to_16_bit_limbs(current_state[x][y]))); 

it remains the same until now , can i try to implement the unit test for this ?

@SyxtonPrime
Copy link
Contributor

Sure that would be great.

The main thing to ensure is that proving times for the KECCAK examples don't change.

E.g. running:
RUSTFLAGS="-Ctarget-cpu=native" cargo run --example prove_prime_field_31 --release --features parallel -- --field koala-bear --objective keccak-f-permutations --log-trace-length 14 --discrete-fourier-transform radix-2-dit-parallel --merkle-hash keccak-f

Should successfully run the prover/verifier and take roughly the same amount of time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants
0