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

changed sha256 syscall selector #5392

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 corelib/src/sha256.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions corelib/src/starknet/syscalls.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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<u32>
) -> SyscallResult<core::sha256::SHA256StateHandle> implicits(GasBuiltin, System) nopanic;
state: core::sha256::Sha256StateHandle, input: Span<u32>
) -> SyscallResult<core::sha256::Sha256StateHandle> implicits(GasBuiltin, System) nopanic;
2 changes: 1 addition & 1 deletion crates/cairo-lang-runner/src/casm_run/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ pub fn core_libfunc_ap_change<InfoProvider: InvocationApChangeInfoProvider>(
| StarkNetConcreteLibfunc::GetExecutionInfoV2(_)
| StarkNetConcreteLibfunc::Deploy(_)
| StarkNetConcreteLibfunc::Keccak(_)
| StarkNetConcreteLibfunc::SHA256ProcessBlock(_)
| StarkNetConcreteLibfunc::Sha256ProcessBlock(_)
| StarkNetConcreteLibfunc::LibraryCall(_)
| StarkNetConcreteLibfunc::ReplaceClass(_)
| StarkNetConcreteLibfunc::SendMessageToL1(_)
Expand All @@ -321,8 +321,8 @@ pub fn core_libfunc_ap_change<InfoProvider: InvocationApChangeInfoProvider>(
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(_)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ pub fn starknet_libfunc_cost_base(libfunc: &StarkNetConcreteLibfunc) -> Vec<Cons
| StarkNetConcreteLibfunc::GetExecutionInfoV2(_) => 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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
Expand Down
2 changes: 1 addition & 1 deletion crates/cairo-lang-sierra-type-size/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(_)
Expand Down
12 changes: 6 additions & 6 deletions crates/cairo-lang-sierra/src/extensions/modules/starknet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -58,7 +58,7 @@ define_type_hierarchy! {
StorageAddress(StorageAddressType),
System(SystemType),
Secp256Point(Secp256PointType),
SHA256StateHandle(SHA256StateHandleType),
Sha256StateHandle(Sha256StateHandleType),
}, StarkNetTypeConcrete
}

Expand All @@ -85,9 +85,9 @@ define_libfunc_hierarchy! {
GetExecutionInfoV2(GetterLibfunc<GetExecutionInfoV2Trait>),
Deploy(DeployLibfunc),
Keccak(KeccakLibfunc),
SHA256ProcessBlock(SHA256ProcessBlockLibfunc),
SHA256StateHandleInit(SHA256StateHandleInitLibfunc),
SHA256StateHandleDigest(SHA256StateHandleDigestLibfunc),
Sha256ProcessBlock(Sha256ProcessBlockLibfunc),
Sha256StateHandleInit(Sha256StateHandleInitLibfunc),
Sha256StateHandleDigest(Sha256StateHandleDigestLibfunc),
LibraryCall(LibraryCallLibfunc),
ReplaceClass(ReplaceClassLibfunc),
SendMessageToL1(SendMessageToL1Libfunc),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,30 +163,30 @@ 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;
const ZERO_SIZED: bool = false;
}

/// 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(
context: &dyn SignatureSpecializationContext,
) -> Result<Vec<crate::ids::ConcreteTypeId>, 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)?,
])
Expand All @@ -195,14 +195,14 @@ impl SyscallGenericLibfunc for SHA256ProcessBlockLibfunc {
fn success_output_tys(
context: &dyn SignatureSpecializationContext,
) -> Result<Vec<crate::ids::ConcreteTypeId>, 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(
Expand All @@ -211,29 +211,29 @@ impl NoGenericArgsGenericLibfunc for SHA256StateHandleInitLibfunc {
) -> Result<LibfuncSignature, SpecializationError> {
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(
&self,
context: &dyn SignatureSpecializationContext,
) -> Result<LibfuncSignature, SpecializationError> {
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<ConcreteTypeId, SpecializationError> {
Expand Down
Loading