Skip to content

Commit

Permalink
Fix hash computation when calldata are split into several APDUs
Browse files Browse the repository at this point in the history
  • Loading branch information
yogh333 committed Jan 27, 2025
1 parent 41fc273 commit 532b0fe
Show file tree
Hide file tree
Showing 19 changed files with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions starknet/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ pub enum SetCallError {
TooManyCalls = 0xFF01,
}

#[derive(PartialEq)]
pub enum SetCallStep {
New = 0x00,
Add = 0x01,
Expand Down Expand Up @@ -322,26 +323,28 @@ fn set_calldata_invoke(
}
let mut call = Call::default();
let mut iter = data.chunks(FIELD_ELEMENT_SIZE);

call.to = iter.next().unwrap().into();
hasher.update(call.to);
call.selector = iter.next().unwrap().into();
hasher.update(call.selector);
hasher.update(FieldElement::from(iter.len() as u8));
for d in iter {
call.calldata.push(d.into());
hasher.update(d.into());
}
calls.push(call);
Ok(())
}
SetCallStep::Add | SetCallStep::End => {
let idx = calls.len() - 1;
let call = calls.get_mut(idx).unwrap();
let call: &mut Call = calls.get_mut(idx).unwrap();
let iter = data.chunks(FIELD_ELEMENT_SIZE);
for d in iter {
call.calldata.push(d.into());
hasher.update(d.into());
}
if p2 == SetCallStep::End {
hasher.update(call.to);
hasher.update(call.selector);
hasher.update(FieldElement::from(call.calldata.len() as u8));
for d in &call.calldata {
hasher.update(*d);
}
}
Ok(())
}
Expand Down
Binary file modified tests/snapshots/flex/test_blind_sign_tx_1/00002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/flex/test_blind_sign_tx_2/00002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/flex/test_blind_sign_tx_3/00002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/nanosp/test_blind_sign_tx_1/00002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/nanosp/test_blind_sign_tx_1/00003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/nanosp/test_blind_sign_tx_2/00002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/nanosp/test_blind_sign_tx_2/00003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/nanosp/test_blind_sign_tx_3/00002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/nanosp/test_blind_sign_tx_3/00003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/nanox/test_blind_sign_tx_1/00002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/nanox/test_blind_sign_tx_1/00003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/nanox/test_blind_sign_tx_2/00002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/nanox/test_blind_sign_tx_2/00003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/nanox/test_blind_sign_tx_3/00002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/nanox/test_blind_sign_tx_3/00003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/stax/test_blind_sign_tx_1/00002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/stax/test_blind_sign_tx_2/00002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/stax/test_blind_sign_tx_3/00002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 532b0fe

Please sign in to comment.