Skip to content

Commit 7a2dd42

Browse files
authored
Validating that multi calls on the same state aligns vm and native. (#1604)
1 parent a127873 commit 7a2dd42

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

test_data/programs/starknet/syscalls.cairo

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,13 @@ fn sha256_process() -> [u32; 8] {
139139

140140
sha256_state_handle_digest(state).unbox()
141141
}
142+
143+
fn multi_sha256_flow() -> bool {
144+
let mut state1 = sha256_state_handle_init(BoxTrait::new(SHA256_INITIAL_STATE));
145+
let chunk = BoxTrait::new([0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xd, 0xe, 0xf, 0x10, 0x11]);
146+
147+
let state2 = starknet::syscalls::sha256_process_block_syscall(state1, chunk).unwrap_syscall();
148+
let state3 = starknet::syscalls::sha256_process_block_syscall(state1, chunk).unwrap_syscall();
149+
150+
sha256_state_handle_digest(state2).unbox() == sha256_state_handle_digest(state3).unbox()
151+
}

tests/tests/starknet/syscalls.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,3 +1419,34 @@ fn get_class_hash_at() {
14191419
},
14201420
);
14211421
}
1422+
1423+
#[test]
1424+
fn multi_sha256_flow() {
1425+
let program = load_program_and_runner("test_data_artifacts/programs/starknet/syscalls");
1426+
let result = run_native_program(
1427+
&program,
1428+
"multi_sha256_flow",
1429+
&[],
1430+
Some(u64::MAX),
1431+
Some(SyscallHandler::new()),
1432+
);
1433+
1434+
assert_eq_sorted!(
1435+
result.return_value,
1436+
Value::Enum {
1437+
tag: 0,
1438+
value: Box::new(Value::Struct {
1439+
fields: vec![Value::Enum {
1440+
tag: 1,
1441+
value: Box::new(Value::Struct {
1442+
fields: vec![],
1443+
debug_name: Some("Unit".to_string()),
1444+
}),
1445+
debug_name: Some("core::bool".to_string()),
1446+
}],
1447+
debug_name: None
1448+
}),
1449+
debug_name: None,
1450+
},
1451+
);
1452+
}

0 commit comments

Comments
 (0)