Move byte-checks of Keccak to Syscall side and include lookups for length bytes #2276
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR aims at constraining the byte-ness of the length prefix read from the oracle in the first few bytes before reading the actual preimage bytes.
In order to simplify the Keccak lookups, I also moved the actual preimage byte-checks from the Keccak side to the MIPS side (this means 4 lookups per
SyscallReadPreimage
row instead of 200 lookups per absorb row).Together with the length bytes checks, this means 8 lookups derived from the
request_preimage_write()
function.I made this PR because I think it is good for soundness, but I am sure there's a better way to do it. In particular, it's absurd to perform 8 lookups when you know at most you read 4 bytes. We should think of a better way to "merge" length and preimage bytes in the same vector instead of having one for each.
I am unsure if the 8 bytes of the preimage are always read in two rows of 4 bytes each, or if instead it could combine things like: first call 3 bytes, second call 3 bytes, third call 2 bytes of length and 2 bytes of preimage. Of course, if it always read 4 and 4, then the length bytes and preimage bytes would never have to "share" the vector, as they would always live in separate rows. And then removing the extra 4 lookups is just trivial.Nonetheless, if that is not the case, we might want to think of smarter ways to combine the vector in a way that is compatible with the preimage chunk computation and the rest of preimage constraints.