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: change from u8 to u16 conversion to prevent key-value pairs length overflow #251

Merged
merged 5 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions packages/sp1-ics07-tendermint-prover/src/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ where
kv_proofs: Vec<(Vec<Vec<u8>>, Vec<u8>, MerkleProof)>,
) -> SP1ProofWithPublicValues {
assert!(!kv_proofs.is_empty(), "No key-value pairs to prove");
let len = u8::try_from(kv_proofs.len()).expect("too many key-value pairs");
let len = u16::try_from(kv_proofs.len()).expect("too many key-value pairs");

let mut stdin = SP1Stdin::new();
stdin.write_slice(commitment_root);
stdin.write_vec(vec![len]);
stdin.write_vec(len.to_le_bytes().to_vec());
srdtrk marked this conversation as resolved.
Show resolved Hide resolved
mmsqe marked this conversation as resolved.
Show resolved Hide resolved
for (path, value, proof) in kv_proofs {
stdin.write_vec(bincode::serialize(&path).unwrap());
stdin.write_vec(value);
Expand Down Expand Up @@ -172,7 +172,7 @@ where
kv_proofs: Vec<(Vec<Vec<u8>>, Vec<u8>, MerkleProof)>,
) -> SP1ProofWithPublicValues {
assert!(!kv_proofs.is_empty(), "No key-value pairs to prove");
let len = u8::try_from(kv_proofs.len()).expect("too many key-value pairs");
let len = u16::try_from(kv_proofs.len()).expect("too many key-value pairs");
// Encode the inputs into our program.
let encoded_1 = client_state.abi_encode();
let encoded_2 = trusted_consensus_state.abi_encode();
Expand All @@ -187,7 +187,7 @@ where
stdin.write_vec(encoded_2);
stdin.write_vec(encoded_3);
stdin.write_vec(encoded_4);
stdin.write_vec(vec![len]);
stdin.write_vec(len.to_le_bytes().to_vec());
srdtrk marked this conversation as resolved.
Show resolved Hide resolved
mmsqe marked this conversation as resolved.
Show resolved Hide resolved
for (path, value, proof) in kv_proofs {
stdin.write_vec(bincode::serialize(&path).unwrap());
stdin.write_vec(value);
Expand Down
Loading