-
Notifications
You must be signed in to change notification settings - Fork 9
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
feat: poseidon2
input pack (byte-input-padding-only)
#1352
Open
reshmem
wants to merge
90
commits into
main
Choose a base branch
from
roman/poseidon-input-pack
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains 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
poseidon2
input packposeidon2
input pack
# Conflicts: # circuits/src/poseidon2_sponge/columns.rs # circuits/src/stark/mozak_stark.rs # runner/src/poseidon2.rs
poseidon2
input packposeidon2
input pack (byte-input-padding-only)
# Conflicts: # circuits/src/stark/mozak_stark.rs
# Conflicts: # circuits/src/stark/mozak_stark.rs
value: value.preimage[i], | ||
..Default::default() | ||
// each Field element in preimage represents packed data (packed bytes) | ||
(0..Poseidon2Permutation::<F>::RATE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO(Matthias): this is all very suspicious.
Base automatically changed from
matthias/enable-poseidon-always-remove-feature
to
main
April 13, 2024 06:41
Basically, the bug allows applying sponge permutation on a given chunk of packed field elements in arbitrary order. That is, prover, instead of supplying given chunk c: [F; 8] in the intended order [c_1, c_2 ...c_8]` to Poseidon2Sponge, can instead supply it in any way he wants! Here is how: Say prover packs two field elements out of address region (0...14) with content [1, 2 ... 14] So corresponding packed values would be let packed_1 = Poseidon2PreimagePack<F> { pub clk: some_clk, pub byte_addr: 0, pub fe_addr: 0, pub bytes: [1, 2 ..7], // 2261738553347342 pub is_executed: 1, } let packed_2 = Poseidon2PreimagePack<F> { pub clk: some_clk, pub byte_addr: 8, pub fe_addr: 1, pub bytes: [8, 9, .. 14], // 283686952306183 pub is_executed: 1, } The idea is that there is no constraint tying byte_addr with fe_addr. That is, the malicious prover can flip the above fe_addrs by (packed_1.fe_addr, packed_2.fe_addr) = (packed_2.fe_addr, packed_1.fe_addr). It won't be detected anywhere! Hence when supplying the above to Poseidon2Sponge, he can emulate that he is supplying 283686952306183 before 2261738553347342. Simply because the former pack has fe_addr=0, and the latter pack has fe_addr=1 after modification. So instead of sponge permutation acting on [2261738553347342, 283686952306183...], it acts on [283686952306183, 2261738553347342...], hence leading to different output. In the former codebase, this can't happen because of CTL against Memory stark, which ensures that input to Poseidon2Sponge is coming in correct order (according to their addresses). But in the current implementation, there is no restriction, because fe_addr is not a real address as you pointed out! I think there is an easy way out though. We change the interpretation of input_addr in Poseidon2Sponge pub struct Poseidon2Sponge<T> { pub clk: T, pub ops: Ops<T>, pub input_addr: T, pub output_addr: T, pub input_len: T, pub preimage: [T; WIDTH], pub output: [T; WIDTH], pub gen_output: T, pub input_addr_padded: T, } Earlier this said "Hey, I am taking 8 bytes in region input_addr...input_addr+8, feeding it to current sponge preimage , apply sponge permutation, and I get output . I have also ordered the trace in increasing order of input_addr which you can check. Hence, you can be sure I am feeding it in correct order."
ed728a8
to
2c07fb9
Compare
Would recomment @codeblooded1729 to take a look. Although part of SDK, this was last touched (and mostly coded up by @codeblooded1729). Not many touch-points here for me! |
# Conflicts: # circuits/src/generation/mod.rs # circuits/src/stark/mozak_stark.rs # sdk/Cargo.toml
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.
poseidon2-preimage-pack
tomemory
poseidon2-sponge
toposeidon2-preimage-pack
+reduce_with_powers
to make 1 field element out of 7 bytesMe and @codeblooded1729 think that this implementation will be performant especially in case of data-input length more than 256 bytes.
For small input, like 32 bytes performance can be decreased .
Benchmarking shows 15-20% increase in performance overall. For very small input, the results are very noisy since
poseidon2
is part ofmozak-stark
and its run-time is less than other starks.