Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into ft/key_not_found_in_p…
Browse files Browse the repository at this point in the history
…reimage
  • Loading branch information
ftheirs committed Dec 12, 2024
2 parents d43e7ed + 35a300a commit e7a5630
Show file tree
Hide file tree
Showing 7 changed files with 1,605 additions and 197 deletions.
4 changes: 4 additions & 0 deletions crates/bin/prove_block/tests/prove_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ const DEFAULT_COMPILED_OS: &[u8] = include_bytes!("../../../../build/os_latest.j
#[case::peekable_peek_is_none(174156)]
#[case::no_more_storage_reads_available(161884)]
#[case::no_more_storage_reads_available(174027)]
#[case::memory_addresses_must_be_relocatable(202083)]
#[case::memory_invalid_signature(216914)]
#[case::diff_assert_values(218624)]
#[case::could_nt_compute_operand_op1(204337)]
// The following ten tests were added due key not found in preimage (verify_game contract function related)
#[case::key_not_found_in_preimage_0(237025)]
#[case::key_not_found_in_preimage_1(237030)]
Expand Down
7 changes: 4 additions & 3 deletions crates/starknet-os/src/hints/execute_transactions.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::HashMap;

use cairo_vm::hint_processor::builtin_hint_processor::hint_utils::{
get_integer_from_var_name, get_ptr_from_var_name, get_relocatable_from_var_name, insert_value_from_var_name,
get_integer_from_var_name, get_ptr_from_var_name, insert_value_from_var_name,
};
use cairo_vm::hint_processor::builtin_hint_processor::sha256_utils::sha256_finalize;
use cairo_vm::hint_processor::hint_processor_definition::HintReference;
Expand Down Expand Up @@ -38,8 +38,9 @@ where
{
let execution_helper: ExecutionHelperWrapper<PCS> = exec_scopes.get(vars::scopes::EXECUTION_HELPER)?;
let execution_context_ptr =
get_relocatable_from_var_name(vars::ids::VALIDATE_DECLARE_EXECUTION_CONTEXT, vm, ids_data, ap_tracking)?;
let deprecated_tx_info_ptr = (execution_context_ptr + ExecutionContext::deprecated_tx_info_offset())?;
get_ptr_from_var_name(vars::ids::VALIDATE_DECLARE_EXECUTION_CONTEXT, vm, ids_data, ap_tracking)?;
let deprecated_tx_info_ptr =
vm.get_relocatable((execution_context_ptr + ExecutionContext::deprecated_tx_info_offset())?)?;

execution_helper.start_tx(Some(deprecated_tx_info_ptr)).await;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// A dummy account contract to replicate a get_tx_info bug.
// This is added to specifically check `get_tx_info` call that had a buggy implementation
%lang starknet

from starkware.cairo.common.bool import FALSE
from starkware.cairo.common.cairo_builtins import HashBuiltin
from starkware.starknet.common.syscalls import (
call_contract,
deploy,
emit_event,
get_block_number,
get_block_timestamp,
get_caller_address,
get_contract_address,
get_tx_info,
get_tx_signature,
library_call,
library_call_l1_handler,
replace_class,
storage_read,
storage_write,
)

// This attempts to check all relevant syscalls in account contracts
// which have been buggy esp on `get_tx_info`
func check_all{syscall_ptr: felt*}() {
let (tx_info) = get_tx_info();
with_attr error_message("tx_info.signature_len failed") {
assert tx_info.signature_len = 0;
}

let (block_number) = get_block_number();
assert block_number = 2000;

let (block_timestamp) = get_block_timestamp();
assert block_timestamp = 1069200;

let (contract_address) = get_contract_address();

let (caller_address) = get_caller_address();
assert caller_address = 0;

let (prev_value) = storage_read(address=contract_address);
storage_write(contract_address, value=prev_value + 1);


let (signature_len: felt, signature: felt*) = get_tx_signature();
assert signature_len = 0;

storage_write(address=contract_address, value=1);

let (res) = storage_read(address=contract_address);
assert res = 1;

return ();
}

@external
func __validate_declare__{syscall_ptr: felt*}(class_hash: felt) {
check_all();
return ();
}

// The hint implementation was using get_relocatable_from_var_name instead of get_ptr_from_var_name
@external
func __validate_deploy__{syscall_ptr: felt*}(class_hash: felt, contract_address_salt: felt) {
check_all();
return ();
}

@external
func __validate__{syscall_ptr: felt*}(contract_address, selector: felt, calldata_len: felt, calldata: felt*) {
check_all();
return ();
}

@external
@raw_output
func __execute__{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
contract_address, selector: felt, calldata_len: felt, calldata: felt*
) -> (retdata_size: felt, retdata: felt*) {
check_all();
let (retdata_size: felt, retdata: felt*) = call_contract(
contract_address=contract_address,
function_selector=selector,
calldata_size=calldata_len,
calldata=calldata,
);
return (retdata_size=retdata_size, retdata=retdata);
}

This file was deleted.

Loading

0 comments on commit e7a5630

Please sign in to comment.