kkrt-labs / kakarot

Kakarot is a zkEVM written in Cairo, leveraging the STARK proof system.
https://kakarot.org
MIT License
990 stars 302 forks source link

Charge gas according to actual resources consumed #1328

Open enitrat opened 3 months ago

enitrat commented 3 months ago

EVM and Starknet have different ways of pricing resource usages due to the underlying architecture differences. As such, there cannot be a 1 <> 1 mapping between the EVM gas consumed and the Starknet fee to pay.

As such, we need to design a mechanism ensuring that in the majority of cases, the fee charged for the user (based on gas price and gas used) matches the actual fee, paid by our relayers, for the execution of the starknet transcation.

### Tasks
- [x] check if is possible to restrict tx usage (pre1559 tx) on sdks and wallets (starting from metamask rabby)
- [ ] how the wallet works (base fee per gas, max prio)
- [ ] how sdks and wallets will be impacted from the evm specs broken
Eikix commented 3 months ago

EVM and Starknet have different ways of pricing resource usages due to the underlying architecture differences. As such, there cannot be a 1 <> 1 mapping between the EVM gas consumed and the Starknet fee to pay.

As such, we need to design a mechanism ensuring that in the majority of cases, the fee charged for the user (based on gas price and gas used) matches the actual fee, paid by our relayers, for the execution of the starknet transcation.

Note that an option is also to use our STRK allocation to sponsor part of our users' transactions as part of an on-chain incentive to boost usage. At least until Stwo/Cairo native (they will bring L2 fees down)

Second note: there are extensive efforts to come up with a Rollup Improvement Proposal for EVM L2s to have multi dimensional gas.

Eikix commented 3 months ago

A fine plan could be:

eugypalu commented 2 weeks ago

IMG_8157

eugypalu commented 2 weeks ago

To ensure that the network only accepts pre-EIP1559 transactions, it's necessary to make the wallets understand that the network does not accept EIP1559 transactions. This is done in the network definition by specifying that the network does not support EIP1559, which will automatically allow wallets to send the correct transactions.

For example, MetaMask stores the data in a Redux state with metadata, which is used, for example, here and here to verify whether the network supports EIP1559 or not.

An example of netowrk configuration that does not accept EIP1559 is the following:

{
    name: "Mordor Testnet",
    title: "Ethereum Classic Mordor Testnet",
    status: "active",
    chain: "ETC",
    icon: "ethereumclassictestnet",
    rpc: [
        "https://rpc.mordor.etccooperative.org",
        "https://geth-mordor.etc-network.info"
    ],
    features: [
        {
            name: "EIP155"
        }
    ],
    faucets: [
        "https://easy.hebeswap.com/#/faucet",
        "https://faucet.mordortest.net"
    ],
    nativeCurrency: {
        name: "Mordor Ether",
        symbol: "METC",
        decimals: 18
    },
    infoURL: "https://ethereumclassic.org/development/testnets",
    shortName: "metc",
    chainId: 63,
    networkId: 7,
    slip44: 1,
    explorers: [
    {
        name: "blockscout-mordor",
        url: "https://etc-mordor.blockscout.com",
        standard: "EIP3091"
    },
    {
        name: "etcnetworkinfo-expedition-mordor",
        url: "https://explorer-expedition.etc-network.info/?network=Ethereum+Classic+at+etc-network.info+GETH+Mordor",
        standard: "none"
    }
    ]
}

Therefore, to exclude it, it is necessary to modify the configuration file by not including the EIP1559 feature, or by not inheriting from a network that accepts it.

Here is an example of a network that does accept EIP1559:

{
  "name": "Ethereum Mainnet",
  "chain": "ETH",
  "rpc": [
    "https://mainnet.infura.io/v3/${INFURA_API_KEY}",
    "https://api.mycryptoapi.com/eth"
  ],
  "faucets": [],
  "nativeCurrency": {
    "name": "Ether",
    "symbol": "ETH",
    "decimals": 18
  },
  "features": [{ "name": "EIP155" }, { "name": "EIP1559" }],
  "infoURL": "https://ethereum.org",
  "shortName": "eth",
  "chainId": 1,
  "networkId": 1,
  "icon": "ethereum",
  "explorers": [{
    "name": "etherscan",
    "url": "https://etherscan.io",
    "icon": "etherscan",
    "standard": "EIP3091"
  }]
}

From the SDKs' perspective, the main SDKs allow sending pre-EIP1559 transactions, but we need to ensure that EIP1559 transactions are rejected on the RPC side.