0xSpaceShard / starknet-devnet-rs

A local testnet for Starknet... in Rust
https://0xspaceshard.github.io/starknet-devnet-rs/
MIT License
100 stars 56 forks source link

Discrepancy in Gas Consumption Estimations between Devnet and Alpha-Sepolia Testnet #526

Open ksew1 opened 2 weeks ago

ksew1 commented 2 weeks ago

Describe the bug (observed vs expected behavior)

Observed:

The field gas_consumed has low estimations on devnet when using starknet_estimateFee and starknet_simulateTransactions. As a result, the following error occurs when trying to deploy:

{
  "code": -1,
  "message": "Max L1 gas amount (13) is lower than the minimal gas amount: 170."
}

Expected:

Calls should have higher gas consumption estimations. This behavior is observed when performing calls on the alpha-sepolia testnet.

Not reproducible on testnet

To Reproduce

  1. Fork devnet from the alpha-sepolia testnet.
  2. Make an RPC call to devnet using either starknet_estimateFee or starknet_simulateTransactions.
  3. Perform the same call to the alpha-sepolia testnet.
  4. Observe that the gas consumed estimation on devnet will be multiple magnitudes smaller compared to alpha-sepolia.

Template for starknet_estimateFee for OZ Account Deployment that Reproduces this Issue:

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "starknet_estimateFee",
  "params": [
    [
      {
        "type": "DEPLOY_ACCOUNT",
        "version": "0x100000000000000000000000000000003",
        "signature": [
          "0x1de005f9a4ee5048257ffefe8dcaf8b0cd52ad2db239eca23af688f2c230010",
          "0x115e35a9220bed1fb7d4b6ba4d4536ea89cd744dd0562230a27c3a6f3dca674"
        ],
        "nonce": "0x0",
        "contract_address_salt": "0x0",
        "constructor_calldata": [
          "0x611aee415ffe318942c857a4be712fa20c26e331f84ab680523002cce01db98"
        ],
        "class_hash": "0x61dac032f228abef9c6626f995015233097ae253a7f72d68552db02f2971b8f",
        "resource_bounds": {
          "l1_gas": {
            "max_amount": "0x0",
            "max_price_per_unit": "0x0"
          },
          "l2_gas": {
            "max_amount": "0x0",
            "max_price_per_unit": "0x0"
          }
        },
        "tip": "0x0",
        "paymaster_data": [],
        "nonce_data_availability_mode": "L1",
        "fee_data_availability_mode": "L1"
      }
    ],
    [],
    "latest"
  ]
}

Devnet version

System specifications

mikiw commented 2 weeks ago

We are discussing if it's a feature or bug and how to handle that.

Forking the origin is just adding the possibility to query the origin network but it doesn't mean that we should also have the same fee as the origin since it's our local development network.

We are thinking about adding the possibility to configure fees so users can tweak it as they like.

marioiordanov commented 2 weeks ago

What can be done is to add an endpoint to tweak the VersionedConstants which are responsible for calculating the gas amount

mikiw commented 1 week ago

Hint: check logic from CLI regarding:

gas_price_wei: self.gas_price_wei,
gas_price_strk: self.gas_price_strk,
data_gas_price_wei: self.data_gas_price_wei,
data_gas_price_strk: self.data_gas_price_strk,

and block_context: BlockContext

mikiw commented 1 week ago

there are also

pub l1_gas_price: GasPricePerToken,
pub l1_data_gas_price: GasPricePerToken,

in BlockHeader