Skip to content

Commit

Permalink
feat(blockifier): version bound accounts: add max tip
Browse files Browse the repository at this point in the history
  • Loading branch information
liorgold2 committed Mar 4, 2025
1 parent c7607ac commit 78dacc5
Show file tree
Hide file tree
Showing 14 changed files with 112 additions and 44 deletions.
3 changes: 2 additions & 1 deletion crates/blockifier/resources/versioned_constants_0_13_0.json
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@
}
},
"v1_bound_accounts_cairo0": [],
"v1_bound_accounts_cairo1": []
"v1_bound_accounts_cairo1": [],
"v1_bound_accounts_max_tip": "0x0"
},
"os_resources": {
"execute_syscalls": {
Expand Down
3 changes: 2 additions & 1 deletion crates/blockifier/resources/versioned_constants_0_13_1.json
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@
}
},
"v1_bound_accounts_cairo0": [],
"v1_bound_accounts_cairo1": []
"v1_bound_accounts_cairo1": [],
"v1_bound_accounts_max_tip": "0x0"
},
"os_resources": {
"execute_syscalls": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@
}
},
"v1_bound_accounts_cairo0": [],
"v1_bound_accounts_cairo1": []
"v1_bound_accounts_cairo1": [],
"v1_bound_accounts_max_tip": "0x0"
},
"os_resources": {
"execute_syscalls": {
Expand Down
3 changes: 2 additions & 1 deletion crates/blockifier/resources/versioned_constants_0_13_2.json
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@
}
},
"v1_bound_accounts_cairo0": [],
"v1_bound_accounts_cairo1": []
"v1_bound_accounts_cairo1": [],
"v1_bound_accounts_max_tip": "0x0"
},
"os_resources": {
"execute_syscalls": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@
}
},
"v1_bound_accounts_cairo0": [],
"v1_bound_accounts_cairo1": []
"v1_bound_accounts_cairo1": [],
"v1_bound_accounts_max_tip": "0x0"
},
"os_resources": {
"execute_syscalls": {
Expand Down
3 changes: 2 additions & 1 deletion crates/blockifier/resources/versioned_constants_0_13_3.json
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@
}
},
"v1_bound_accounts_cairo0": [],
"v1_bound_accounts_cairo1": []
"v1_bound_accounts_cairo1": [],
"v1_bound_accounts_max_tip": "0x0"
},
"os_resources": {
"execute_syscalls": {
Expand Down
3 changes: 2 additions & 1 deletion crates/blockifier/resources/versioned_constants_0_13_4.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@
},
"validated": "VALID",
"v1_bound_accounts_cairo0": [],
"v1_bound_accounts_cairo1": []
"v1_bound_accounts_cairo1": [],
"v1_bound_accounts_max_tip": "0x0"
},
"os_resources": {
"execute_syscalls": {
Expand Down
3 changes: 2 additions & 1 deletion crates/blockifier/resources/versioned_constants_0_13_5.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@
"0x01c0bb51e2ce73dc007601a1e7725453627254016c28f118251a71bbb0507fcb",
"0x0251830adc3d8b4d818c2c309d71f1958308e8c745212480c26e01120c69ee49",
"0x0251cac7b2f45d255b83b7a06dcdef70c8a8752f00ea776517c1c2243c7a06e5"
]
],
"v1_bound_accounts_max_tip": "0x1000"
},
"os_resources": {
"execute_syscalls": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use starknet_api::test_utils::{
CURRENT_BLOCK_TIMESTAMP_FOR_VALIDATE,
TEST_SEQUENCER_ADDRESS,
};
use starknet_api::transaction::fields::{Calldata, ContractAddressSalt, Fee};
use starknet_api::transaction::fields::{Calldata, ContractAddressSalt, Fee, Tip};
use starknet_api::transaction::{
EventContent,
EventData,
Expand Down Expand Up @@ -42,11 +42,7 @@ use crate::test_utils::{
trivial_external_entry_point_new,
CairoVersion,
};
use crate::transaction::objects::{
CommonAccountFields,
DeprecatedTransactionInfo,
TransactionInfo,
};
use crate::transaction::objects::{CommonAccountFields, CurrentTransactionInfo, TransactionInfo};
use crate::versioned_constants::VersionedConstants;
use crate::{check_entry_point_execution_error_for_custom_hint, retdata};

Expand Down Expand Up @@ -455,6 +451,8 @@ fn test_block_info_syscalls(
fn test_tx_info(
#[values(false, true)] only_query: bool,
#[values(false, true)] v1_bound_account: bool,
// Whether the tip is larger than `v1_bound_accounts_max_tip`.
#[values(false, true)] high_tip: bool,
) {
let test_contract = FeatureContract::TestContract(CairoVersion::Cairo0);
let mut test_contract_data: FeatureContractData = test_contract.into();
Expand All @@ -468,7 +466,7 @@ fn test_tx_info(
let mut state =
test_state_ex(&ChainInfo::create_for_testing(), Fee(0), &[(test_contract_data, 1)]);
let mut version = felt!(3_u8);
let mut expected_version = if v1_bound_account { felt!(1_u8) } else { version };
let mut expected_version = if v1_bound_account && !high_tip { felt!(1_u8) } else { version };
if only_query {
let simulate_version_base = *QUERY_VERSION_BASE;
version += simulate_version_base;
Expand All @@ -492,7 +490,12 @@ fn test_tx_info(
calldata: expected_tx_info,
..trivial_external_entry_point_new(test_contract)
};
let tx_info = TransactionInfo::Deprecated(DeprecatedTransactionInfo {

// Transaction tip.
let tip = Tip(VersionedConstants::latest_constants().os_constants.v1_bound_accounts_max_tip.0
+ if high_tip { 1 } else { 0 });

let tx_info = TransactionInfo::Current(CurrentTransactionInfo {
common_fields: CommonAccountFields {
transaction_hash: tx_hash,
version: TransactionVersion::THREE,
Expand All @@ -501,7 +504,8 @@ fn test_tx_info(
only_query,
..Default::default()
},
max_fee,
tip,
..CurrentTransactionInfo::create_for_testing()
});
let limit_steps_by_resources = false; // Do not limit steps by resources as we use default reasources.
let result = entry_point_call
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ use crate::execution::hint_code;
use crate::execution::syscalls::hint_processor::{EmitEventError, SyscallUsageMap};
use crate::state::errors::StateError;
use crate::state::state_api::State;
use crate::transaction::objects::TransactionInfo;

#[derive(Debug, Error)]
pub enum DeprecatedSyscallExecutionError {
Expand Down Expand Up @@ -332,11 +333,19 @@ impl<'a> DeprecatedSyscallHintProcessor<'a> {
// the syscall should return transaction version 1 instead.
// In such a case, `self.tx_info_start_ptr` is not used.
if version == TransactionVersion::THREE && v1_bound_accounts.contains(&self.class_hash) {
let modified_version = signed_tx_version(
&TransactionVersion::ONE,
&TransactionOptions { only_query: tx_context.tx_info.only_query() },
);
return self.allocate_tx_info_segment(vm, Some(modified_version));
let tip = match &tx_context.tx_info {
TransactionInfo::Current(transaction_info) => transaction_info.tip,
TransactionInfo::Deprecated(_) => {
panic!("Transaction info variant doesn't match transaction version")
}
};
if tip <= versioned_constants.os_constants.v1_bound_accounts_max_tip {
let modified_version = signed_tx_version(
&TransactionVersion::ONE,
&TransactionOptions { only_query: tx_context.tx_info.only_query() },
);
return self.allocate_tx_info_segment(vm, Some(modified_version));
}
}

match self.tx_info_start_ptr {
Expand Down
21 changes: 15 additions & 6 deletions crates/blockifier/src/execution/syscalls/syscall_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use crate::execution::syscalls::hint_processor::{
};
use crate::state::state_api::State;
use crate::transaction::account_transaction::is_cairo1;
use crate::transaction::objects::TransactionInfo;

pub type SyscallResult<T> = Result<T, SyscallExecutionError>;
pub const KECCAK_FULL_RATE_IN_WORDS: usize = 17;
Expand Down Expand Up @@ -192,13 +193,21 @@ impl<'state> SyscallHandlerBase<'state> {
// If the transaction version is 3 and the account is in the v1-bound-accounts set,
// the syscall should return transaction version 1 instead.
if version == TransactionVersion::THREE && v1_bound_accounts.contains(class_hash) {
signed_tx_version(
&TransactionVersion::ONE,
&TransactionOptions { only_query: tx_context.tx_info.only_query() },
)
} else {
tx_context.tx_info.signed_version()
let tip = match &tx_context.tx_info {
TransactionInfo::Current(transaction_info) => transaction_info.tip,
TransactionInfo::Deprecated(_) => {
panic!("Transaction info variant doesn't match transaction version")
}
};
if tip <= versioned_constants.os_constants.v1_bound_accounts_max_tip {
return signed_tx_version(
&TransactionVersion::ONE,
&TransactionOptions { only_query: tx_context.tx_info.only_query() },
);
}
}

tx_context.tx_info.signed_version()
}

pub fn emit_event(&mut self, event: EventContent) -> SyscallResult<()> {
Expand Down
Loading

0 comments on commit 78dacc5

Please sign in to comment.