Skip to content

Commit

Permalink
feat: add basefee as kakarot storage slot (#774)
Browse files Browse the repository at this point in the history
* feat: add basefee as kakarot storage slot

* fix: fix gas price

* fix ci
  • Loading branch information
Eikix authored Feb 19, 2024
1 parent bd9b30e commit d24903a
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ katana-genesis:
run-katana: install-katana katana-genesis
katana --disable-fee --chain-id=KKRT --genesis .katana/genesis.json

test: katana-genesis load-env
test: install-katana katana-genesis load-env
cargo test --all --features testing

test-coverage: katana-genesis load-env
Expand Down
2 changes: 1 addition & 1 deletion lib/kakarot
Submodule kakarot updated 51 files
+9 −5 .devcontainer/devcontainer.json
+6 −1 .dockerignore
+2 −2 .env.example
+1 −6 .github/workflows/ci.yml
+1 −0 .gitignore
+13 −6 .trunk/trunk.yaml
+2 −2 Makefile
+33 −1,584 blockchain-tests-skip.yml
+0 −55 docker/ci/Dockerfile
+0 −17 docker/ci/README.md
+0 −370 docker/ci/setup_16.x
+40 −5 docker/deployer/Dockerfile
+0 −9 docker/devnet/Dockerfile
+0 −35 docker/devnet/run_and_deploy.py
+0 −45 docker/katana/Dockerfile
+0 −11 docker/katana/scripts/download_katana.sh
+0 −7 docker/katana/scripts/run.sh
+0 −39 docker/katana/scripts/wait_and_deploy.sh
+409 −1 poetry.lock
+1 −0 pyproject.toml
+1 −1 rust-toolchain
+49 −0 scripts/artifacts.py
+3 −1 scripts/constants.py
+3 −3 scripts/utils/kakarot.py
+31 −28 scripts/utils/starknet.py
+69 −0 src/kakarot/errors.cairo
+4 −0 src/kakarot/events.cairo
+14 −0 src/kakarot/evm.cairo
+14 −1 src/kakarot/instructions/environmental_information.cairo
+3 −0 src/kakarot/instructions/memory_operations.cairo
+17 −9 src/kakarot/instructions/system_operations.cairo
+68 −14 src/kakarot/interpreter.cairo
+17 −2 src/kakarot/kakarot.cairo
+1 −1 src/kakarot/precompiles/precompiles.cairo
+7 −19 src/kakarot/state.cairo
+10 −0 src/utils/utils.cairo
+20 −0 tests/end_to_end/conftest.py
+49 −0 tests/end_to_end/test_kakarot.py
+12 −0 tests/fixtures/replace_class.cairo
+1 −1 tests/fixtures/starknet.py
+19 −0 tests/src/backend/test_starknet.cairo
+6 −0 tests/src/backend/test_starknet.py
+0 −1 tests/src/kakarot/precompiles/test_precompiles.py
+6 −6 tests/src/kakarot/test_memory.cairo
+2 −1 tests/src/kakarot/test_memory.py
+2 −12 tests/src/kakarot/test_stack.cairo
+2 −1 tests/src/kakarot/test_stack.py
+19 −2 tests/src/kakarot/test_state.cairo
+18 −4 tests/src/kakarot/test_state.py
+3 −19 tests/src/utils/test_eth_transaction.py
+154 −166 tests/utils/serde.py
6 changes: 0 additions & 6 deletions src/eth_provider/constant.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
use lazy_static::lazy_static;

lazy_static! {
pub static ref MAX_FEE: u64 = 100_000_000_000_000_000u64;
/// Since Kakarot does not have a fee market, the base fee
/// per gas should currently be the Starknet gas price.
/// Since this field is not present in the Starknet
/// block header, we arbitrarily set it to 100 Gwei.
pub static ref BASE_FEE_PER_GAS: u64 = 100_000_000_000;
pub static ref MAX_PRIORITY_FEE_PER_GAS: u64 = 0;
}
2 changes: 1 addition & 1 deletion src/eth_provider/contracts/erc20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl<P: EthereumProvider> EthereumErc20<P> {
let request = TransactionRequest {
from: Some(Address::default()),
to: Some(self.address),
gas_price: Some(U256::from(1)),
gas_price: Some(U256::ZERO),
gas: Some(U256::from(1_000_000)),
value: Some(U256::ZERO),
input: TransactionInput { input: Some(calldata.into()), data: None },
Expand Down
10 changes: 8 additions & 2 deletions src/eth_provider/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ use starknet::core::utils::get_storage_var_address;
use starknet::providers::Provider as StarknetProvider;
use starknet_crypto::FieldElement;

use super::constant::MAX_FEE;
use super::database::types::log::StoredLog;
use super::database::types::{
header::StoredHeader, receipt::StoredTransactionReceipt, transaction::StoredTransaction,
Expand Down Expand Up @@ -119,6 +118,7 @@ pub trait EthereumProvider {
) -> EthProviderResult<FeeHistory>;
/// Send a raw transaction to the network and returns the transactions hash.
async fn send_raw_transaction(&self, transaction: Bytes) -> EthProviderResult<B256>;
async fn gas_price(&self) -> EthProviderResult<U256>;
}

/// Structure that implements the EthereumProvider trait.
Expand Down Expand Up @@ -381,7 +381,7 @@ where

async fn estimate_gas(&self, request: TransactionRequest, block_id: Option<BlockId>) -> EthProviderResult<U256> {
// Set a high gas limit to make sure the transaction will not fail due to gas.
let request = TransactionRequest { gas: Some(U256::from(*MAX_FEE)), ..request };
let request = TransactionRequest { gas: Some(U256::from(u64::MAX)), ..request };

let (_, gas_used) = self.call_helper(request, block_id).await?;
Ok(U256::from(gas_used))
Expand Down Expand Up @@ -467,6 +467,12 @@ where
Ok(B256::from_slice(&res.transaction_hash.to_bytes_be()[..]))
}
}

async fn gas_price(&self) -> EthProviderResult<U256> {
let kakarot_contract = KakarotCoreReader::new(*KAKAROT_ADDRESS, &self.starknet_provider);
let gas_price = kakarot_contract.get_base_fee().call().await?.base_fee;
Ok(into_via_wrapper!(gas_price))
}
}

impl<SP> EthDataProvider<SP>
Expand Down
4 changes: 2 additions & 2 deletions src/eth_provider/starknet/kakarot_core.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::str::FromStr;

use crate::{eth_provider::constant::MAX_FEE, models::felt::Felt252Wrapper};
use crate::models::felt::Felt252Wrapper;
use cainome::rs::abigen_legacy;
use dotenv::dotenv;
use lazy_static::lazy_static;
Expand Down Expand Up @@ -71,7 +71,7 @@ pub(crate) fn to_starknet_transaction(

let nonce = FieldElement::from(transaction.nonce());

let max_fee = (*MAX_FEE).into();
let max_fee = (u64::MAX).into();

// Step: Signature
// Extract the signature from the Ethereum Transaction
Expand Down
4 changes: 2 additions & 2 deletions src/eth_rpc/servers/eth_rpc.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::eth_provider::constant::{BASE_FEE_PER_GAS, MAX_PRIORITY_FEE_PER_GAS};
use crate::eth_provider::constant::MAX_PRIORITY_FEE_PER_GAS;
use crate::eth_provider::error::EthProviderError;
use crate::eth_provider::provider::EthereumProvider;
use jsonrpsee::core::{async_trait, RpcResult as Result};
Expand Down Expand Up @@ -174,7 +174,7 @@ where

#[tracing::instrument(skip_all, ret, err)]
async fn gas_price(&self) -> Result<U256> {
Ok(U256::from(*BASE_FEE_PER_GAS))
Ok(self.eth_provider.gas_price().await?)
}

#[tracing::instrument(skip_all, ret, err, fields(block_count = %block_count, newest_block = %newest_block, reward_percentiles = ?reward_percentiles))]
Expand Down

0 comments on commit d24903a

Please sign in to comment.