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

Execute L1Handler transactions using the RpcState #1103

Merged
merged 66 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
c22eb56
Add test case
fmoletta Oct 18, 2023
855d516
Fix get_onchain_data_segment_length
fmoletta Oct 18, 2023
d163fdb
Debug setup
fmoletta Oct 18, 2023
ced01c4
Fix get_onchain_data_segment_length
fmoletta Oct 18, 2023
1e7efff
Add StorageChangesCount struct
fmoletta Oct 18, 2023
2347431
Update test values
fmoletta Oct 18, 2023
ac56f81
Update test values
fmoletta Oct 19, 2023
cc55c5c
Merge branch 'fix-get_onchain_data_segment_length' into fix-count_act…
fmoletta Oct 19, 2023
5d2e5e3
fmt
fmoletta Oct 19, 2023
ba8cf16
Merge branch 'fix-get_onchain_data_segment_length' into fix-count_act…
fmoletta Oct 19, 2023
0df3007
Use StorageChangesCount struct in state method
fmoletta Oct 19, 2023
fed2162
Fix implicated code
fmoletta Oct 19, 2023
413dfa1
Update doc
fmoletta Oct 19, 2023
d680546
Update test values
fmoletta Oct 19, 2023
6a2bd15
Rename method for consistency
fmoletta Oct 19, 2023
94804d2
Add note comment
fmoletta Oct 19, 2023
5ae787e
Remove hardcoded contract address
fmoletta Oct 19, 2023
e75750b
Remove txt files
fmoletta Oct 19, 2023
7ddad62
Remove dbg prints
fmoletta Oct 19, 2023
c70a509
Remove dbg prints
fmoletta Oct 19, 2023
14576a6
Format
fmoletta Oct 19, 2023
bc06dbd
Restore blockifier version
fmoletta Oct 19, 2023
11f9f00
Restore tests
fmoletta Oct 19, 2023
52fb298
Restore newlines
fmoletta Oct 19, 2023
b0673c4
Restore newlines
fmoletta Oct 19, 2023
c82c682
Remove txt file
fmoletta Oct 19, 2023
0a517fc
Merge branch 'main' of github.com:lambdaclass/starknet_in_rust into r…
fmoletta Oct 19, 2023
fd99568
Merge remote-tracking branch 'origin/fix-count_actual_storage_changes…
fmoletta Oct 19, 2023
3a0b7fe
fmt
fmoletta Oct 19, 2023
d2bbe9b
Merge branch 'main' into fix-get_onchain_data_segment_length
fmoletta Oct 19, 2023
1bfa497
Merge branch 'fix-get_onchain_data_segment_length' into fix-count_act…
fmoletta Oct 19, 2023
f6295c9
Merge branch 'fix-count_actual_storage_changes' into rpc-state-reader…
fmoletta Oct 19, 2023
882b751
Merge branch 'main' into fix-get_onchain_data_segment_length
juanbono Oct 23, 2023
620abe3
Add test case with declare
fmoletta Oct 23, 2023
0fb938d
Deserialize Declare transactions
fmoletta Oct 23, 2023
f2a164c
Create blockifier Declare transaction
fmoletta Oct 23, 2023
41c09cd
Fix/Refactor `State::count actual storage changes` (#1086)
fmoletta Oct 23, 2023
2fed600
Add the ability to execute `DeployAccount` transactions using the `Rp…
fmoletta Oct 23, 2023
bff5b45
fetch class hash from the next block in declare tx
fmoletta Oct 23, 2023
219633d
Return an error if a class_hash is not declared + add tests for decla…
fmoletta Oct 23, 2023
3422eec
Fix error msg
fmoletta Oct 23, 2023
fb5f2b4
Add support for DeclareV0-1 in sir_tests
fmoletta Oct 23, 2023
e26aa30
Make Sierra class optional in declare v2 + other changes
fmoletta Oct 23, 2023
6a70c11
Add support for DeclareV2
fmoletta Oct 23, 2023
bf55785
Uncomment test
fmoletta Oct 23, 2023
5893af0
fix
fmoletta Oct 23, 2023
200e8de
Use new_with_sierra_class_hash_and_tx_hash
fmoletta Oct 24, 2023
2fefb3d
use CompiledClassHash instead of CompiledClass where applicatble
fmoletta Oct 24, 2023
dc60e6b
Handle nonce in declare v2 + run fmt
fmoletta Oct 24, 2023
163e7ca
Set casm class before counting state changes in declare v2
fmoletta Oct 24, 2023
35154ff
Changes
fmoletta Oct 24, 2023
ab0a4f3
Make sierra class hash non-optional
fmoletta Oct 24, 2023
cd010fd
fix + clippy
fmoletta Oct 24, 2023
debc149
Merge branch 'main' of github.com:lambdaclass/starknet_in_rust into f…
fmoletta Oct 24, 2023
2ba0145
Use state_reader instead of creating a state to fetch the next block …
fmoletta Oct 24, 2023
6e3dc4c
Merge remote-tracking branch 'origin/fix-get_onchain_data_segment_len…
fmoletta Oct 24, 2023
3c5f3cf
Add removed test
fmoletta Oct 24, 2023
5d2a42f
Update test values
fmoletta Oct 24, 2023
d1245e2
Merge branch 'main' of github.com:lambdaclass/starknet_in_rust into r…
fmoletta Oct 24, 2023
7aeefc7
Make validate_invocation and fee_transfer_info fields optional + add …
fmoletta Oct 25, 2023
b4e016d
Add L1Handler to blockifier_tests::execute_tx
fmoletta Oct 25, 2023
621b962
Add blockifier test case
fmoletta Oct 25, 2023
05ef718
Add L1Handler to sir_tests::execute_tx
fmoletta Oct 25, 2023
959b202
Add one more test case
fmoletta Oct 25, 2023
6c9f643
fmt
fmoletta Oct 25, 2023
210c453
Merge branch 'main' of github.com:lambdaclass/starknet_in_rust into r…
fmoletta Oct 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 35 additions & 8 deletions rpc_state_reader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ mod tests {
);

assert_eq!(
tx_trace.validate_invocation.calldata,
tx_trace.validate_invocation.as_ref().unwrap().calldata,
Some(vec![
stark_felt!("1"),
stark_felt!("690c876e61beda61e994543af68038edac4e1cb1990ab06e52a2d27e56a1232"),
Expand All @@ -157,9 +157,16 @@ mod tests {
stark_felt!("38bd34c31a0a5c"),
])
);
assert_eq!(tx_trace.validate_invocation.retdata, Some(vec![]));
assert_eq!(
tx_trace.validate_invocation.as_ref().unwrap().retdata,
Some(vec![])
);
assert_eq_sorted!(
tx_trace.validate_invocation.execution_resources,
tx_trace
.validate_invocation
.as_ref()
.unwrap()
.execution_resources,
ExecutionResources {
n_steps: 790,
n_memory_holes: 51,
Expand All @@ -170,7 +177,15 @@ mod tests {
]),
}
);
assert_eq!(tx_trace.validate_invocation.internal_calls.len(), 1);
assert_eq!(
tx_trace
.validate_invocation
.as_ref()
.unwrap()
.internal_calls
.len(),
1
);

assert_eq!(
tx_trace.function_invocation.as_ref().unwrap().calldata,
Expand Down Expand Up @@ -243,19 +258,23 @@ mod tests {
);

assert_eq!(
tx_trace.fee_transfer_invocation.calldata,
tx_trace.fee_transfer_invocation.as_ref().unwrap().calldata,
Some(vec![
stark_felt!("1176a1bd84444c89232ec27754698e5d2e7e1a7f1539f12027f28b23ec9f3d8"),
stark_felt!("2b0322a23ba4"),
stark_felt!("0"),
])
);
assert_eq!(
tx_trace.fee_transfer_invocation.retdata,
tx_trace.fee_transfer_invocation.as_ref().unwrap().retdata,
Some(vec![1u128.into()])
);
assert_eq_sorted!(
tx_trace.fee_transfer_invocation.execution_resources,
tx_trace
.fee_transfer_invocation
.as_ref()
.unwrap()
.execution_resources,
ExecutionResources {
n_steps: 586,
n_memory_holes: 42,
Expand All @@ -265,7 +284,15 @@ mod tests {
]),
}
);
assert_eq!(tx_trace.fee_transfer_invocation.internal_calls.len(), 1);
assert_eq!(
tx_trace
.fee_transfer_invocation
.as_ref()
.unwrap()
.internal_calls
.len(),
1
);
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions rpc_state_reader/src/rpc_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ pub struct RpcResponse<T> {

#[derive(Debug, Deserialize, Clone, Eq, PartialEq)]
pub struct TransactionTrace {
pub validate_invocation: RpcCallInfo,
pub validate_invocation: Option<RpcCallInfo>,
pub function_invocation: Option<RpcCallInfo>,
pub fee_transfer_invocation: RpcCallInfo,
pub fee_transfer_invocation: Option<RpcCallInfo>,
pub signature: Vec<StarkFelt>,
pub revert_error: Option<String>,
}
Expand Down
1 change: 1 addition & 0 deletions rpc_state_reader/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ pub fn deserialize_transaction_json(
"unimplemented declare version: {x}"
))),
},
"L1_HANDLER" => Ok(Transaction::L1Handler(serde_json::from_value(transaction)?)),
x => Err(serde::de::Error::custom(format!(
"unimplemented transaction type deserialization: {x}"
))),
Expand Down
30 changes: 29 additions & 1 deletion rpc_state_reader/tests/blockifier_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ use blockifier::{
transaction::{
account_transaction::AccountTransaction,
objects::TransactionExecutionInfo,
transactions::{DeclareTransaction, DeployAccountTransaction, ExecutableTransaction},
transactions::{
DeclareTransaction, DeployAccountTransaction, ExecutableTransaction,
L1HandlerTransaction,
},
},
};
use blockifier::{
Expand Down Expand Up @@ -207,6 +210,21 @@ pub fn execute_tx(
let declare = DeclareTransaction::new(tx, tx_hash, contract_class).unwrap();
AccountTransaction::Declare(declare)
}
SNTransaction::L1Handler(tx) => {
// As L1Hanlder is not an account transaction we execute it here and return the result
let blockifier_tx = L1HandlerTransaction {
tx,
tx_hash,
paid_fee_on_l1: starknet_api::transaction::Fee(u128::MAX),
};
return (
blockifier_tx
.execute(&mut state, &block_context, true, true)
.unwrap(),
trace,
receipt,
);
}
_ => unimplemented!(),
};

Expand Down Expand Up @@ -327,6 +345,16 @@ fn blockifier_test_recent_tx() {
281513, // real block 281514
RpcChain::MainNet
)]
#[test_case(
"0x26be3e906db66973de1ca5eec1ddb4f30e3087dbdce9560778937071c3d3a83",
351268, // real block 351269
RpcChain::MainNet
)]
#[test_case(
"0x4f552c9430bd21ad300db56c8f4cae45d554a18fac20bf1703f180fac587d7e",
351225, // real block 351226
RpcChain::MainNet
)]
// DeployAccount for different account providers (as of October 2023):
// All of them were deployed on testnet using starkli
// OpenZeppelin (v0.7.0)
Expand Down
19 changes: 18 additions & 1 deletion rpc_state_reader/tests/sir_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use starknet_in_rust::{
state_cache::StorageEntry,
BlockInfo,
},
transaction::{Declare, DeclareV2, DeployAccount, InvokeFunction},
transaction::{Declare, DeclareV2, DeployAccount, InvokeFunction, L1Handler},
utils::{Address, ClassHash},
};

Expand Down Expand Up @@ -208,6 +208,13 @@ pub fn execute_tx_configurable(
declare.create_for_simulation(skip_validate, false, false, false)
}
}
SNTransaction::L1Handler(tx) => L1Handler::from_sn_api_tx(
tx,
Felt252::from_bytes_be(tx_hash.0.bytes()),
Some(Felt252::from(u128::MAX)),
)
.unwrap()
.create_for_simulation(skip_validate, false),
_ => unimplemented!(),
};

Expand Down Expand Up @@ -352,6 +359,16 @@ fn test_get_gas_price() {
281513, // real block 281514
RpcChain::MainNet
)]
#[test_case(
"0x26be3e906db66973de1ca5eec1ddb4f30e3087dbdce9560778937071c3d3a83",
351268, // real block 351269
RpcChain::MainNet
)]
#[test_case(
"0x4f552c9430bd21ad300db56c8f4cae45d554a18fac20bf1703f180fac587d7e",
351225, // real block 351226
RpcChain::MainNet
)]
// DeployAccount for different account providers (as of October 2023):
// All of them were deployed on testnet using starkli
// OpenZeppelin (v0.7.0)
Expand Down
27 changes: 22 additions & 5 deletions src/transaction/l1_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,7 @@ impl L1Handler {
}

/// Creates a L1Handler for simulation purposes.
pub(crate) fn create_for_simulation(
&self,
skip_validate: bool,
skip_execute: bool,
) -> Transaction {
pub fn create_for_simulation(&self, skip_validate: bool, skip_execute: bool) -> Transaction {
let tx = L1Handler {
skip_validate,
skip_execute,
Expand All @@ -213,6 +209,27 @@ impl L1Handler {

Transaction::L1Handler(tx)
}

/// Creates a `L1Handler` from a starknet api `L1HandlerTransaction`.
pub fn from_sn_api_tx(
tx: starknet_api::transaction::L1HandlerTransaction,
tx_hash: Felt252,
paid_fee_on_l1: Option<Felt252>,
) -> Result<Self, TransactionError> {
L1Handler::new_with_tx_hash(
Address(Felt252::from_bytes_be(tx.contract_address.0.key().bytes())),
Felt252::from_bytes_be(tx.entry_point_selector.0.bytes()),
tx.calldata
.0
.as_ref()
.iter()
.map(|f| Felt252::from_bytes_be(f.bytes()))
.collect(),
Felt252::from_bytes_be(tx.nonce.0.bytes()),
paid_fee_on_l1,
tx_hash,
)
}
}

#[cfg(test)]
Expand Down