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

Commit

Permalink
Braavos fix (#1356)
Browse files Browse the repository at this point in the history
Co-authored-by: lanaivina <[email protected]>
Co-authored-by: Lana Ivina <[email protected]>
Co-authored-by: d-roak <[email protected]>
  • Loading branch information
4 people authored Jan 10, 2024
1 parent bd1898a commit 933d5e3
Show file tree
Hide file tree
Showing 36 changed files with 248 additions and 121 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/configs-verifier.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
genesis-docs:
name: Genesis documentation
runs-on: ubuntu-latest
if: ${{ github.event.label.name != 'ignore-docs' }}
if: startsWith(github.event.ref, 'refs/tags/ignore-docs')
steps:
- uses: actions/checkout@v3
with:
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/madara-commands.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ jobs:
with:
path: |
target/release/madara
configs
key:
${{ runner.os }}-cargo-${{ hashFiles('Cargo.lock') }}-${{
github.run_id }}
Expand All @@ -24,10 +23,10 @@ jobs:
target/release/madara setup --chain local --from-local=configs
- name: Create build-spec (plain)
run: |
target/release/madara build-spec --chain local > chain-plain.json
RUST_LOG=debug target/release/madara build-spec --chain local > chain-plain.json
- name: Create build-spec (raw)
run: |
target/release/madara build-spec --chain chain-plain.json --raw > chain-raw.json
RUST_LOG=debug target/release/madara build-spec --chain chain-plain.json --raw > chain-raw.json
- name: Generate Sr25519 key for Aura (Leader Election)
id: key-gen
run: |
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/rust-build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ jobs:
with:
path: |
target/release/madara
configs
key:
${{ runner.os }}-cargo-${{ hashFiles('Cargo.lock') }}-${{
github.run_id }}
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/starknet-js-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ jobs:
with:
path: |
target/release/madara
configs
key:
${{ runner.os }}-cargo-${{ hashFiles('Cargo.lock') }}-${{
github.run_id }}
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/starknet-rpc-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ jobs:
with:
path: |
target/release/madara
configs
key:
${{ runner.os }}-cargo-${{ hashFiles('Cargo.lock') }}-${{
github.run_id }}
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Next release

- fix: decouple is_query into is_query and offset_version
- feat: add sierra to casm class hash mapping to genesis assets
- chore: remove ArgentMulticall from genesis assets
- feat: remove `seq_addr_updated` from `GenesisData`
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

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

24 changes: 12 additions & 12 deletions configs/genesis-assets/genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,35 +143,35 @@
"contract_address": "0x1",
"class_hash": "0x0279d77db761fba82e0054125a6fdb5f6baa6286fa3fb73450cc44d193c2d37f",
"name": "No Validation Account",
"private_key": null
"private_key": null,
"public_key": "0x0"
},
{
"contract_address": "0x2",
"class_hash": "0x06f0d6f6ae72e1a507ff4b65181291642889742dbf8f1a53e9ec1c595d01ba7d",
"name": "Argent Account",
"private_key": [
48, 120, 48, 48, 99, 49, 99, 102, 49, 52, 57, 48, 100, 101, 49, 51, 53,
50, 56, 54, 53, 51, 48, 49, 98, 98, 56, 55, 48, 53, 49, 52, 51, 102, 51,
101, 102, 57, 51, 56, 102, 57, 55, 102, 100, 102, 56, 57, 50, 102, 49,
48, 57, 48, 100, 99, 98, 53, 97, 99, 55, 98, 99, 100, 49, 100
]
0, 193, 207, 20, 144, 222, 19, 82, 134, 83, 1, 187, 135, 5, 20, 63, 62,
249, 56, 249, 127, 223, 137, 47, 16, 144, 220, 181, 172, 123, 205, 29
],
"public_key": "0x3603a2692a2ae60abb343e832ee53b55d6b25f02a3ef1565ec691edc7a209b2"
},
{
"contract_address": "0x3",
"class_hash": "0x006280083f8c2a2db9f737320d5e3029b380e0e820fe24b8d312a6a34fdba0cd",
"name": "Openzeppelin Account",
"private_key": [
48, 120, 48, 48, 99, 49, 99, 102, 49, 52, 57, 48, 100, 101, 49, 51, 53,
50, 56, 54, 53, 51, 48, 49, 98, 98, 56, 55, 48, 53, 49, 52, 51, 102, 51,
101, 102, 57, 51, 56, 102, 57, 55, 102, 100, 102, 56, 57, 50, 102, 49,
48, 57, 48, 100, 99, 98, 53, 97, 99, 55, 98, 99, 100, 49, 100
]
0, 193, 207, 20, 144, 222, 19, 82, 134, 83, 1, 187, 135, 5, 20, 63, 62,
249, 56, 249, 127, 223, 137, 47, 16, 144, 220, 181, 172, 123, 205, 29
],
"public_key": "0x3603a2692a2ae60abb343e832ee53b55d6b25f02a3ef1565ec691edc7a209b2"
},
{
"contract_address": "0x4",
"class_hash": "0x02f99bf9799ada84cd5ac0d0fe36b9d8f65efcb377cd2e8cf8309ad2daf15e4b",
"name": "No Validation Account (cairo 1)",
"private_key": null
"private_key": null,
"public_key": "0x0"
}
],
"storage": [
Expand Down
2 changes: 1 addition & 1 deletion configs/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
},
{
"name": "genesis.json",
"md5": "eb71ae350b3165a08524a7f0170402b4"
"md5": "8b36630988032b77d747b389080175ff"
},
{
"name": "NoValidateAccount.casm.json",
Expand Down
12 changes: 0 additions & 12 deletions crates/client/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -937,18 +937,6 @@ where
request: Vec<BroadcastedTransaction>,
block_id: BlockId,
) -> RpcResult<Vec<FeeEstimate>> {
let is_query = request.iter().any(|tx| match tx {
BroadcastedTransaction::Invoke(invoke_tx) => invoke_tx.is_query,
BroadcastedTransaction::Declare(BroadcastedDeclareTransaction::V1(tx_v1)) => tx_v1.is_query,
BroadcastedTransaction::Declare(BroadcastedDeclareTransaction::V2(tx_v2)) => tx_v2.is_query,
BroadcastedTransaction::DeployAccount(deploy_tx) => deploy_tx.is_query,
});
if !is_query {
log::error!(
"Got `is_query`: false. In a future version, this will fail fee estimation with UnsupportedTxVersion"
);
}

let substrate_block_hash = self.substrate_block_hash_from_starknet_block(block_id).map_err(|e| {
error!("'{e}'");
StarknetRpcApiError::BlockNotFound
Expand Down
7 changes: 7 additions & 0 deletions crates/pallets/starknet/src/execution_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ impl RuntimeExecutionConfigBuilder {
disable_validation: false,
disable_nonce_validation: T::DisableNonceValidation::get(),
disable_transaction_fee: T::DisableTransactionFee::get(),
offset_version: false,
})
}
#[must_use]
Expand All @@ -31,6 +32,12 @@ impl RuntimeExecutionConfigBuilder {
self
}

#[must_use]
pub fn with_offset_version(mut self) -> Self {
self.0.offset_version = true;
self
}

pub fn build(self) -> ExecutionConfig {
self.0
}
Expand Down
4 changes: 2 additions & 2 deletions crates/pallets/starknet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,7 @@ impl<T: Config> Pallet<T> {
&transactions,
&Self::get_block_context(),
chain_id,
&RuntimeExecutionConfigBuilder::new::<T>().with_query_mode().build(),
&mut RuntimeExecutionConfigBuilder::new::<T>().with_query_mode().build(),
)?;

let mut results = vec![];
Expand Down Expand Up @@ -1122,7 +1122,7 @@ impl<T: Config> Pallet<T> {
&transactions,
&Self::get_block_context(),
chain_id,
&RuntimeExecutionConfigBuilder::new::<T>().with_simulation_mode(&simulation_flags).build(),
&mut RuntimeExecutionConfigBuilder::new::<T>().with_simulation_mode(&simulation_flags).build(),
)?;

fn get_function_invocation(
Expand Down
1 change: 1 addition & 0 deletions crates/pallets/starknet/src/tests/call_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ fn given_call_contract_call_works() {
nonce: Felt252Wrapper::ZERO,
calldata: constructor_calldata,
max_fee: u128::MAX,
offset_version: false,
};

assert_ok!(Starknet::invoke(origin, deploy_transaction.into()));
Expand Down
6 changes: 6 additions & 0 deletions crates/pallets/starknet/src/tests/declare_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ fn given_contract_declare_tx_works_once_not_twice() {
nonce: Felt252Wrapper::ZERO,
max_fee: u128::MAX,
signature: vec![],
offset_version: false,
};

assert_ok!(Starknet::declare(none_origin.clone(), transaction.clone().into(), erc20_class.clone()));
Expand Down Expand Up @@ -67,6 +68,7 @@ fn given_contract_declare_tx_fails_sender_not_deployed() {
nonce: Felt252Wrapper::ZERO,
max_fee: u128::MAX,
signature: vec![],
offset_version: false,
};

assert_err!(
Expand Down Expand Up @@ -116,6 +118,7 @@ fn given_contract_declare_on_openzeppelin_account_with_incorrect_signature_then_
nonce: Felt252Wrapper::ZERO,
class_hash: erc20_class_hash,
sender_address: account_addr.into(),
offset_version: false,
};

assert_matches!(
Expand Down Expand Up @@ -174,6 +177,7 @@ fn given_contract_declare_on_braavos_account_with_incorrect_signature_then_it_fa
nonce: Felt252Wrapper::ZERO,
class_hash: erc20_class_hash,
sender_address: account_addr.into(),
offset_version: false,
};

assert_matches!(
Expand Down Expand Up @@ -232,6 +236,7 @@ fn given_contract_declare_on_argent_account_with_incorrect_signature_then_it_fai
nonce: Felt252Wrapper::ZERO,
class_hash: erc20_class_hash,
sender_address: account_addr.into(),
offset_version: false,
};

assert_matches!(
Expand Down Expand Up @@ -270,6 +275,7 @@ fn given_contract_declare_on_cairo_1_no_validate_account_then_it_works() {
nonce: Felt252Wrapper::ZERO,
max_fee: u128::MAX,
signature: vec![],
offset_version: false,
};

let chain_id = Starknet::chain_id();
Expand Down
10 changes: 10 additions & 0 deletions crates/pallets/starknet/src/tests/deploy_account_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ fn given_contract_run_deploy_account_tx_works() {
contract_address_salt: salt,
constructor_calldata: calldata.0.iter().map(|e| Felt252Wrapper::from(*e)).collect(),
class_hash: account_class_hash.into(),
offset_version: false,
};

let address = deploy_tx.account_address().into();
Expand Down Expand Up @@ -76,6 +77,7 @@ fn given_contract_run_deploy_account_tx_twice_fails() {
contract_address_salt: *SALT,
constructor_calldata: calldata.0.iter().map(|e| Felt252Wrapper::from(*e)).collect(),
class_hash: account_class_hash.into(),
offset_version: false,
};

let address = deploy_tx.account_address().into();
Expand Down Expand Up @@ -104,6 +106,7 @@ fn given_contract_run_deploy_account_tx_undeclared_then_it_fails() {
nonce: Felt252Wrapper::ZERO,
max_fee: u128::MAX,
signature: vec![],
offset_version: false,
};

assert_err!(
Expand Down Expand Up @@ -146,6 +149,7 @@ fn given_contract_run_deploy_account_openzeppelin_tx_works() {
contract_address_salt: *SALT,
constructor_calldata: calldata.0.iter().map(|e| Felt252Wrapper::from(*e)).collect(),
class_hash: account_class_hash.into(),
offset_version: false,
};

let chain_id = Starknet::chain_id();
Expand Down Expand Up @@ -176,6 +180,7 @@ fn given_contract_run_deploy_account_openzeppelin_with_incorrect_signature_then_
contract_address_salt: *SALT,
constructor_calldata: calldata.0.iter().map(|e| Felt252Wrapper::from(*e)).collect(),
class_hash: account_class_hash.into(),
offset_version: false,
};
deploy_tx.signature = vec![Felt252Wrapper::ONE, Felt252Wrapper::ONE];

Expand All @@ -202,6 +207,7 @@ fn given_contract_run_deploy_account_argent_tx_works() {
contract_address_salt: *SALT,
constructor_calldata: calldata.0.iter().map(|e| Felt252Wrapper::from(*e)).collect(),
class_hash: account_class_hash.into(),
offset_version: false,
};

let chain_id = Starknet::chain_id();
Expand Down Expand Up @@ -232,6 +238,7 @@ fn given_contract_run_deploy_account_argent_with_incorrect_signature_then_it_fai
contract_address_salt: *SALT,
constructor_calldata: calldata.0.iter().map(|e| Felt252Wrapper::from(*e)).collect(),
class_hash: account_class_hash.into(),
offset_version: false,
};

deploy_tx.signature = vec![Felt252Wrapper::ONE, Felt252Wrapper::ONE];
Expand Down Expand Up @@ -261,6 +268,7 @@ fn given_contract_run_deploy_account_braavos_tx_works() {
contract_address_salt: *SALT,
constructor_calldata: calldata,
class_hash: proxy_class_hash.into(),
offset_version: false,
};

let tx_hash = deploy_tx.compute_hash::<<MockRuntime as Config>::SystemHash>(Starknet::chain_id(), false);
Expand Down Expand Up @@ -293,6 +301,7 @@ fn given_contract_run_deploy_account_braavos_tx_works_whis_hardware_signer() {
contract_address_salt: *SALT,
constructor_calldata: calldata,
class_hash: proxy_class_hash.into(),
offset_version: false,
};

let tx_hash = deploy_tx.compute_hash::<<MockRuntime as Config>::SystemHash>(Starknet::chain_id(), false);
Expand Down Expand Up @@ -341,6 +350,7 @@ fn given_contract_run_deploy_account_braavos_with_incorrect_signature_then_it_fa
nonce: Felt252Wrapper::ZERO,
max_fee: u128::MAX,
signature: [Felt252Wrapper::ZERO; 10].to_vec(),
offset_version: false,
};

let address = deploy_tx.account_address().into();
Expand Down
1 change: 1 addition & 0 deletions crates/pallets/starknet/src/tests/erc20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ fn given_erc20_transfer_when_invoke_then_it_works() {
Felt252Wrapper::from_hex_be("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF").unwrap(), // Initial supply high
felt_252_sender_account, // recipient
],
offset_version: false,
};

let expected_erc20_address =
Expand Down
1 change: 1 addition & 0 deletions crates/pallets/starknet/src/tests/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ fn internal_and_external_events_are_emitted_in_the_right_order() {
nonce: Felt252Wrapper::ZERO,
max_fee: u128::MAX,
signature: vec![],
offset_version: false,
};

let none_origin = RuntimeOrigin::none();
Expand Down
5 changes: 5 additions & 0 deletions crates/pallets/starknet/src/tests/invoke_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ fn given_hardcoded_contract_run_invoke_tx_fails_sender_not_deployed() {
nonce: Felt252Wrapper::ZERO,
max_fee: u128::MAX,
signature: vec![],
offset_version: false,
};

assert_err!(Starknet::invoke(none_origin, transaction.into()), Error::<MockRuntime>::AccountNotDeployed);
Expand Down Expand Up @@ -171,6 +172,7 @@ fn given_hardcoded_contract_run_invoke_tx_then_multiple_events_is_emitted() {
nonce: Felt252Wrapper::ZERO,
max_fee: u128::MAX,
signature: vec![],
offset_version: false,
};

let none_origin = RuntimeOrigin::none();
Expand All @@ -197,6 +199,7 @@ fn given_hardcoded_contract_run_invoke_tx_then_multiple_events_is_emitted() {
nonce: Felt252Wrapper::ONE,
max_fee: u128::MAX,
signature: vec![],
offset_version: false,
};

let none_origin = RuntimeOrigin::none();
Expand Down Expand Up @@ -425,6 +428,7 @@ fn given_account_not_deployed_invoke_tx_works_for_nonce_one() {
nonce: Felt252Wrapper::ONE,
max_fee: u128::MAX,
signature: vec![],
offset_version: false,
};

assert_ok!(Starknet::validate_unsigned(
Expand All @@ -448,6 +452,7 @@ fn given_account_not_deployed_invoke_tx_fails_for_nonce_not_one() {
nonce: Felt252Wrapper::TWO,
max_fee: u128::MAX,
signature: vec![],
offset_version: false,
};

assert_eq!(
Expand Down
3 changes: 2 additions & 1 deletion crates/pallets/starknet/src/tests/mock/genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@
"0x02356b628d108863baf8644c945d97bad70190af5957031f4852d00d0f690a77",
"0x03bcec8de953ba8e305e2ce2db52c91504aefa7c56c91211873b4d6ba36e8c32",
"No validation account",
null
null,
""
]
],
"storage": [
Expand Down
Loading

0 comments on commit 933d5e3

Please sign in to comment.