From cac1768b1d24601d30945b2192bfb15d36b63c3f Mon Sep 17 00:00:00 2001 From: TomerStarkware Date: Wed, 10 Apr 2024 13:22:38 +0300 Subject: [PATCH] changed sha256 syscall selector --- corelib/src/sha256.cairo | 6 ++-- corelib/src/starknet/syscalls.cairo | 4 +-- crates/cairo-lang-runner/src/casm_run/mod.rs | 2 +- .../src/core_libfunc_ap_change.rs | 6 ++-- .../src/starknet_libfunc_cost_base.rs | 6 ++-- .../src/invocations/starknet/mod.rs | 8 ++--- crates/cairo-lang-sierra-type-size/src/lib.rs | 2 +- .../src/extensions/modules/starknet/mod.rs | 12 ++++---- .../extensions/modules/starknet/syscalls.rs | 30 +++++++++---------- 9 files changed, 38 insertions(+), 38 deletions(-) diff --git a/corelib/src/sha256.cairo b/corelib/src/sha256.cairo index 768d3390ff1..e00ff045eb8 100644 --- a/corelib/src/sha256.cairo +++ b/corelib/src/sha256.cairo @@ -2,13 +2,13 @@ use core::starknet::SyscallResultTrait; /// A handle to the state of a SHA-256 hash. #[derive(Copy, Drop)] -pub(crate) extern type SHA256StateHandle; +pub(crate) extern type Sha256StateHandle; /// Initializes a new SHA-256 state handle. -extern fn sha256_state_handle_init(state: Box<[u32; 8]>) -> SHA256StateHandle nopanic; +extern fn sha256_state_handle_init(state: Box<[u32; 8]>) -> Sha256StateHandle nopanic; /// returns the state of a SHA-256 hash. -extern fn sha256_state_handle_digest(state: SHA256StateHandle) -> Box<[u32; 8]> nopanic; +extern fn sha256_state_handle_digest(state: Sha256StateHandle) -> Box<[u32; 8]> nopanic; const SHA256_INITIAL_STATE: [ u32 diff --git a/corelib/src/starknet/syscalls.cairo b/corelib/src/starknet/syscalls.cairo index f86fdbf196e..174af708e10 100644 --- a/corelib/src/starknet/syscalls.cairo +++ b/corelib/src/starknet/syscalls.cairo @@ -103,5 +103,5 @@ pub extern fn keccak_syscall( /// The system call does not add any padding and the input needs to be a multiple of 512 bits /// (== 16 u32 word). pub extern fn sha256_process_block_syscall( - state: core::sha256::SHA256StateHandle, input: Span -) -> SyscallResult implicits(GasBuiltin, System) nopanic; + state: core::sha256::Sha256StateHandle, input: Span +) -> SyscallResult implicits(GasBuiltin, System) nopanic; diff --git a/crates/cairo-lang-runner/src/casm_run/mod.rs b/crates/cairo-lang-runner/src/casm_run/mod.rs index bf6805bcbe2..17311f14c9a 100644 --- a/crates/cairo-lang-runner/src/casm_run/mod.rs +++ b/crates/cairo-lang-runner/src/casm_run/mod.rs @@ -697,7 +697,7 @@ impl<'a> CairoHintProcessor<'a> { "Keccak" => execute_handle_helper(&mut |system_buffer, gas_counter| { keccak(gas_counter, system_buffer.next_arr()?) }), - "SHA256ProcessBlock" => execute_handle_helper(&mut |system_buffer, gas_counter| { + "Sha256ProcessBlock" => execute_handle_helper(&mut |system_buffer, gas_counter| { sha_256_process_block( gas_counter, system_buffer.next_fixed_size_arr_pointer(8)?, diff --git a/crates/cairo-lang-sierra-ap-change/src/core_libfunc_ap_change.rs b/crates/cairo-lang-sierra-ap-change/src/core_libfunc_ap_change.rs index 29fe14b7794..de1fa6e0886 100644 --- a/crates/cairo-lang-sierra-ap-change/src/core_libfunc_ap_change.rs +++ b/crates/cairo-lang-sierra-ap-change/src/core_libfunc_ap_change.rs @@ -311,7 +311,7 @@ pub fn core_libfunc_ap_change( | StarkNetConcreteLibfunc::GetExecutionInfoV2(_) | StarkNetConcreteLibfunc::Deploy(_) | StarkNetConcreteLibfunc::Keccak(_) - | StarkNetConcreteLibfunc::SHA256ProcessBlock(_) + | StarkNetConcreteLibfunc::Sha256ProcessBlock(_) | StarkNetConcreteLibfunc::LibraryCall(_) | StarkNetConcreteLibfunc::ReplaceClass(_) | StarkNetConcreteLibfunc::SendMessageToL1(_) @@ -321,8 +321,8 @@ pub fn core_libfunc_ap_change( StarkNetConcreteLibfunc::Testing(libfunc) => match libfunc { TestingConcreteLibfunc::Cheatcode(_) => vec![ApChange::Known(2)], }, - StarkNetConcreteLibfunc::SHA256StateHandleInit(_) => vec![ApChange::Known(0)], - StarkNetConcreteLibfunc::SHA256StateHandleDigest(_) => vec![ApChange::Known(0)], + StarkNetConcreteLibfunc::Sha256StateHandleInit(_) => vec![ApChange::Known(0)], + StarkNetConcreteLibfunc::Sha256StateHandleDigest(_) => vec![ApChange::Known(0)], }, Nullable(libfunc) => match libfunc { NullableConcreteLibfunc::Null(_) diff --git a/crates/cairo-lang-sierra-gas/src/starknet_libfunc_cost_base.rs b/crates/cairo-lang-sierra-gas/src/starknet_libfunc_cost_base.rs index e54c9ea4459..36aacff3a24 100644 --- a/crates/cairo-lang-sierra-gas/src/starknet_libfunc_cost_base.rs +++ b/crates/cairo-lang-sierra-gas/src/starknet_libfunc_cost_base.rs @@ -45,9 +45,9 @@ pub fn starknet_libfunc_cost_base(libfunc: &StarkNetConcreteLibfunc) -> Vec syscall_cost(0), StarkNetConcreteLibfunc::Deploy(_) => syscall_cost(5), StarkNetConcreteLibfunc::Keccak(_) => syscall_cost(2), - StarkNetConcreteLibfunc::SHA256ProcessBlock(_) => syscall_cost(3), - StarkNetConcreteLibfunc::SHA256StateHandleInit(_) => vec![steps(0)], - StarkNetConcreteLibfunc::SHA256StateHandleDigest(_) => vec![steps(0)], + StarkNetConcreteLibfunc::Sha256ProcessBlock(_) => syscall_cost(3), + StarkNetConcreteLibfunc::Sha256StateHandleInit(_) => vec![steps(0)], + StarkNetConcreteLibfunc::Sha256StateHandleDigest(_) => vec![steps(0)], StarkNetConcreteLibfunc::LibraryCall(_) => syscall_cost(4), StarkNetConcreteLibfunc::ReplaceClass(_) => syscall_cost(1), StarkNetConcreteLibfunc::SendMessageToL1(_) => syscall_cost(3), diff --git a/crates/cairo-lang-sierra-to-casm/src/invocations/starknet/mod.rs b/crates/cairo-lang-sierra-to-casm/src/invocations/starknet/mod.rs index bf532a7e477..dedf7747e08 100644 --- a/crates/cairo-lang-sierra-to-casm/src/invocations/starknet/mod.rs +++ b/crates/cairo-lang-sierra-to-casm/src/invocations/starknet/mod.rs @@ -67,11 +67,11 @@ pub fn build( build_syscalls(builder, "Deploy", [1, 1, 2, 1], [1, 2]) } StarkNetConcreteLibfunc::Keccak(_) => build_syscalls(builder, "Keccak", [2], [2]), - StarkNetConcreteLibfunc::SHA256ProcessBlock(_) => { - build_syscalls(builder, "SHA256ProcessBlock", [1, 2], [1]) + StarkNetConcreteLibfunc::Sha256ProcessBlock(_) => { + build_syscalls(builder, "Sha256ProcessBlock", [1, 2], [1]) } - StarkNetConcreteLibfunc::SHA256StateHandleInit(_) => build_identity(builder), - StarkNetConcreteLibfunc::SHA256StateHandleDigest(_) => build_identity(builder), + StarkNetConcreteLibfunc::Sha256StateHandleInit(_) => build_identity(builder), + StarkNetConcreteLibfunc::Sha256StateHandleDigest(_) => build_identity(builder), StarkNetConcreteLibfunc::LibraryCall(_) => { build_syscalls(builder, "LibraryCall", [1, 1, 2], [2]) } diff --git a/crates/cairo-lang-sierra-type-size/src/lib.rs b/crates/cairo-lang-sierra-type-size/src/lib.rs index ea583b1860d..c7220b1a650 100644 --- a/crates/cairo-lang-sierra-type-size/src/lib.rs +++ b/crates/cairo-lang-sierra-type-size/src/lib.rs @@ -40,7 +40,7 @@ pub fn get_type_size_map( | CoreTypeConcrete::StarkNet(StarkNetTypeConcrete::ContractAddress(_)) | CoreTypeConcrete::StarkNet(StarkNetTypeConcrete::ClassHash(_)) | CoreTypeConcrete::StarkNet(StarkNetTypeConcrete::Secp256Point(_)) - | CoreTypeConcrete::StarkNet(StarkNetTypeConcrete::SHA256StateHandle(_)) + | CoreTypeConcrete::StarkNet(StarkNetTypeConcrete::Sha256StateHandle(_)) | CoreTypeConcrete::Pedersen(_) | CoreTypeConcrete::Poseidon(_) | CoreTypeConcrete::Felt252Dict(_) diff --git a/crates/cairo-lang-sierra/src/extensions/modules/starknet/mod.rs b/crates/cairo-lang-sierra/src/extensions/modules/starknet/mod.rs index d63f76f7ee8..913f0be93b7 100644 --- a/crates/cairo-lang-sierra/src/extensions/modules/starknet/mod.rs +++ b/crates/cairo-lang-sierra/src/extensions/modules/starknet/mod.rs @@ -39,8 +39,8 @@ use self::storage::{ StorageAddressTryFromFelt252Trait, StorageAddressType, StorageBaseAddressFromFelt252Libfunc, }; use self::syscalls::{ - KeccakLibfunc, SHA256ProcessBlockLibfunc, SHA256StateHandleDigestLibfunc, - SHA256StateHandleInitLibfunc, SHA256StateHandleType, + KeccakLibfunc, Sha256ProcessBlockLibfunc, Sha256StateHandleDigestLibfunc, + Sha256StateHandleInitLibfunc, Sha256StateHandleType, }; use self::testing::TestingLibfunc; use super::array::ArrayType; @@ -58,7 +58,7 @@ define_type_hierarchy! { StorageAddress(StorageAddressType), System(SystemType), Secp256Point(Secp256PointType), - SHA256StateHandle(SHA256StateHandleType), + Sha256StateHandle(Sha256StateHandleType), }, StarkNetTypeConcrete } @@ -85,9 +85,9 @@ define_libfunc_hierarchy! { GetExecutionInfoV2(GetterLibfunc), Deploy(DeployLibfunc), Keccak(KeccakLibfunc), - SHA256ProcessBlock(SHA256ProcessBlockLibfunc), - SHA256StateHandleInit(SHA256StateHandleInitLibfunc), - SHA256StateHandleDigest(SHA256StateHandleDigestLibfunc), + Sha256ProcessBlock(Sha256ProcessBlockLibfunc), + Sha256StateHandleInit(Sha256StateHandleInitLibfunc), + Sha256StateHandleDigest(Sha256StateHandleDigestLibfunc), LibraryCall(LibraryCallLibfunc), ReplaceClass(ReplaceClassLibfunc), SendMessageToL1(SendMessageToL1Libfunc), diff --git a/crates/cairo-lang-sierra/src/extensions/modules/starknet/syscalls.rs b/crates/cairo-lang-sierra/src/extensions/modules/starknet/syscalls.rs index c8110c00ec2..e62df05d512 100644 --- a/crates/cairo-lang-sierra/src/extensions/modules/starknet/syscalls.rs +++ b/crates/cairo-lang-sierra/src/extensions/modules/starknet/syscalls.rs @@ -163,10 +163,10 @@ impl SyscallGenericLibfunc for KeccakLibfunc { /// Type representing the sha256 state handle. #[derive(Default)] -pub struct SHA256StateHandleType {} +pub struct Sha256StateHandleType {} -impl NoGenericArgsGenericType for SHA256StateHandleType { - const ID: GenericTypeId = GenericTypeId::new_inline("SHA256StateHandle"); +impl NoGenericArgsGenericType for Sha256StateHandleType { + const ID: GenericTypeId = GenericTypeId::new_inline("Sha256StateHandle"); const STORABLE: bool = true; const DUPLICATABLE: bool = true; const DROPPABLE: bool = true; @@ -174,11 +174,11 @@ impl NoGenericArgsGenericType for SHA256StateHandleType { } /// Libfunc for the sha256_process_block system call. -/// The input needs a SHA256StateHandleType for the previous state and a span of 16 words +/// The input needs a Sha256StateHandleType for the previous state and a span of 16 words /// (each word is 32 bits). #[derive(Default)] -pub struct SHA256ProcessBlockLibfunc {} -impl SyscallGenericLibfunc for SHA256ProcessBlockLibfunc { +pub struct Sha256ProcessBlockLibfunc {} +impl SyscallGenericLibfunc for Sha256ProcessBlockLibfunc { const STR_ID: &'static str = "sha256_process_block_syscall"; fn input_tys( @@ -186,7 +186,7 @@ impl SyscallGenericLibfunc for SHA256ProcessBlockLibfunc { ) -> Result, SpecializationError> { Ok(vec![ // Previous state of the hash. - context.get_concrete_type(SHA256StateHandleType::id(), &[])?, + context.get_concrete_type(Sha256StateHandleType::id(), &[])?, // The current block to process. u32_span_ty(context)?, ]) @@ -195,14 +195,14 @@ impl SyscallGenericLibfunc for SHA256ProcessBlockLibfunc { fn success_output_tys( context: &dyn SignatureSpecializationContext, ) -> Result, SpecializationError> { - Ok(vec![context.get_concrete_type(SHA256StateHandleType::id(), &[])?]) + Ok(vec![context.get_concrete_type(Sha256StateHandleType::id(), &[])?]) } } /// Libfunc for converting a ContractAddress into a felt252. #[derive(Default)] -pub struct SHA256StateHandleInitLibfunc {} -impl NoGenericArgsGenericLibfunc for SHA256StateHandleInitLibfunc { +pub struct Sha256StateHandleInitLibfunc {} +impl NoGenericArgsGenericLibfunc for Sha256StateHandleInitLibfunc { const STR_ID: &'static str = "sha256_state_handle_init"; fn specialize_signature( @@ -211,15 +211,15 @@ impl NoGenericArgsGenericLibfunc for SHA256StateHandleInitLibfunc { ) -> Result { Ok(reinterpret_cast_signature( sha256_state_handle_unwrapped_type(context)?, - context.get_concrete_type(SHA256StateHandleType::id(), &[])?, + context.get_concrete_type(Sha256StateHandleType::id(), &[])?, )) } } /// Libfunc for converting a ContractAddress into a felt252. #[derive(Default)] -pub struct SHA256StateHandleDigestLibfunc {} -impl NoGenericArgsGenericLibfunc for SHA256StateHandleDigestLibfunc { +pub struct Sha256StateHandleDigestLibfunc {} +impl NoGenericArgsGenericLibfunc for Sha256StateHandleDigestLibfunc { const STR_ID: &'static str = "sha256_state_handle_digest"; fn specialize_signature( @@ -227,13 +227,13 @@ impl NoGenericArgsGenericLibfunc for SHA256StateHandleDigestLibfunc { context: &dyn SignatureSpecializationContext, ) -> Result { Ok(reinterpret_cast_signature( - context.get_concrete_type(SHA256StateHandleType::id(), &[])?, + context.get_concrete_type(Sha256StateHandleType::id(), &[])?, sha256_state_handle_unwrapped_type(context)?, )) } } -/// The inner type of the SHA256StateHandle. +/// The inner type of the Sha256StateHandle. pub fn sha256_state_handle_unwrapped_type( context: &dyn SignatureSpecializationContext, ) -> Result {