Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
TMP - DO NOT MERGE
Browse files Browse the repository at this point in the history
Signed-off-by: Dori Medini <dori@starkware.co>
  • Loading branch information
dorimedini-starkware committed Jun 2, 2023
1 parent b4f6cb3 commit 19f3c6d
Show file tree
Hide file tree
Showing 13 changed files with 705 additions and 248 deletions.
801 changes: 632 additions & 169 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ members = ["crates/blockifier", "crates/native_blockifier"]

[workspace.dependencies]
assert_matches = "1.5.0"
cairo-felt = "0.3.0-rc1"
cairo-lang-casm = { version = "1.1.0-alpha0" }
cairo-lang-runner = { version = "1.1.0-alpha0" }
cairo-lang-starknet = { version = "1.1.0-alpha0" }
cairo-vm = "0.3.0-rc1"
cairo-felt = { git = "https://github.com/lambdaclass/cairo-rs", rev = "5db2e65" }
cairo-lang-casm = { git = "https://github.com/starkware-libs/cairo", rev = "7531601" }
cairo-lang-runner = { git = "https://github.com/starkware-libs/cairo", rev = "7531601" }
cairo-lang-starknet = { git = "https://github.com/starkware-libs/cairo", rev = "7531601" }
cairo-vm = { git = "https://github.com/lambdaclass/cairo-rs", rev = "5db2e65" }
ctor = "0.2.0"
derive_more = "0.99.17"
hex = "0.4.3"
Expand All @@ -22,7 +22,7 @@ num-bigint = "0.4"
num-integer = "0.1.45"
num-traits = "0.2"
ouroboros = "0.15.6"
papyrus_storage = { git = "https://github.com/starkware-libs/papyrus", rev = "6545673" }
papyrus_storage = { git = "https://github.com/starkware-libs/papyrus", rev = "5bb23d6" }
phf = { version = "0.11", features = ["macros"] }
pretty_assertions = "1.2.1"
serde = "1.0.130"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6646,71 +6646,71 @@
"selector": "0x3c118a68e16e12e97ed25cb4901c12f4d3162818669cc44c391d8049924c14",
"offset": 556,
"builtins": [
"range_check"
"range_check_builtin"
]
},
{
"selector": "0xe7510edcf6e9f1b70f7bd1f488767b50f0363422f3c563160ab77adf62467b",
"offset": 1328,
"builtins": [
"range_check"
"range_check_builtin"
]
},
{
"selector": "0x10d2fede95e3ec06a875a67219425c27c5bd734d57f1b221d729a2337b6b556",
"offset": 1647,
"builtins": [
"range_check",
"range_check_builtin",
"segment_arena"
]
},
{
"selector": "0x169f135eddda5ab51886052d777a57f2ea9c162d713691b5e04a6d4ed71d47f",
"offset": 1761,
"builtins": [
"range_check"
"range_check_builtin"
]
},
{
"selector": "0x27c3334165536f239cfd400ed956eabff55fc60de4fb56728b6a4f6b87db01c",
"offset": 167,
"builtins": [
"range_check"
"range_check_builtin"
]
},
{
"selector": "0x2913ee03e5e3308c41e308bd391ea4faac9b9cb5062c76a6b3ab4f65397e106",
"offset": 365,
"builtins": [
"range_check"
"range_check_builtin"
]
},
{
"selector": "0x2d7cf5d5a324a320f9f37804b1615a533fde487400b41af80f13f7ac5581325",
"offset": 1469,
"builtins": [
"range_check"
"range_check_builtin"
]
},
{
"selector": "0x3604cea1cdb094a73a31144f14a3e5861613c008e1e879939ebc4827d10cd50",
"offset": 907,
"builtins": [
"range_check"
"range_check_builtin"
]
},
{
"selector": "0x3a6a8bae4c51d5959683ae246347ffdd96aa5b2bfa68cc8c3a6a7c2ed0be331",
"offset": 1105,
"builtins": [
"range_check"
"range_check_builtin"
]
},
{
"selector": "0x3b097c62d3e4b85742aadd0dfb823f96134b886ec13bda57b68faf86f294d97",
"offset": 0,
"builtins": [
"range_check"
"range_check_builtin"
]
}
],
Expand All @@ -6719,7 +6719,7 @@
"selector": "0x39edbbb129ad752107a94d40c3873cae369a46fd2fc578d075679aa67e85d12",
"offset": 1982,
"builtins": [
"range_check"
"range_check_builtin"
]
}
],
Expand All @@ -6728,9 +6728,9 @@
"selector": "0x28ffe4ff0f226a9107253e17a904099aa4f63a02a5621de0576e5aa71bc5194",
"offset": 2136,
"builtins": [
"range_check"
"range_check_builtin"
]
}
]
}
}
}
4 changes: 2 additions & 2 deletions crates/blockifier/src/execution/cairo1_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,13 @@ fn prepare_builtin_costs(

// Put a pointer to the builtin cost segment at the end of the program (after the
// additional `ret` statement).
let mut ptr = (vm.get_pc() + contract_class.program.data.len())?;
let mut ptr = (vm.get_pc() + contract_class.program.data_len())?;
// Push a `ret` opcode.
write_stark_felt(vm, &mut ptr, stark_felt!("0x208b7fff7fff7ffe"))?;
// Push a pointer to the builtin cost segment.
write_maybe_relocatable(vm, &mut ptr, builtin_cost_segment_start)?;

Ok(contract_class.program.data.len() + 2)
Ok(contract_class.program.data_len() + 2)
}

pub fn prepare_call_arguments(
Expand Down
1 change: 0 additions & 1 deletion crates/blockifier/src/execution/contract_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ impl TryFrom<CasmContractClass> for ContractClassV1 {

let program = Program::new(
builtins,
Felt252::prime().to_str_radix(16),
data,
main,
hints,
Expand Down
5 changes: 4 additions & 1 deletion crates/blockifier/src/execution/entry_point_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,17 +524,20 @@ Got an exception while executing a hint.
Cairo traceback (most recent call last):
Unknown location (pc=0:629)
Unknown location (pc=0:612)
Error in the called contract ({}):
Error at pc=0:19:
Got an exception while executing a hint.
Cairo traceback (most recent call last):
Unknown location (pc=0:629)
Unknown location (pc=0:612)
Error in the called contract ({}):
Error at pc=0:58:
An ASSERT_EQ instruction failed: 1 != 0.
Cairo traceback (most recent call last):
Unknown location (pc=0:62)",
Unknown location (pc=0:62)
",
pad_address_to_64(TEST_CONTRACT_ADDRESS),
pad_address_to_64(TEST_CONTRACT_ADDRESS_2),
pad_address_to_64(SECURITY_TEST_CONTRACT_ADDRESS)
Expand Down
1 change: 0 additions & 1 deletion crates/blockifier/src/execution/execution_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ pub fn sn_api_to_cairo_vm_program(program: DeprecatedProgram) -> Result<Program,

let program = Program::new(
builtins,
Felt252::prime().to_str_radix(16),
data,
main,
hints,
Expand Down
14 changes: 9 additions & 5 deletions crates/blockifier/src/fee/fee_test.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
use std::collections::HashMap;

use assert_matches::assert_matches;
use cairo_vm::vm::runners::builtin_runner::{
BITWISE_BUILTIN_NAME, HASH_BUILTIN_NAME, POSEIDON_BUILTIN_NAME, RANGE_CHECK_BUILTIN_NAME,
SIGNATURE_BUILTIN_NAME,
};

use crate::block_context::BlockContext;
use crate::fee::fee_utils::calculate_l1_gas_by_vm_usage;
Expand All @@ -10,11 +14,11 @@ use crate::transaction::objects::ResourcesMapping;
fn get_vm_resource_usage() -> ResourcesMapping {
ResourcesMapping(HashMap::from([
(String::from("n_steps"), 1800),
(String::from("pedersen"), 10),
(String::from("range_check"), 24),
(String::from("ecdsa"), 1),
(String::from("bitwise"), 1),
(String::from("poseidon"), 1),
(String::from(HASH_BUILTIN_NAME), 10),
(String::from(RANGE_CHECK_BUILTIN_NAME), 24),
(String::from(SIGNATURE_BUILTIN_NAME), 1),
(String::from(BITWISE_BUILTIN_NAME), 1),
(String::from(POSEIDON_BUILTIN_NAME), 1),
]))
}

Expand Down
31 changes: 16 additions & 15 deletions crates/blockifier/src/fee/os_resources.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use cairo_vm::vm::runners::builtin_runner::{HASH_BUILTIN_NAME, RANGE_CHECK_BUILTIN_NAME};
use serde_json::json;

use crate::fee::os_usage::OsResources;
Expand All @@ -13,29 +14,29 @@ fn os_resources() -> serde_json::Value {
"execute_syscalls": {
"CallContract": {
"builtin_instance_counter": {
"range_check": 19
RANGE_CHECK_BUILTIN_NAME: 19
},
"n_memory_holes": 0,
"n_steps": 690
},
"DelegateCall": {
"builtin_instance_counter": {
"range_check": 19
RANGE_CHECK_BUILTIN_NAME: 19
},
"n_memory_holes": 0,
"n_steps": 712
},
"DelegateL1Handler": {
"builtin_instance_counter": {
"range_check": 15
RANGE_CHECK_BUILTIN_NAME: 15
},
"n_memory_holes": 0,
"n_steps": 691
},
"Deploy": {
"builtin_instance_counter": {
"pedersen": 7,
"range_check": 18
HASH_BUILTIN_NAME: 7,
RANGE_CHECK_BUILTIN_NAME: 18
},
"n_memory_holes": 0,
"n_steps": 936
Expand Down Expand Up @@ -87,14 +88,14 @@ fn os_resources() -> serde_json::Value {
},
"LibraryCall": {
"builtin_instance_counter": {
"range_check": 19
RANGE_CHECK_BUILTIN_NAME: 19
},
"n_memory_holes": 0,
"n_steps": 679
},
"LibraryCallL1Handler": {
"builtin_instance_counter": {
"range_check": 15
RANGE_CHECK_BUILTIN_NAME: 15
},
"n_memory_holes": 0,
"n_steps": 658
Expand Down Expand Up @@ -123,32 +124,32 @@ fn os_resources() -> serde_json::Value {
"execute_txs_inner": {
"Declare": {
"builtin_instance_counter": {
"pedersen": 15,
"range_check": 63
HASH_BUILTIN_NAME: 15,
RANGE_CHECK_BUILTIN_NAME: 63
},
"n_memory_holes": 0,
"n_steps": 2703
},
"DeployAccount": {
"builtin_instance_counter": {
"pedersen": 23,
"range_check": 83
HASH_BUILTIN_NAME: 23,
RANGE_CHECK_BUILTIN_NAME: 83
},
"n_memory_holes": 0,
"n_steps": 3612
},
"InvokeFunction": {
"builtin_instance_counter": {
"pedersen": 16,
"range_check": 80,
HASH_BUILTIN_NAME: 16,
RANGE_CHECK_BUILTIN_NAME: 80,
},
"n_memory_holes": 0,
"n_steps": 3363
},
"L1Handler": {
"builtin_instance_counter": {
"pedersen": 11,
"range_check": 17
HASH_BUILTIN_NAME: 11,
RANGE_CHECK_BUILTIN_NAME: 17
},
"n_memory_holes": 0,
"n_steps": 1068
Expand Down
18 changes: 11 additions & 7 deletions crates/blockifier/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ use std::collections::HashMap;
use std::fs;
use std::path::PathBuf;

use cairo_vm::vm::runners::builtin_runner::{
BITWISE_BUILTIN_NAME, EC_OP_BUILTIN_NAME, HASH_BUILTIN_NAME, OUTPUT_BUILTIN_NAME,
POSEIDON_BUILTIN_NAME, RANGE_CHECK_BUILTIN_NAME, SIGNATURE_BUILTIN_NAME,
};
use starknet_api::block::{BlockNumber, BlockTimestamp};
use starknet_api::core::{
calculate_contract_address, ChainId, ClassHash, CompiledClassHash, ContractAddress,
Expand Down Expand Up @@ -332,13 +336,13 @@ impl BlockContext {
pub fn create_for_account_testing() -> BlockContext {
let vm_resource_fee_cost = HashMap::from([
(String::from("n_steps"), 1_f64),
(String::from("pedersen"), 1_f64),
(String::from("range_check"), 1_f64),
(String::from("ecdsa"), 1_f64),
(String::from("bitwise"), 1_f64),
(String::from("poseidon"), 1_f64),
(String::from("output"), 1_f64),
(String::from("ec_op"), 1_f64),
(String::from(HASH_BUILTIN_NAME), 1_f64),
(String::from(RANGE_CHECK_BUILTIN_NAME), 1_f64),
(String::from(SIGNATURE_BUILTIN_NAME), 1_f64),
(String::from(BITWISE_BUILTIN_NAME), 1_f64),
(String::from(POSEIDON_BUILTIN_NAME), 1_f64),
(String::from(OUTPUT_BUILTIN_NAME), 1_f64),
(String::from(EC_OP_BUILTIN_NAME), 1_f64),
]);
BlockContext { vm_resource_fee_cost, ..BlockContext::create_for_testing() }
}
Expand Down
12 changes: 6 additions & 6 deletions crates/blockifier/src/transaction/transactions_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,8 @@ fn test_invoke_tx() {
actual_fee: expected_actual_fee,
actual_resources: ResourcesMapping(HashMap::from([
(abi_constants::GAS_USAGE.to_string(), 1224),
("pedersen".to_string(), 16),
("range_check".to_string(), 101),
(HASH_BUILTIN_NAME.to_string(), 16),
(RANGE_CHECK_BUILTIN_NAME.to_string(), 101),
(abi_constants::N_STEPS_RESOURCE.to_string(), 4135),
])),
revert_error: None,
Expand Down Expand Up @@ -580,8 +580,8 @@ fn test_declare_tx() {
actual_fee: expected_actual_fee,
actual_resources: ResourcesMapping(HashMap::from([
(abi_constants::GAS_USAGE.to_string(), 1224),
("pedersen".to_string(), 15),
("range_check".to_string(), 63),
(HASH_BUILTIN_NAME.to_string(), 15),
(RANGE_CHECK_BUILTIN_NAME.to_string(), 63),
(abi_constants::N_STEPS_RESOURCE.to_string(), 2715),
])),
revert_error: None,
Expand Down Expand Up @@ -697,8 +697,8 @@ fn test_deploy_account_tx() {
actual_fee: expected_actual_fee,
actual_resources: ResourcesMapping(HashMap::from([
(abi_constants::GAS_USAGE.to_string(), 3060),
("pedersen".to_string(), 23),
("range_check".to_string(), 83),
(HASH_BUILTIN_NAME.to_string(), 23),
(RANGE_CHECK_BUILTIN_NAME.to_string(), 83),
(abi_constants::N_STEPS_RESOURCE.to_string(), 3625),
])),
revert_error: None,
Expand Down
4 changes: 2 additions & 2 deletions crates/native_blockifier/src/papyrus_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl<'env> StateReader for PapyrusReader<'env> {
if class_is_declared {
let casm_contract_class = self
.contract_classes
.get_casm(*class_hash)
.get_casm(class_hash)
.map_err(|err| StateError::StateReadError(err.to_string()))?
.expect(
"Should be able to fetch a Casm class if its definition exists, database is \
Expand Down Expand Up @@ -190,7 +190,7 @@ impl<'env> PapyrusExecutableClassReader<'env> {
Self { txn }
}

fn get_casm(&self, class_hash: ClassHash) -> StorageResult<Option<CasmContractClass>> {
fn get_casm(&self, class_hash: &ClassHash) -> StorageResult<Option<CasmContractClass>> {
self.txn.get_casm(class_hash)
}
}
Loading

0 comments on commit 19f3c6d

Please sign in to comment.