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

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
edg-l committed Jun 6, 2024
1 parent a69490e commit 8760ed7
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 67 deletions.
18 changes: 13 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ cairo-lang-sierra = { workspace = true }
cairo-lang-starknet = { workspace = true }
cairo-lang-utils = { workspace = true }
cairo-lang-starknet-classes = { workspace = true }
cairo-native = { git = "https://github.com/lambdaclass/cairo_native", rev = "15bd4b9e672a0c1a196de4b613ee72befaf08b28", optional = true }
cairo-native = { path = "/Users/edgar/Documents/cairo_sierra_to_mlir", optional = true }
k256 = "0.13.3"
p256 = "0.13.2"
sec1 = "0.7.3"
Expand Down Expand Up @@ -76,6 +76,7 @@ tracing = "0.1.40"
[dev-dependencies]
assert_matches = "1.5.0"
coverage-helper = "0.2.2"
itertools = "0.13.0"
lru = "0.12.3"
pretty_assertions_sorted = "1.2.3"
reth-primitives = { git = "https://github.com/paradigmxyz/reth.git", tag = "v0.2.0-beta.6", default-features = false }
Expand Down
7 changes: 7 additions & 0 deletions src/execution/execution_entry_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ impl ExecutionEntryPoint {

match contract_class {
CompiledClass::Deprecated(contract_class) => {
dbg!("deprecated");
let call_info = self._execute_version0_class(
state,
resources_manager,
Expand All @@ -157,6 +158,7 @@ impl ExecutionEntryPoint {
sierra: Some(sierra_program_and_entrypoints),
..
} => {
dbg!("casm");
let mut transactional_state = state.create_transactional()?;

let program_cache = program_cache.unwrap_or_else(|| {
Expand Down Expand Up @@ -716,6 +718,7 @@ impl ExecutionEntryPoint {
.iter()
.find(|entry_point| entry_point.selector == self.entry_point_selector.to_biguint())
.unwrap();
dbg!(&entry_point);
let native_executor: NativeExecutor = {
let mut cache = program_cache.borrow_mut();
let cache = &mut *cache;
Expand Down Expand Up @@ -760,6 +763,10 @@ impl ExecutionEntryPoint {
.find(|x| x.id.id == (entry_point.function_idx as u64))
.unwrap();

dbg!(&entry_point_fn.id.debug_name.as_ref());
dbg!(&entry_point_fn.params);
std::fs::write("hello.sierra", sierra_program.to_string()).unwrap();

let entry_point_id = &entry_point_fn.id;

let value = match native_executor {
Expand Down
60 changes: 4 additions & 56 deletions src/syscalls/native_syscall_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1012,62 +1012,10 @@ impl<'a, 'cache, S: StateReader, C: ContractClassCache> StarknetSyscallHandler
Ok((p.x, p.y))
}

fn pop_log(&mut self) {
todo!()
}

fn set_account_contract_address(&mut self, contract_address: Felt252) {
self.tx_execution_context.account_contract_address = Address(contract_address);
}

fn set_block_number(&mut self, block_number: u64) {
self.block_context.block_info.block_number = block_number;
}

fn set_block_timestamp(&mut self, block_timestamp: u64) {
self.block_context.block_info.block_timestamp = block_timestamp;
}

fn set_caller_address(&mut self, address: Felt252) {
self.caller_address = Address(address);
}

fn set_chain_id(&mut self, chain_id: Felt252) {
self.block_context.starknet_os_config.chain_id = chain_id;
}

fn set_contract_address(&mut self, address: Felt252) {
self.contract_address = Address(address);
}

fn set_max_fee(&mut self, max_fee: u128) {
if matches!(
self.tx_execution_context.account_tx_fields,
VersionSpecificAccountTxFields::Deprecated(_)
) {
self.tx_execution_context.account_tx_fields =
VersionSpecificAccountTxFields::new_deprecated(max_fee)
};
}

fn set_nonce(&mut self, nonce: Felt252) {
self.tx_execution_context.nonce = nonce;
}

fn set_sequencer_address(&mut self, _address: Felt252) {
todo!()
}

fn set_signature(&mut self, signature: &[Felt252]) {
self.tx_execution_context.signature = signature.to_vec();
}

fn set_transaction_hash(&mut self, transaction_hash: Felt252) {
self.tx_execution_context.transaction_hash = transaction_hash;
}

fn set_version(&mut self, version: Felt252) {
self.tx_execution_context.version = version;
fn cheatcode(&mut self, _selector: Felt252, _input: &[Felt252]) -> Vec<Felt252> {
dbg!(_selector);
dbg!(_input);
vec![Felt252::ONE]
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/transaction/declare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ impl Declare {
if !execution_result
.call_info
.as_ref()
.map(|ci| ci.retdata == vec![*VALIDATE_RETDATA])
.map(|ci| dbg!(&ci.retdata) == &vec![*VALIDATE_RETDATA])
.unwrap_or_default()
{
return Err(TransactionError::WrongValidateRetdata);
Expand Down
2 changes: 1 addition & 1 deletion src/transaction/deploy_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ impl DeployAccount {
// return `VALID`.
if !call_info
.as_ref()
.map(|ci| ci.retdata == vec![*VALIDATE_RETDATA])
.map(|ci| dbg!(&ci.retdata) == &vec![*VALIDATE_RETDATA])
.unwrap_or_default()
{
return Err(TransactionError::WrongValidateRetdata);
Expand Down
9 changes: 8 additions & 1 deletion src/transaction/invoke_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,13 @@ impl InvokeFunction {
// return `VALID`.
if !call_info
.as_ref()
.map(|ci| ci.retdata == vec![*VALIDATE_RETDATA])
.map(|ci| {
dbg!(ci.retdata[0].to_hex_string());
dbg!(ci.retdata[0].to_string());
dbg!(ci.retdata[0].to_bigint());

dbg!(&ci.retdata) == &vec![*VALIDATE_RETDATA]
})
.unwrap_or_default()
{
return Err(TransactionError::WrongValidateRetdata);
Expand Down Expand Up @@ -439,6 +445,7 @@ impl InvokeFunction {
Rc<RefCell<ProgramCache<'_, ClassHash>>>,
>,
) -> Result<TransactionExecutionInfo, TransactionError> {
dbg!("execute transaction native");
if !(self.version == Felt252::ZERO
|| self.version == Felt252::ONE
|| self.version == Felt252::THREE)
Expand Down
12 changes: 10 additions & 2 deletions tests/integration_tests/complex_contracts/kakarot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ fn test_kakarot_contract() {

let mut state = TestStateSetup::default();

dbg!("deploy");

// Deploy Kakarot
state
.load_contract_at_address(
Expand All @@ -81,6 +83,7 @@ fn test_kakarot_contract() {
"starknet_programs/kakarot/contracts_KakarotCore.cairo",
)
.unwrap();
dbg!("deploy eoa");
// Deploy EOA
state
.load_contract_at_address(
Expand All @@ -89,6 +92,7 @@ fn test_kakarot_contract() {
"starknet_programs/kakarot/contracts_AccountContract.cairo",
)
.unwrap();
dbg!("deploy contract account");
// Deploy Contract Account
state
.load_contract_at_address(
Expand All @@ -98,6 +102,7 @@ fn test_kakarot_contract() {
)
.unwrap();

dbg!("uninit account");
// Declare uninitialized account class hash
state
.load_contract(
Expand All @@ -106,6 +111,7 @@ fn test_kakarot_contract() {
)
.unwrap();

dbg!("perepare storage");
// Prepare storage for Kakarot
let kakarot_storage = vec![
// Add the EOA to the address registry
Expand Down Expand Up @@ -316,11 +322,11 @@ fn test_kakarot_contract() {
transaction.signature = signature;

// Prepare the starknet transaction
let mut calldata = vec![];
let mut calldata: Vec<u8> = vec![];
transaction
.transaction
.encode_without_signature(&mut calldata);
let mut calldata = calldata.into_iter().map(Felt252::from).collect::<Vec<_>>();
let mut calldata: Vec<Felt252> = calldata.into_iter().map(Felt252::from).collect::<Vec<_>>();
let mut execute_calldata = vec![
Felt252::ONE, // call array length
kakarot_address.0, // contract address
Expand Down Expand Up @@ -352,7 +358,9 @@ fn test_kakarot_contract() {

let tx = tx.create_for_simulation(false, false, true, true, true);

dbg!("executing tx");
let execution_result = state.execute_transaction(tx).unwrap();
dbg!("after executing tx");
assert!(execution_result.revert_error.is_none());

// Check that the storage var was updated (contract bytecode should update storage var at key 0u256 to 1)
Expand Down

0 comments on commit 8760ed7

Please sign in to comment.