Skip to content
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

Fix communication channel for the hash digest between syscall and keccak #2278

Open
wants to merge 7 commits into
base: zkvm/syscalls/bytelength-lookups
Choose a base branch
from

Conversation

querolita
Copy link
Member

@querolita querolita commented May 31, 2024

While debugging SyscallReadPreimage I realized that the content of the RAM lookup on the MIPS side and the Keccak side for the hash digest (aka preimage key) was not aligned. Meaning, on the MIPS side the whole 256 bits were being taken into account for the vector lookup (32 bytes) whereas in the Keccak side it was ignoring the leading MSB (because it is meant to be substituted with a file descriptor at some point), so it was just computing the lookup with 31 bytes.

Because the preimage key bytes are stored in the registers in 8 columns of 4 bytes each, it was easier to unify the lookup so the 32 bytes are considered. Then, other parts of the system are in charge of "removing" the leading byte.

Not true, they were not being stored in the witness at all until now.

NOTE: this was not spotted before because we don't have tests for ram lookups yet, only fixed table lookups.

@querolita
Copy link
Member Author

querolita commented Jun 10, 2024

Looks like the oracle will read the 0x02 byte, so I need to adapt the communication channel to look only at the 31 bytes. This means I need to decompose the upper chunk of 4 bytes into 1 byte and 3 more bytes, and ignore the most significant one.

No need to decompose, as they were not being stored in the witness regardless. Instead, I am writing the key into the witness before calling Keccak.

@querolita querolita marked this pull request as draft June 10, 2024 16:36
@querolita querolita marked this pull request as ready for review June 12, 2024 10:30
@querolita
Copy link
Member Author

I just learnt that the preimage key chunks were not being stored at all in the witness columns (meaning REGISTER_PREIMAGE_KEY_START is not referring to scratch state columns). Thus, I am manually storing it inside request_preimage_write() before triggering Keccak, so that the communication channel matches on both sides.

@querolita
Copy link
Member Author

Checked demo, this does not halt the VM and the SyscallReadPreimage constraints hold.

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 this pull request may close these issues.

None yet

1 participant