Skip to content

Commit

Permalink
Fix native commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoni-Starkware authored and Yonatan-Starkware committed Nov 24, 2024
1 parent 3815c0b commit 7497521
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 49 deletions.
2 changes: 1 addition & 1 deletion crates/blockifier/cairo_native
Submodule cairo_native updated 90 files
+19 −0 .github/ISSUE_TEMPLATE/daily_failure.md
+36 −0 .github/actions/install-linux-deps/action.yml
+6 −10 .github/workflows/bench-hyperfine.yml
+234 −0 .github/workflows/daily.yml
+150 −0 .github/workflows/starknet-blocks.yml
+138 −169 Cargo.lock
+19 −18 Cargo.toml
+3 −2 Makefile
+24 −88 benches/benches.rs
+17 −0 benches/compile_time.rs
+57 −6 benches/libfuncs.rs
+1 −2 docs/gas_builtin_accounting.md
+41 −27 docs/overview.md
+15 −1 docs/sierra.md
+24 −24 examples/erc20.rs
+24 −24 examples/starknet.rs
+10 −5 programs/benches/factorial_2M.c
+10 −5 programs/benches/fib_2M.c
+10 −5 programs/benches/logistic_map.c
+42 −48 programs/compile_benches/dijkstra.cairo
+8 −17 programs/compile_benches/extended_euclidean_algorithm.cairo
+78 −27 programs/compile_benches/fast_power.cairo
+0 −285 programs/compile_benches/sha256.cairo
+539 −0 programs/compile_benches/sha512.cairo
+2 −2 runtime/Cargo.toml
+28 −1 runtime/src/lib.rs
+10 −38 scripts/bench-hyperfine.sh
+51 −0 scripts/cmp_state_dumps.sh
+30 −0 scripts/diff-check.sh
+2 −9 src/arch/aarch64.rs
+2 −9 src/arch/x86_64.rs
+1 −1 src/bin/cairo-native-run.rs
+1 −1 src/bin/cairo-native-stress/main.rs
+7 −11 src/bin/cairo-native-test.rs
+14 −13 src/cache/aot.rs
+10 −8 src/cache/jit.rs
+20 −11 src/compiler.rs
+0 −6 src/debug.rs
+107 −0 src/error.rs
+2 −2 src/execution_result.rs
+88 −41 src/executor.rs
+57 −9 src/executor/aot.rs
+331 −50 src/executor/contract.rs
+26 −5 src/executor/jit.rs
+10 −14 src/ffi.rs
+9 −8 src/libfuncs.rs
+28 −17 src/libfuncs/array.rs
+43 −10 src/libfuncs/bounded_int.rs
+4 −1 src/libfuncs/cast.rs
+5 −3 src/libfuncs/circuit.rs
+10 −5 src/libfuncs/const.rs
+2 −2 src/libfuncs/debug.rs
+9 −4 src/libfuncs/enum.rs
+9 −2 src/libfuncs/felt252.rs
+1 −6 src/libfuncs/felt252_dict.rs
+2 −2 src/libfuncs/felt252_dict_entry.rs
+3 −2 src/libfuncs/function_call.rs
+131 −45 src/libfuncs/gas.rs
+426 −727 src/libfuncs/starknet.rs
+714 −1,545 src/libfuncs/starknet/secp256.rs
+46 −17 src/metadata/gas.rs
+44 −0 src/metadata/runtime_bindings.rs
+93 −97 src/starknet.rs
+23 −23 src/starknet_stub.rs
+12 −17 src/types.rs
+19 −24 src/types/array.rs
+6 −2 src/types/builtin_costs.rs
+10 −9 src/types/enum.rs
+9 −5 src/types/felt252_dict.rs
+1 −1 src/types/gas_builtin.rs
+5 −5 src/types/snapshot.rs
+5 −5 src/types/struct.rs
+111 −3 src/utils.rs
+87 −1 src/utils/block_ext.rs
+2 −3 src/values.rs
+6 −6 tests/alexandria/Scarb.lock
+4 −4 tests/alexandria/Scarb.toml
+41 −30 tests/common.rs
+1 −1 tests/tests/alexandria.rs
+2 −2 tests/tests/arrays.rs
+7 −7 tests/tests/boolean.rs
+1 −1 tests/tests/dict.rs
+5 −5 tests/tests/ec.rs
+4 −4 tests/tests/felt252.rs
+11 −11 tests/tests/programs.rs
+13 −5 tests/tests/starknet/keccak.rs
+57 −57 tests/tests/starknet/secp256.rs
+42 −42 tests/tests/starknet/syscalls.rs
+1 −4 tests/tests/starknet/u256.rs
+25 −25 tests/tests/uint.rs
113 changes: 65 additions & 48 deletions crates/blockifier/src/versioned_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,52 +568,69 @@ pub struct GasCosts {

impl GasCosts {
pub fn get_builtin_gas_cost(&self, builtin: &BuiltinName) -> Result<u64, GasCostsError> {
const KECCAK_BUILTIN_GAS_COST : u64 = 136189;
match *builtin {
BuiltinName::range_check => Ok(self.range_check_gas_cost),
BuiltinName::pedersen => Ok(self.pedersen_gas_cost),
BuiltinName::bitwise => Ok(self.bitwise_builtin_gas_cost),
BuiltinName::ec_op => Ok(self.ecop_gas_cost),
//TODO (Yonatan): once keccak_builtin_gas_cost is being inserted to the versioned constants, replace the constant with field's value
BuiltinName::keccak => Ok(KECCAK_BUILTIN_GAS_COST),
BuiltinName::poseidon => Ok(self.poseidon_gas_cost),
BuiltinName::range_check96 => Ok(self.range_check_gas_cost),
BuiltinName::add_mod => Ok(self.add_mod_gas_cost),
BuiltinName::mul_mod => Ok(self.mul_mod_gas_cost),
BuiltinName::segment_arena => Err(GasCostsError::VirtualBuiltin),
// The following are unsupported builtins in Cairo 1
BuiltinName::output | BuiltinName::ecdsa => Err(GasCostsError::UnsupportedBuiltinInCairo1 {builtin: *builtin,}),
}
const KECCAK_BUILTIN_GAS_COST: u64 = 136189;

let gas_cost = match *builtin {
BuiltinName::range_check => self.range_check_gas_cost,
BuiltinName::pedersen => self.pedersen_gas_cost,
BuiltinName::bitwise => self.bitwise_builtin_gas_cost,
BuiltinName::ec_op => self.ecop_gas_cost,
// TODO (Yonatan): once keccak_builtin_gas_cost is being inserted to the versioned
// constants, replace the constant with field's value
BuiltinName::keccak => KECCAK_BUILTIN_GAS_COST,
BuiltinName::poseidon => self.poseidon_gas_cost,
BuiltinName::range_check96 => self.range_check_gas_cost,
BuiltinName::add_mod => self.add_mod_gas_cost,
BuiltinName::mul_mod => self.mul_mod_gas_cost,
BuiltinName::segment_arena => return Err(GasCostsError::VirtualBuiltin),
BuiltinName::output | BuiltinName::ecdsa => {
return Err(GasCostsError::UnsupportedBuiltinInCairo1 { builtin: *builtin });
}
};

Ok(gas_cost)
}

pub fn get_syscall_gas_cost(&self, selector: &SyscallSelector) -> Result<u64, GasCostsError> {
match selector {
SyscallSelector::CallContract => Ok(self.call_contract_gas_cost),
SyscallSelector::Deploy => Ok(self.deploy_gas_cost),
SyscallSelector::EmitEvent => Ok(self.emit_event_gas_cost),
SyscallSelector::GetBlockHash => Ok(self.get_block_hash_gas_cost),
SyscallSelector::GetExecutionInfo => Ok(self.get_execution_info_gas_cost),
SyscallSelector::GetClassHashAt => Ok(self.get_class_hash_at_gas_cost),
SyscallSelector::Keccak => Ok(self.keccak_gas_cost),
SyscallSelector::Sha256ProcessBlock => Ok(self.sha256_process_block_gas_cost),
SyscallSelector::LibraryCall => Ok(self.library_call_gas_cost),
SyscallSelector::ReplaceClass => Ok(self.replace_class_gas_cost),
SyscallSelector::Secp256k1Add => Ok(self.secp256k1_add_gas_cost),
SyscallSelector::Secp256k1GetPointFromX => Ok(self.secp256k1_get_point_from_x_gas_cost),
SyscallSelector::Secp256k1GetXy => Ok(self.secp256k1_get_xy_gas_cost),
SyscallSelector::Secp256k1Mul => Ok(self.secp256k1_mul_gas_cost),
SyscallSelector::Secp256k1New => Ok(self.secp256k1_new_gas_cost),
SyscallSelector::Secp256r1Add => Ok(self.secp256r1_add_gas_cost),
SyscallSelector::Secp256r1GetPointFromX => Ok(self.secp256r1_get_point_from_x_gas_cost),
SyscallSelector::Secp256r1GetXy => Ok(self.secp256r1_get_xy_gas_cost),
SyscallSelector::Secp256r1Mul => Ok(self.secp256r1_mul_gas_cost),
SyscallSelector::Secp256r1New => Ok(self.secp256r1_new_gas_cost),
SyscallSelector::SendMessageToL1 => Ok(self.send_message_to_l1_gas_cost),
SyscallSelector::StorageRead => Ok(self.storage_read_gas_cost),
SyscallSelector::StorageWrite => Ok(self.storage_write_gas_cost),
// The following are unsupported syscalls in Cairo 1
SyscallSelector::DelegateCall | SyscallSelector::DelegateL1Handler | SyscallSelector::GetBlockNumber | SyscallSelector::GetBlockTimestamp | SyscallSelector::GetCallerAddress | SyscallSelector::GetContractAddress | SyscallSelector::GetTxInfo | SyscallSelector::GetSequencerAddress | SyscallSelector::GetTxSignature | SyscallSelector::LibraryCallL1Handler => Err(GasCostsError::DeprecatedSyscall{selector: *selector,}),
}
let gas_cost = match *selector {
SyscallSelector::CallContract => self.call_contract_gas_cost,
SyscallSelector::Deploy => self.deploy_gas_cost,
SyscallSelector::EmitEvent => self.emit_event_gas_cost,
SyscallSelector::GetBlockHash => self.get_block_hash_gas_cost,
SyscallSelector::GetExecutionInfo => self.get_execution_info_gas_cost,
SyscallSelector::GetClassHashAt => self.get_class_hash_at_gas_cost,
SyscallSelector::Keccak => self.keccak_gas_cost,
SyscallSelector::Sha256ProcessBlock => self.sha256_process_block_gas_cost,
SyscallSelector::LibraryCall => self.library_call_gas_cost,
SyscallSelector::ReplaceClass => self.replace_class_gas_cost,
SyscallSelector::Secp256k1Add => self.secp256k1_add_gas_cost,
SyscallSelector::Secp256k1GetPointFromX => self.secp256k1_get_point_from_x_gas_cost,
SyscallSelector::Secp256k1GetXy => self.secp256k1_get_xy_gas_cost,
SyscallSelector::Secp256k1Mul => self.secp256k1_mul_gas_cost,
SyscallSelector::Secp256k1New => self.secp256k1_new_gas_cost,
SyscallSelector::Secp256r1Add => self.secp256r1_add_gas_cost,
SyscallSelector::Secp256r1GetPointFromX => self.secp256r1_get_point_from_x_gas_cost,
SyscallSelector::Secp256r1GetXy => self.secp256r1_get_xy_gas_cost,
SyscallSelector::Secp256r1Mul => self.secp256r1_mul_gas_cost,
SyscallSelector::Secp256r1New => self.secp256r1_new_gas_cost,
SyscallSelector::SendMessageToL1 => self.send_message_to_l1_gas_cost,
SyscallSelector::StorageRead => self.storage_read_gas_cost,
SyscallSelector::StorageWrite => self.storage_write_gas_cost,
SyscallSelector::DelegateCall
| SyscallSelector::DelegateL1Handler
| SyscallSelector::GetBlockNumber
| SyscallSelector::GetBlockTimestamp
| SyscallSelector::GetCallerAddress
| SyscallSelector::GetContractAddress
| SyscallSelector::GetTxInfo
| SyscallSelector::GetSequencerAddress
| SyscallSelector::GetTxSignature
| SyscallSelector::LibraryCallL1Handler => {
return Err(GasCostsError::DeprecatedSyscall { selector: *selector });
}
};

Ok(gas_cost)
}
}

Expand Down Expand Up @@ -814,11 +831,11 @@ pub enum OsConstantsSerdeError {

#[derive(Debug, Error)]
pub enum GasCostsError {
#[error("used syscall: {:?} is not supported in a Cairo 0 contract", selector)]
DeprecatedSyscall {selector: SyscallSelector},
#[error("used builtin: {:?} is not supported in a Cairo 1 contract", builtin)]
UnsupportedBuiltinInCairo1 {builtin: BuiltinName},
#[error("a virtual builtin cannot be used in a smart contract")]
#[error("used syscall: {:?} is not supported in a Cairo 0 contract.", selector)]
DeprecatedSyscall { selector: SyscallSelector },
#[error("used builtin: {:?} is not supported in a Cairo 1 contract.", builtin)]
UnsupportedBuiltinInCairo1 { builtin: BuiltinName },
#[error("a virtual builtin does not have a gas cost.")]
VirtualBuiltin,
}

Expand Down

0 comments on commit 7497521

Please sign in to comment.