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

Commit

Permalink
chore: update cairo vm commit and gas fees (#1467)
Browse files Browse the repository at this point in the history
  • Loading branch information
apoorvsadana authored Feb 26, 2024
1 parent 0f49322 commit 026f7a9
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 33 deletions.
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

- chore: update cairo-vm commit and update gas per op
- refactor(rpc): use single arc instance of starknet rpc
- build: remove patch on `ring-vrf` dependecy
- ci: use `production` profile binary in the workflows
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion crates/pallets/starknet/src/tests/deploy_account_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fn given_contract_run_deploy_account_tx_works() {
data: EventData(vec![
address.0.0, // From
StarkFelt::try_from("0xdead").unwrap(), // To
StarkFelt::try_from("0x195a").unwrap(), // Amount low
StarkFelt::try_from("0x18a6").unwrap(), // Amount low
StarkFelt::from(0u128), // Amount high
]),
},
Expand Down
4 changes: 2 additions & 2 deletions crates/pallets/starknet/src/tests/erc20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ fn given_erc20_transfer_when_invoke_then_it_works() {
data: EventData(vec![
sender_account.0 .0, // From
StarkFelt::try_from("0x000000000000000000000000000000000000000000000000000000000000dead").unwrap(), // Sequencer address
StarkFelt::try_from("0x00000000000000000000000000000000000000000000000000000000000198de").unwrap(), // Amount low
StarkFelt::try_from("0x00000000000000000000000000000000000000000000000000000000000197a8").unwrap(), // Amount low
StarkFelt::from(0u128), // Amount high
]),
},
Expand Down Expand Up @@ -207,7 +207,7 @@ fn given_erc20_transfer_when_invoke_then_it_works() {
data: EventData(vec![
sender_account.0 .0, // From
StarkFelt::try_from("0xdead").unwrap(), // Sequencer address
StarkFelt::try_from("0xf118").unwrap(), // Amount low
StarkFelt::try_from("0xf014").unwrap(), // Amount low
StarkFelt::from(0u128), // Amount high
]),
},
Expand Down
4 changes: 2 additions & 2 deletions crates/pallets/starknet/src/tests/invoke_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ fn given_hardcoded_contract_run_invoke_tx_then_it_works() {
StarkFelt::try_from(BLOCKIFIER_ACCOUNT_ADDRESS).unwrap(),
StarkFelt::try_from("0x000000000000000000000000000000000000000000000000000000000000dead")
.unwrap(),
StarkFelt::try_from("0x00000000000000000000000000000000000000000000000000000000000001a4")
StarkFelt::try_from("0x00000000000000000000000000000000000000000000000000000000000000d2")
.unwrap(),
StarkFelt::from(0u128),
]),
Expand Down Expand Up @@ -126,7 +126,7 @@ fn given_hardcoded_contract_run_invoke_tx_then_event_is_emitted() {
data: EventData(vec![
StarkFelt::try_from("0x01a3339ec92ac1061e3e0f8e704106286c642eaf302e94a582e5f95ef5e6b4d0").unwrap(), // From
StarkFelt::try_from("0xdead").unwrap(), // To
StarkFelt::try_from("0x1a4").unwrap(), // Amount low
StarkFelt::try_from("0xd2").unwrap(), // Amount low
StarkFelt::from(0u128), // Amount high
]),
},
Expand Down
32 changes: 17 additions & 15 deletions crates/primitives/fee/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@ pub const FEE_TRANSFER_N_STORAGE_CHANGES: u8 = 2; // Sender and sequencer balanc
/// Number of storage updates to actually charge for the fee transfer tx.
pub const FEE_TRANSFER_N_STORAGE_CHANGES_TO_CHARGE: u8 = FEE_TRANSFER_N_STORAGE_CHANGES - 1; // Exclude the sequencer balance update, since it's charged once throughout the batch.

pub static VM_RESOURCE_FEE_COSTS: [(&str, FixedU128); 7] = [
("n_steps", FixedU128::from_inner(10_000_000_000_000_000)),
("pedersen_builtin", FixedU128::from_inner(320_000_000_000_000_000)),
("range_check_builtin", FixedU128::from_inner(160_000_000_000_000_000)),
("ecdsa_builtin", FixedU128::from_inner(20_480_000_000_000_000_000)),
("bitwise_builtin", FixedU128::from_inner(640_000_000_000_000_000)),
("poseidon_builtin", FixedU128::from_inner(320_000_000_000_000_000)),
("ec_op_builtin", FixedU128::from_inner(10_240_000_000_000_000_000)),
pub static VM_RESOURCE_FEE_COSTS: [(&str, FixedU128); 8] = [
("n_steps", FixedU128::from_inner(5_000_000_000_000_000)),
("pedersen_builtin", FixedU128::from_inner(160_000_000_000_000_000)),
("range_check_builtin", FixedU128::from_inner(80_000_000_000_000_000)),
("ecdsa_builtin", FixedU128::from_inner(10_240_000_000_000_000_000)),
("bitwise_builtin", FixedU128::from_inner(320_000_000_000_000_000)),
("poseidon_builtin", FixedU128::from_inner(160_000_000_000_000_000)),
("ec_op_builtin", FixedU128::from_inner(5_120_000_000_000_000_000)),
("keccak_builtin", FixedU128::from_inner(5_120_000_000_000_000_000)),
];

pub const TRANSFER_SELECTOR_NAME: &str = "Transfer";
Expand Down Expand Up @@ -237,12 +238,13 @@ mod vm_resource_fee_costs {
fn check_values_as_floats() {
let hm = HashMap::from(VM_RESOURCE_FEE_COSTS);

assert_eq!(hm.get("n_steps"), Some(FixedU128::from_float(0.01)).as_ref());
assert_eq!(hm.get("pedersen_builtin"), Some(FixedU128::from_float(0.32)).as_ref());
assert_eq!(hm.get("range_check_builtin"), Some(FixedU128::from_float(0.16)).as_ref());
assert_eq!(hm.get("ecdsa_builtin"), Some(FixedU128::from_float(20.48)).as_ref());
assert_eq!(hm.get("bitwise_builtin"), Some(FixedU128::from_float(0.64)).as_ref());
assert_eq!(hm.get("poseidon_builtin"), Some(FixedU128::from_float(0.32)).as_ref());
assert_eq!(hm.get("ec_op_builtin"), Some(FixedU128::from_float(10.24)).as_ref());
assert_eq!(hm.get("n_steps"), Some(FixedU128::from_float(0.005)).as_ref());
assert_eq!(hm.get("pedersen_builtin"), Some(FixedU128::from_float(0.16)).as_ref());
assert_eq!(hm.get("range_check_builtin"), Some(FixedU128::from_float(0.08)).as_ref());
assert_eq!(hm.get("ecdsa_builtin"), Some(FixedU128::from_float(10.24)).as_ref());
assert_eq!(hm.get("bitwise_builtin"), Some(FixedU128::from_float(0.32)).as_ref());
assert_eq!(hm.get("poseidon_builtin"), Some(FixedU128::from_float(0.16)).as_ref());
assert_eq!(hm.get("ec_op_builtin"), Some(FixedU128::from_float(5.12)).as_ref());
assert_eq!(hm.get("keccak_builtin"), Some(FixedU128::from_float(5.12)).as_ref());
}
}
4 changes: 2 additions & 2 deletions starknet-rpc-test/estimate_fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ async fn works_ok(madara: &ThreadSafeMadaraClient) -> Result<(), anyhow::Error>

// TODO: instead execute the tx and check that the actual fee are the same as the estimated ones
assert_eq!(estimates.len(), 2);
assert_eq!(estimates[0].overall_fee, 420);
assert_eq!(estimates[1].overall_fee, 420);
assert_eq!(estimates[0].overall_fee, 210);
assert_eq!(estimates[1].overall_fee, 210);
// https://starkscan.co/block/5
assert_eq!(estimates[0].gas_consumed, 0);
assert_eq!(estimates[1].gas_consumed, 0);
Expand Down
1 change: 1 addition & 0 deletions starknet-rpc-test/get_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ async fn fail_non_existing_class_hash(madara: &ThreadSafeMadaraClient) -> Result

#[rstest]
#[tokio::test]
#[ignore = "Waiting for issue #1469 to be solved"]
async fn work_ok_retrieving_class_for_contract_version_0(madara: &ThreadSafeMadaraClient) -> Result<(), anyhow::Error> {
let rpc = madara.get_starknet_client().await;

Expand Down
1 change: 1 addition & 0 deletions starknet-rpc-test/get_class_at.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ async fn fail_non_existing_contract(madara: &ThreadSafeMadaraClient) -> Result<(

#[rstest]
#[tokio::test]
#[ignore = "Waiting for issue #1469 to be solved"]
async fn work_ok_retrieving_class_for_contract_version_0(madara: &ThreadSafeMadaraClient) -> Result<(), anyhow::Error> {
let rpc = madara.get_starknet_client().await;

Expand Down
8 changes: 4 additions & 4 deletions starknet-rpc-test/get_transaction_receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ async fn work_with_invoke_transaction(madara: &ThreadSafeMadaraClient) -> Result

let invoke_tx_receipt = get_transaction_receipt(&rpc, rpc_response.transaction_hash).await;
let fee_token_address = FieldElement::from_hex_be(FEE_TOKEN_ADDRESS).unwrap();
let expected_fee = FieldElement::from_hex_be("0xf154").unwrap();
let expected_fee = FieldElement::from_hex_be("0xf032").unwrap();

match invoke_tx_receipt {
Ok(MaybePendingTransactionReceipt::Receipt(TransactionReceipt::Invoke(receipt))) => {
Expand Down Expand Up @@ -166,7 +166,7 @@ async fn work_with_declare_transaction(madara: &ThreadSafeMadaraClient) -> Resul

let fee_token_address = FieldElement::from_hex_be(FEE_TOKEN_ADDRESS).unwrap();
let expected_fee =
FieldElement::from_hex_be("0x00000000000000000000000000000000000000000000000000000000000030fc").unwrap();
FieldElement::from_hex_be("0x0000000000000000000000000000000000000000000000000000000000003066").unwrap();
let expected_events = vec![Event {
from_address: fee_token_address,
keys: vec![get_selector_from_name("Transfer").unwrap()],
Expand Down Expand Up @@ -272,7 +272,7 @@ async fn work_with_deploy_account_transaction(madara: &ThreadSafeMadaraClient) -

let account_deployment_tx_receipt = get_transaction_receipt(&rpc, rpc_response.transaction_hash).await;
let fee_token_address = FieldElement::from_hex_be(FEE_TOKEN_ADDRESS).unwrap();
let expected_fee = FieldElement::from_hex_be("0x790e").unwrap();
let expected_fee = FieldElement::from_hex_be("0x7850").unwrap();

match account_deployment_tx_receipt {
Ok(MaybePendingTransactionReceipt::Receipt(TransactionReceipt::DeployAccount(receipt))) => {
Expand Down Expand Up @@ -382,7 +382,7 @@ async fn ensure_transfer_fee_event_not_messed_up_with_similar_transfer(
};
let tx_receipt = get_transaction_receipt(&rpc, rpc_response.transaction_hash).await;
let fee_token_address = FieldElement::from_hex_be(FEE_TOKEN_ADDRESS).unwrap();
let expected_fee = FieldElement::from_hex_be("0xf154").unwrap();
let expected_fee = FieldElement::from_hex_be("0xf032").unwrap();

match tx_receipt {
Ok(MaybePendingTransactionReceipt::Receipt(TransactionReceipt::Invoke(mut receipt))) => {
Expand Down
10 changes: 5 additions & 5 deletions starknet-rpc-test/simulate_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ async fn works_ok_on_no_validate(madara: &ThreadSafeMadaraClient) -> Result<(),
FieldElement::from_hex_be("1").unwrap(),
FieldElement::from(81u8),
],
max_fee: FieldElement::from(420u16),
max_fee: FieldElement::from(210u16),
signature: vec![],
nonce: FieldElement::ZERO,
is_query: false,
Expand All @@ -137,7 +137,7 @@ async fn works_ok_on_no_validate(madara: &ThreadSafeMadaraClient) -> Result<(),

assert_eq!(simulations.len(), 2);
assert_eq!(simulations[0].fee_estimation.gas_consumed, 0);
assert_eq!(simulations[0].fee_estimation.overall_fee, 420);
assert_eq!(simulations[0].fee_estimation.overall_fee, 210);
assert_eq!(simulations[0].fee_estimation.gas_price, 0);

Ok(())
Expand All @@ -164,7 +164,7 @@ async fn works_ok_on_validate_with_signature(madara: &ThreadSafeMadaraClient) ->

assert_eq!(simulations.len(), 1);
assert_eq!(simulations[0].fee_estimation.gas_consumed, 0);
assert_eq!(simulations[0].fee_estimation.overall_fee, 480);
assert_eq!(simulations[0].fee_estimation.overall_fee, 240);
assert_eq!(simulations[0].fee_estimation.gas_price, 0);

Ok(())
Expand Down Expand Up @@ -195,7 +195,7 @@ async fn works_ok_on_validate_without_signature_with_skip_validate(

assert_eq!(simulations.len(), 1);
assert_eq!(simulations[0].fee_estimation.gas_consumed, 0);
assert_eq!(simulations[0].fee_estimation.overall_fee, 440);
assert_eq!(simulations[0].fee_estimation.overall_fee, 220);
assert_eq!(simulations[0].fee_estimation.gas_price, 0);

Ok(())
Expand Down Expand Up @@ -235,7 +235,7 @@ async fn works_ok_without_max_fee_with_skip_fee_charge(madara: &ThreadSafeMadara

assert_eq!(simulations.len(), 2);
assert_eq!(simulations[0].fee_estimation.gas_consumed, 0);
assert_eq!(simulations[0].fee_estimation.overall_fee, 420);
assert_eq!(simulations[0].fee_estimation.overall_fee, 210);
assert_eq!(simulations[0].fee_estimation.gas_price, 0);

Ok(())
Expand Down

0 comments on commit 026f7a9

Please sign in to comment.