blockifier: sha512 syscall#14072
Conversation
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
|
Artifacts upload workflows: |
b11ea68 to
f15fa30
Compare
f15fa30 to
6249aad
Compare
6249aad to
be74220
Compare
PR SummaryHigh Risk Overview OS / proving: Tests & tooling: Contract Reviewed by Cursor Bugbot for commit 7dd2592. Bugbot is set up for automated code reviews on this repo. Configure here. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit be74220. Configure here.
6ba9319 to
f293605
Compare
be74220 to
ad0c4b6
Compare
Yoni-Starkware
left a comment
There was a problem hiding this comment.
@Yoni-Starkware reviewed 19 files and all commit messages, and made 1 comment.
Reviewable status: 19 of 65 files reviewed, 1 unresolved discussion (waiting on dorimedini-starkware and liorgold2).
crates/blockifier/resources/blockifier_versioned_constants_0_14_3.json line 477 at r3 (raw file):
"bitwise_builtin": 2230 } },
Not consistent with your slack message
Code quote:
"Sha256ProcessBlock": {
"n_steps": 1867,
"n_memory_holes": 0,
"builtin_instance_counter": {
"range_check_builtin": 65,
"bitwise_builtin": 1115
}
},
"Sha512ProcessBlock": {
"n_steps": 3734,
"n_memory_holes": 0,
"builtin_instance_counter": {
"range_check_builtin": 130,
"bitwise_builtin": 2230
}
},
Yoni-Starkware
left a comment
There was a problem hiding this comment.
Can you please add sha512 call in here? (virtual os e2e test)
@Yoni-Starkware reviewed 7 files and made 1 comment.
Reviewable status: 26 of 65 files reviewed, 1 unresolved discussion (waiting on dorimedini-starkware and liorgold2).
Yoni-Starkware
left a comment
There was a problem hiding this comment.
You should add SHA512_PROCESS_BLOCK_GAS_COST to constants_test.rs
@Yoni-Starkware reviewed 1 file and made 1 comment.
Reviewable status: 27 of 65 files reviewed, 1 unresolved discussion (waiting on dorimedini-starkware and liorgold2).
Yoni-Starkware
left a comment
There was a problem hiding this comment.
@Yoni-Starkware made 3 comments.
Reviewable status: 27 of 65 files reviewed, 4 unresolved discussions (waiting on dorimedini-starkware and liorgold2).
crates/starknet_os/src/hints/hint_implementation/execute_transactions/implementation.rs line 67 at r3 (raw file):
} pub(crate) fn sha2_finalize(ctx: HintContext<'_>) -> OsHintResult {
(why not 256? nonblocking)
Code quote:
sha2_finalize(crates/starknet_os/src/hints/hint_implementation/execute_transactions/implementation.rs line 68 at r3 (raw file):
pub(crate) fn sha2_finalize(ctx: HintContext<'_>) -> OsHintResult { let batch_size = &ctx.fetch_const(Const::ShaBatchSize)?.to_bigint();
Add a TODO to rename to Sha256BatchSize
Code quote:
ShaBatchSizecrates/starknet_os/src/hints/hint_implementation/execute_transactions/implementation.rs line 113 at r3 (raw file):
let padding = calculate_sha512_padding(sha512_input_chunk_size_felts, number_of_missing_blocks); let sha512_ptr_end = ctx.get_ptr(Ids::Sha512PtrEnd)?; ctx.vm.load_data(sha512_ptr_end, &padding)?;
Please share this code with sha256
Code quote:
let batch_size = &ctx.fetch_const(Const::Sha512BatchSize)?.to_bigint();
let n = &ctx.get_integer(Ids::N)?.to_bigint();
let number_of_missing_blocks = ((((-n) % batch_size) + batch_size) % batch_size)
.to_u32()
.expect("Failed to convert number of missing blocks to u32.");
assert!(
(0..N_MISSING_BLOCKS_BOUND).contains(&number_of_missing_blocks),
"number_of_missing_blocks: {number_of_missing_blocks} is expected to be in the range [0, \
{N_MISSING_BLOCKS_BOUND}). Got n: {n} and batch size: {batch_size}."
);
let sha512_input_chunk_size_felts =
felt_to_usize(ctx.fetch_const(Const::Sha512InputChunkSize)?)?;
assert!(
(0..SHA256_INPUT_CHUNK_SIZE_BOUND).contains(&sha512_input_chunk_size_felts),
"sha512_input_chunk_size_felts: {sha512_input_chunk_size_felts} is expected to be in the \
range [0, {SHA256_INPUT_CHUNK_SIZE_BOUND})."
);
let padding = calculate_sha512_padding(sha512_input_chunk_size_felts, number_of_missing_blocks);
let sha512_ptr_end = ctx.get_ptr(Ids::Sha512PtrEnd)?;
ctx.vm.load_data(sha512_ptr_end, &padding)?;
Yoni-Starkware
left a comment
There was a problem hiding this comment.
@Yoni-Starkware made 1 comment.
Reviewable status: 27 of 65 files reviewed, 5 unresolved discussions (waiting on dorimedini-starkware and liorgold2).
crates/starknet_os/src/hints/hint_implementation/execute_transactions/implementation.rs line 107 at r3 (raw file):
felt_to_usize(ctx.fetch_const(Const::Sha512InputChunkSize)?)?; assert!( (0..SHA256_INPUT_CHUNK_SIZE_BOUND).contains(&sha512_input_chunk_size_felts),
Should be the same? if so, please add an alias so it would be clear
Suggestion:
SHA512_INPUT_CHUNK_SIZE_BOUND
Yoni-Starkware
left a comment
There was a problem hiding this comment.
@Yoni-Starkware made 1 comment.
Reviewable status: 27 of 65 files reviewed, 6 unresolved discussions (waiting on dorimedini-starkware and liorgold2).
crates/starknet_os/src/hints/hint_implementation/execute_syscalls.rs line 65 at r3 (raw file):
ctx.vm.add_relocation_rule(state_ptr, actual_out_state_ptr.into())?; Ok(()) }
Please share this code
Code quote:
pub(crate) fn relocate_sha512_segment<S: StateReader>(
_hint_processor: &mut SnosHintProcessor<'_, S>,
ctx: HintContext<'_>,
) -> OsHintResult {
let state_ptr = ctx.get_nested_field_ptr(
Ids::Response,
CairoStruct::Sha512ProcessBlockResponsePtr,
&["state_ptr"],
)?;
let actual_out_state_ptr = ctx.get_ptr(Ids::ActualOutState)?;
// TODO(Nimrod): Use SHA256_STATE_SIZE_FELTS constant.
let sha_state_size = 8;
let data = ctx.vm.get_continuous_range(state_ptr, sha_state_size)?;
ctx.vm.load_data(actual_out_state_ptr, &data)?;
ctx.vm.add_relocation_rule(state_ptr, actual_out_state_ptr.into())?;
Ok(())
}
Yoni-Starkware
left a comment
There was a problem hiding this comment.
@Yoni-Starkware made 2 comments.
Reviewable status: 27 of 65 files reviewed, 8 unresolved discussions (waiting on dorimedini-starkware and liorgold2).
crates/starknet_os/src/hints/hint_implementation/execute_transactions/utils.rs line 24 at r3 (raw file):
]; pub(crate) fn calculate_padding(
Suggestion:
calculate_sha256_padding(crates/starknet_os/src/hints/hint_implementation/execute_transactions/utils.rs line 68 at r3 (raw file):
} padding }
Please share, at least parts of it
Code quote:
pub(crate) fn calculate_sha512_padding(
sha512_input_chunk_size_felts: usize,
number_of_missing_blocks: u32,
) -> Vec<MaybeRelocatable> {
let message = vec![0_u64; sha512_input_chunk_size_felts];
let flat_message = sha2::digest::generic_array::GenericArray::from_exact_iter(
message.iter().flat_map(|v| v.to_be_bytes()),
)
.expect("Failed to create a dummy message for sha512_finalize.");
let mut state = SHA512_IV;
sha2::compress512(&mut state, &[flat_message]);
let padding_to_repeat: Vec<u64> =
[message, SHA512_IV.to_vec(), state.to_vec()].into_iter().flatten().collect();
let mut padding = vec![];
let padding_extension =
padding_to_repeat.iter().map(|x| MaybeRelocatable::from(Felt::from(*x)));
for _ in 0..number_of_missing_blocks {
padding.extend(padding_extension.clone());
}
padding
}
Yoni-Starkware
left a comment
There was a problem hiding this comment.
@Yoni-Starkware reviewed 6 files and made 1 comment.
Reviewable status: 33 of 65 files reviewed, 9 unresolved discussions (waiting on dorimedini-starkware and liorgold2).
crates/starknet_os/src/hint_processor/snos_syscall_executor.rs line 385 at r3 (raw file):
vm.load_data(temp_segment, state)?; Ok(temp_segment) }
Identical to the above, please share the code or rename the first func
Code quote:
fn write_sha512_out_state(
&mut self,
state: &[MaybeRelocatable],
vm: &mut VirtualMachine,
) -> Result<Relocatable, Self::Error> {
let temp_segment = vm.add_temporary_segment();
vm.load_data(temp_segment, state)?;
Ok(temp_segment)
}e063dae to
04f14e3
Compare
f293605 to
e583f90
Compare
dorimedini-starkware
left a comment
There was a problem hiding this comment.
@dorimedini-starkware made 6 comments.
Reviewable status: 30 of 68 files reviewed, 9 unresolved discussions (waiting on liorgold2 and Yoni-Starkware).
crates/blockifier/resources/blockifier_versioned_constants_0_14_3.json line 477 at r3 (raw file):
Previously, Yoni-Starkware (Yoni) wrote…
Not consistent with your slack message
Done.
crates/starknet_os/src/hint_processor/snos_syscall_executor.rs line 385 at r3 (raw file):
Previously, Yoni-Starkware (Yoni) wrote…
Identical to the above, please share the code or rename the first func
Done.
crates/starknet_os/src/hints/hint_implementation/execute_syscalls.rs line 65 at r3 (raw file):
Previously, Yoni-Starkware (Yoni) wrote…
Please share this code
Done.
crates/starknet_os/src/hints/hint_implementation/execute_transactions/implementation.rs line 107 at r3 (raw file):
Previously, Yoni-Starkware (Yoni) wrote…
Should be the same? if so, please add an alias so it would be clear
it's hard-coded as 100 in both cases, so just added another named constant.
crates/starknet_os/src/hints/hint_implementation/execute_transactions/implementation.rs line 113 at r3 (raw file):
Previously, Yoni-Starkware (Yoni) wrote…
Please share this code with sha256
Done.
crates/starknet_os/src/hints/hint_implementation/execute_transactions/utils.rs line 68 at r3 (raw file):
Previously, Yoni-Starkware (Yoni) wrote…
Please share, at least parts of it
Done.
ea057fb to
3029639
Compare
dorimedini-starkware
left a comment
There was a problem hiding this comment.
@dorimedini-starkware made 3 comments and resolved 3 discussions.
Reviewable status: 30 of 68 files reviewed, 6 unresolved discussions (waiting on liorgold2 and Yoni-Starkware).
crates/starknet_os/src/hints/hint_implementation/execute_transactions/implementation.rs line 67 at r3 (raw file):
Previously, Yoni-Starkware (Yoni) wrote…
(why not 256? nonblocking)
done, next PR in stack
crates/starknet_os/src/hints/hint_implementation/execute_transactions/implementation.rs line 68 at r3 (raw file):
Previously, Yoni-Starkware (Yoni) wrote…
Add a TODO to rename to Sha256BatchSize
done, next PR in stack
crates/starknet_os/src/hints/hint_implementation/execute_transactions/utils.rs line 24 at r3 (raw file):
]; pub(crate) fn calculate_padding(
done, next PR in stack
3029639 to
0094ede
Compare
dorimedini-starkware
left a comment
There was a problem hiding this comment.
done, and here already
@dorimedini-starkware made 1 comment.
Reviewable status: 30 of 69 files reviewed, 6 unresolved discussions (waiting on liorgold2 and Yoni-Starkware).
d198e92 to
d16a453
Compare
e583f90 to
085f6c6
Compare
d16a453 to
014f2e5
Compare
Yoni-Starkware
left a comment
There was a problem hiding this comment.
@Yoni-Starkware reviewed 18 files and all commit messages, made 1 comment, and resolved 6 discussions.
Reviewable status: 48 of 72 files reviewed, 1 unresolved discussion (waiting on dorimedini-starkware and liorgold2).
crates/blockifier_test_utils/resources/feature_contracts/cairo1/test_contract.cairo line 684 at r6 (raw file):
#[external(v0)] fn test_sha512(ref self: ContractState) {
Add a case with a non-trivial array
014f2e5 to
bea1354
Compare
dorimedini-starkware
left a comment
There was a problem hiding this comment.
@dorimedini-starkware resolved 1 discussion.
Reviewable status: 48 of 72 files reviewed, all discussions resolved (waiting on liorgold2).
bea1354 to
8936907
Compare
Yoni-Starkware
left a comment
There was a problem hiding this comment.
@Yoni-Starkware reviewed 7 files and all commit messages, and made 2 comments.
Reviewable status: 53 of 72 files reviewed, 1 unresolved discussion (waiting on dorimedini-starkware and liorgold2).
crates/blockifier/src/execution/syscalls/vm_syscall_utils.rs line 570 at r6 (raw file):
Ok(()) } }
Duplication of the above. You can just rename Sha256 -> SharedSha and delete this one
nonblocking
Code quote:
// Sha512ProcessBlock syscall.
#[derive(Debug, Eq, PartialEq)]
pub struct Sha512ProcessBlockRequest {
pub state_ptr: Relocatable,
pub input_start: Relocatable,
}
impl SyscallRequest for Sha512ProcessBlockRequest {
fn read(
vm: &VirtualMachine,
ptr: &mut Relocatable,
) -> SyscallBaseResult<Sha512ProcessBlockRequest> {
let state_start = vm.get_relocatable(*ptr)?;
*ptr = (*ptr + 1)?;
let input_start = vm.get_relocatable(*ptr)?;
*ptr = (*ptr + 1)?;
Ok(Sha512ProcessBlockRequest { state_ptr: state_start, input_start })
}
}
#[derive(Debug, Eq, PartialEq)]
pub struct Sha512ProcessBlockResponse {
pub state_ptr: Relocatable,
}
impl SyscallResponse for Sha512ProcessBlockResponse {
fn write(self, vm: &mut VirtualMachine, ptr: &mut Relocatable) -> WriteResponseResult {
write_maybe_relocatable(vm, ptr, self.state_ptr)?;
Ok(())
}
}8936907 to
d2c4983
Compare
dorimedini-starkware
left a comment
There was a problem hiding this comment.
@dorimedini-starkware made 1 comment and resolved 1 discussion.
Reviewable status: 52 of 72 files reviewed, all discussions resolved (waiting on liorgold2 and Yoni-Starkware).
crates/blockifier/src/execution/syscalls/vm_syscall_utils.rs line 570 at r6 (raw file):
Previously, Yoni-Starkware (Yoni) wrote…
Duplication of the above. You can just rename Sha256 -> SharedSha and delete this one
nonblocking
done in top PR
d2c4983 to
3b71060
Compare
Yoni-Starkware
left a comment
There was a problem hiding this comment.
@Yoni-Starkware reviewed 4 files and all commit messages.
Reviewable status: 54 of 73 files reviewed, all discussions resolved (waiting on liorgold2).
3b71060 to
94e61a4
Compare
Yoni-Starkware
left a comment
There was a problem hiding this comment.
@Yoni-Starkware reviewed 1 file.
Reviewable status: 55 of 74 files reviewed, all discussions resolved (waiting on liorgold2).
94e61a4 to
7dd2592
Compare
Yoni-Starkware
left a comment
There was a problem hiding this comment.
@Yoni-Starkware reviewed 1 file and all commit messages.
Reviewable status: 56 of 75 files reviewed, all discussions resolved (waiting on liorgold2).
Yoni-Starkware
left a comment
There was a problem hiding this comment.
@Yoni-Starkware made 1 comment.
Reviewable status: 56 of 75 files reviewed, all discussions resolved (waiting on liorgold2).
dorimedini-starkware
left a comment
There was a problem hiding this comment.
@dorimedini-starkware reviewed 56 files and all commit messages.
Reviewable status: 56 of 75 files reviewed, all discussions resolved (waiting on liorgold2).
dorimedini-starkware
left a comment
There was a problem hiding this comment.
@dorimedini-starkware partially reviewed 25 files.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on liorgold2).


No description provided.