Repository navigation
fix(zkvm): halt with invalid hint when read_vec length rounding overflows - #3012
Closed
MatusKysel wants to merge 1 commit into
Closed
MatusKysel wants to merge 1 commit into
MatusKysel wants to merge 1 commit into
Conversation
…lows read_vec_raw rounded the prover-supplied HINT_LEN up to a multiple of 8 with unchecked arithmetic. A length in [usize::MAX - 6, usize::MAX - 1] wrapped the capacity to 0, so the input pointer was not advanced and read_vec/read built a Vec with len > capacity via Vec::from_raw_parts. Use checked rounding and halt with exit code 3 (invalid hint) when it overflows. No real input can be that long, so honest executions are unaffected.
Contributor
Author
|
Superseded by d3d90aa (feat: improve zkvm allocators), which makes the rounding checked and asserts |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Motivation
read_vec_rawrounds the prover-suppliedHINT_LENup to a multiple of 8 with(len + 7) / 8 * 8. A length in[usize::MAX - 6, usize::MAX - 1]wraps the capacity to 0, so the input pointer isn't advanced andread_vecbuilds aVecwithlen > capacity. The honest executor can't produce such a length, butHINT_LENis only range-checked, so a malicious prover can.Solution
Use
checked_next_multiple_of(8)and halt with exit code 3 (invalid hint) on overflow. Every other length rounds as before.Checked with an executor patched to return
usize::MAX - 6: exit 0 with the forgedlen/capacitybefore, exit 3 after. There's no automated test because the executor can't forgeHINT_LEN.PR Checklist