Skip to content

Commit

Permalink
bump Katana to v0.7.0-alpha.0 (#958)
Browse files Browse the repository at this point in the history
* bump Katana to v0.6.1-alpha.0

* update

* removing more dependencies to ethers

* update import

* bump Katana to v0.6.1-alpha.0

* update

* removing more dependencies to ethers

* update import

* fix tests

* add default generic param on KatanaGenesisBuilder

* add unit test for eth api block number

* update

* update

* update lock

* try with v0.6.0-alpha.13

* update

* test v0.6.0-alpha.3

* test v0.6.0-alpha.4

* test v0.6.0-alpha.6

* test v0.6.0-alpha.10

* test v0.6.0-alpha.13

* test v0.6.0-alpha.12

* test v0.6.0-alpha.11

* update GasPrices

* increase block-time

* update

* bump katana version

* cargo update

* revert bump

* update

* bump

* bump to v0.7.0-alpha.0

* clean up

* update

* remove useless test

* fix comments

* fix clippy

---------

Co-authored-by: Gregory Edison <[email protected]>
  • Loading branch information
tcoratger and greged93 authored May 21, 2024
1 parent aab3d58 commit 39f8fe6
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 62 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

23 changes: 16 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,13 @@ tokio-stream = { version = "0.1.15", default-features = false, optional = true }
# Otherwise, underlying dependencies of dojo will not be patched and we will get a compilation error
# see https://github.com/dojoengine/dojo/issues/563
# When making changes to the rev, please also update to make file to the same rev in the `install-katana` rule.
dojo-test-utils = { git = 'https://github.com/dojoengine/dojo', tag = "v0.6.0-alpha.6", default-features = false }
katana-core = { git = 'https://github.com/dojoengine/dojo', tag = "v0.6.0-alpha.6", features = [
"messaging",
] }
katana-primitives = { git = 'https://github.com/dojoengine/dojo', tag = "v0.6.0-alpha.6", default-features = false, features = [
"serde",
] }
dojo-test-utils = { git = 'https://github.com/dojoengine/dojo', tag = "v0.7.0-alpha.0", default-features = false }
katana-core = { git = 'https://github.com/dojoengine/dojo', tag = "v0.7.0-alpha.0", features = ["messaging"] }
katana-primitives = { git = 'https://github.com/dojoengine/dojo', tag = "v0.7.0-alpha.0", default-features = false, features = ["serde"] }
arbitrary = { version = "1", features = ["derive"] }

alloy-signer-wallet = { version = "0.1.0", default-features = false }

[patch."https://github.com/starkware-libs/blockifier"]
blockifier = { git = "https://github.com/dojoengine/blockifier", rev = "d38b979" }

Expand All @@ -192,6 +190,17 @@ cairo-vm = { git = "https://github.com/dojoengine/cairo-rs.git", rev = "1031381"
# we need v0.7.0-rc.0 to be compatible with dojo.
starknet_api = { git = "https://github.com/starkware-libs/starknet-api.git", tag = "v0.7.0-rc.0" }

alloy-primitives = { git = "https://github.com/alloy-rs/core", rev = "ff339696fa9b490698cb3edec3d4647fae0bd332" }
alloy-json-abi = { git = "https://github.com/alloy-rs/core", rev = "ff339696fa9b490698cb3edec3d4647fae0bd332" }
alloy-contract = { git = "https://github.com/alloy-rs/alloy", rev = "d68a6b787b2904061f0ae7fcc02ece8513e3c500" }
alloy-json-rpc = { git = "https://github.com/alloy-rs/alloy", rev = "d68a6b787b2904061f0ae7fcc02ece8513e3c500" }
alloy-network = { git = "https://github.com/alloy-rs/alloy", rev = "d68a6b787b2904061f0ae7fcc02ece8513e3c500" }
alloy-provider = { git = "https://github.com/alloy-rs/alloy", rev = "d68a6b787b2904061f0ae7fcc02ece8513e3c500"}
alloy-rpc-types = { git = "https://github.com/alloy-rs/alloy", rev = "d68a6b787b2904061f0ae7fcc02ece8513e3c500" }
alloy-signer = { git = "https://github.com/alloy-rs/alloy", rev = "d68a6b787b2904061f0ae7fcc02ece8513e3c500" }
alloy-signer-wallet = { git = "https://github.com/alloy-rs/alloy", rev = "d68a6b787b2904061f0ae7fcc02ece8513e3c500" }
alloy-transport = { git = "https://github.com/alloy-rs/alloy", rev = "d68a6b787b2904061f0ae7fcc02ece8513e3c500" }

[dev-dependencies]
rstest = { version = "0.19.0", default-features = false }
toml = { version = "0.8.12", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ run-dev: load-env


install-katana:
cargo install --git https://github.com/dojoengine/dojo --locked --tag v0.6.0-alpha.6 katana
cargo install --git https://github.com/dojoengine/dojo --locked --tag v0.7.0-alpha.0 katana

katana-genesis: install-katana
rm -fr .katana/ && mkdir .katana
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: "3.2"

services:
starknet:
image: ghcr.io/dojoengine/dojo:v0.6.0-alpha.6
image: ghcr.io/dojoengine/dojo:v0.7.0-alpha.0
command:
- katana
- --disable-fee
Expand Down
2 changes: 1 addition & 1 deletion docker/hive/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# trunk-ignore-all(terrascan/AC_DOCKER_0047)

# CairoVM Chain
FROM ghcr.io/dojoengine/dojo:v0.6.0-alpha.6 as katana
FROM ghcr.io/dojoengine/dojo:v0.7.0-alpha.0 as katana

# Indexer service
### Apibara DNA indexer and indexer
Expand Down
6 changes: 3 additions & 3 deletions docker/hive/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ until
curl --silent --request POST \
--header "Content-Type: application/json" \
--data '{
"jsonrpc": "2.0",
"method": "starknet_blockNumber",
"params": [],
"jsonrpc": "2.0",
"method": "starknet_blockNumber",
"params": [],
"id": 1
}' \
"${STARKNET_NETWORK}" # Use the provided network address
Expand Down
3 changes: 1 addition & 2 deletions src/bin/katana_genesis.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use dotenvy::dotenv;
use ethers::types::U256;
use kakarot_rpc::test_utils::katana::genesis::KatanaGenesisBuilder;
use lazy_static::lazy_static;
use reth_primitives::B256;
use reth_primitives::{B256, U256};
use starknet_crypto::FieldElement;
use std::{
env::var,
Expand Down
14 changes: 12 additions & 2 deletions src/eth_provider/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,21 @@ pub fn split_u256<T: From<u128>>(value: impl Into<U256>) -> [T; 2] {
}

/// Checks if the error is a contract not found error.
/// Some providers return a contract not found error when the contract is not deployed.
/// Katana returns a contract error with a revert message containing "is not deployed".
#[inline]
pub(crate) const fn contract_not_found<T>(err: &Result<T, Error>) -> bool {
pub(crate) fn contract_not_found<T>(err: &Result<T, Error>) -> bool {
match err {
Ok(_) => false,
Err(err) => matches!(err, Error::Provider(ProviderError::StarknetError(StarknetError::ContractNotFound))),
Err(err) => {
matches!(err, Error::Provider(ProviderError::StarknetError(StarknetError::ContractNotFound)))
|| matches!(
err,
Error::Provider(ProviderError::StarknetError(StarknetError::ContractError(ContractErrorData {
revert_error: reason
}))) if reason.contains("is not deployed")
)
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/test_utils/eoa.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::sync::Arc;

use alloy_signer_wallet::LocalWallet;
use async_trait::async_trait;
use ethers::abi::Tokenize;
use ethers::signers::{LocalWallet, Signer};
use ethers_solc::artifacts::CompactContractBytecode;
use reth_primitives::{sign_message, Address, Transaction, TransactionSigned, TxEip1559, TxKind, B256, U256};
use starknet::core::types::{MaybePendingTransactionReceipt, TransactionReceipt};
Expand All @@ -29,8 +29,8 @@ pub trait Eoa<P: Provider + Send + Sync> {
Ok(starknet_address(self.evm_address()?))
}
fn evm_address(&self) -> Result<Address, eyre::Error> {
let wallet = LocalWallet::from_bytes(self.private_key().as_slice())?;
Ok(Address::from_slice(wallet.address().as_bytes()))
let wallet = LocalWallet::from_bytes(&self.private_key())?;
Ok(wallet.address())
}
fn private_key(&self) -> B256;
fn eth_provider(&self) -> &EthDataProvider<P>;
Expand Down
1 change: 1 addition & 0 deletions src/test_utils/fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub async fn contract_empty(#[future] katana: Katana) -> (Katana, KakarotEvmCont
#[awt]
pub async fn erc20(#[future] katana: Katana) -> (Katana, KakarotEvmContract) {
let eoa = katana.eoa();

let contract = eoa
.deploy_evm_contract(
Some("ERC20"),
Expand Down
5 changes: 2 additions & 3 deletions src/test_utils/hive/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::collections::HashMap;

use ef_testing::evm_sequencer::account::KakarotAccount;
use ethers::types::U256 as EthersU256;
use katana_primitives::{
contract::ContractAddress,
genesis::json::{GenesisContractJson, GenesisJson},
Expand Down Expand Up @@ -108,7 +107,7 @@ impl HiveGenesisConfig {
ContractAddress::new(starknet_address),
GenesisContractJson {
class: Some(account_contract_class_hash.0.into()),
balance: Some(EthersU256::from_big_endian(&info.balance.to_be_bytes::<32>())),
balance: Some(info.balance),
nonce: None,
storage: Some(kakarot_account_storage.into_iter().collect()),
},
Expand Down Expand Up @@ -178,7 +177,7 @@ mod tests {
let contract = GENESIS.contracts.get(&ContractAddress::new(starknet_address)).unwrap();

// Check the balance
assert_eq!(contract.balance, Some(EthersU256::from_big_endian(&account.balance.to_be_bytes::<32>())));
assert_eq!(contract.balance, Some(account.balance));
// Check the storage
for (key, value) in account.storage.unwrap_or_default() {
let key = get_storage_var_address(ACCOUNT_STORAGE, &split_u256::<FieldElement>(key)).unwrap();
Expand Down
52 changes: 19 additions & 33 deletions src/test_utils/katana/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ use std::fs;
use std::marker::PhantomData;
use std::path::PathBuf;

use ethers::signers::LocalWallet;
use ethers::signers::Signer;
use ethers::types::U256;
use crate::eth_provider::utils::split_u256;
use alloy_signer_wallet::LocalWallet;
use eyre::{eyre, OptionExt, Result};
use katana_primitives::block::GasPrices;
use katana_primitives::contract::{StorageKey, StorageValue};
use katana_primitives::genesis::allocation::DevAllocationsGenerator;
use katana_primitives::genesis::constant::DEFAULT_FEE_TOKEN_ADDRESS;
Expand All @@ -20,7 +18,7 @@ use katana_primitives::{
};
use lazy_static::lazy_static;
use rayon::prelude::*;
use reth_primitives::B256;
use reth_primitives::{B256, U256};
use serde::Serialize;
use serde_json::Value;
use serde_with::serde_as;
Expand Down Expand Up @@ -101,7 +99,7 @@ impl<T> KatanaGenesisBuilder<T> {

pub fn with_dev_allocation(mut self, amount: u16) -> Self {
let dev_allocations = DevAllocationsGenerator::new(amount)
.with_balance(DEFAULT_PREFUNDED_ACCOUNT_BALANCE)
.with_balance(U256::from(DEFAULT_PREFUNDED_ACCOUNT_BALANCE))
.with_seed(parse_seed("0"))
.generate()
.into_iter()
Expand All @@ -119,7 +117,6 @@ impl<T> KatanaGenesisBuilder<T> {
)
});
self.accounts.extend(dev_allocations);

self
}

Expand Down Expand Up @@ -150,27 +147,21 @@ impl KatanaGenesisBuilder<Uninitialized> {
.map(|entry| {
let path = entry.unwrap().path().to_path_buf();
let artifact = fs::read_to_string(&path).expect("Failed to read artifact");
(
path,
GenesisClassJson {
class: PathOrFullArtifact::Artifact(
serde_json::from_str(&artifact).expect("Failed to parse artifact"),
),
class_hash: None,
},
)
let artifact = serde_json::from_str(&artifact).expect("Failed to parse artifact");
let class_hash = compute_class_hash(&artifact)
.inspect_err(|e| eprint!("Failed to compute class hash: {:?}", e))
.ok();
(path, GenesisClassJson { class: PathOrFullArtifact::Artifact(artifact), class_hash })
})
.collect::<Vec<_>>();

self.class_hashes = classes
.par_iter()
.filter_map(|(path, class)| {
let artifact = match &class.class {
PathOrFullArtifact::Artifact(artifact) => artifact,
PathOrFullArtifact::Path(_) => unreachable!("Expected artifact"),
};
let class_hash = compute_class_hash(artifact).ok()?;
Some((path.file_stem().unwrap().to_str().unwrap().to_string(), class_hash))
.iter()
.map(|(path, class)| {
(
path.file_stem().unwrap().to_str().unwrap().to_string(),
class.class_hash.expect("all class hashes should be computed"),
)
})
.collect();
self.classes = classes.into_iter().map(|(_, class)| class).collect();
Expand Down Expand Up @@ -290,12 +281,9 @@ impl KatanaGenesisBuilder<Initialized> {
let eoa = self.contracts.get_mut(&starknet_address).ok_or_eyre("Missing EOA contract")?;

let key = get_storage_var_address("ERC20_balances", &[*starknet_address])?;
let low = amount & U256::from(u128::MAX);
let low: u128 = low.try_into().unwrap(); // safe to unwrap
let high = amount >> U256::from(128);
let high: u128 = high.try_into().unwrap(); // safe to unwrap
let amount_split = split_u256::<u128>(amount);

let storage = [(key, low.into()), (key + 1u8.into(), high.into())].into_iter();
let storage = [(key, amount_split[0].into()), (key + 1u8.into(), amount_split[1].into())].into_iter();
self.fee_token_storage.extend(storage);

eoa.balance = Some(amount);
Expand All @@ -311,7 +299,7 @@ impl KatanaGenesisBuilder<Initialized> {
number: 0,
timestamp: 0,
sequencer_address: self.compute_starknet_address(self.coinbase)?,
gas_prices: GasPrices::default(),
gas_prices: Default::default(),
classes: self.classes,
fee_token: FeeTokenConfigJson {
name: "Ether".to_string(),
Expand Down Expand Up @@ -349,9 +337,7 @@ impl KatanaGenesisBuilder<Initialized> {
}

fn evm_address(&self, pk: B256) -> Result<FieldElement> {
let wallet = LocalWallet::from_bytes(pk.as_slice())?;
let evm_address = wallet.address();
Ok(FieldElement::from_byte_slice_be(evm_address.as_bytes())?)
Ok(FieldElement::from_byte_slice_be(&LocalWallet::from_bytes(&pk)?.address().into_array())?)
}

pub fn cache_load(&self, key: &str) -> Result<FieldElement> {
Expand Down
10 changes: 5 additions & 5 deletions src/test_utils/katana/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use std::path::Path;
use std::sync::Arc;

use dojo_test_utils::sequencer::{Environment, StarknetConfig, TestSequencer};
use katana_primitives::block::GasPrices;
use katana_primitives::chain::ChainId;
use katana_primitives::genesis::json::GenesisJson;
use katana_primitives::genesis::Genesis;
Expand Down Expand Up @@ -37,9 +36,11 @@ use {
};

fn load_genesis() -> Genesis {
let path = Path::new(env!("CARGO_MANIFEST_DIR")).join(".katana/genesis.json");
let genesis_json = GenesisJson::load(path).expect("Failed to load genesis.json, run `make katana-genesis`");
Genesis::try_from(genesis_json).expect("Failed to convert GenesisJson to Genesis")
Genesis::try_from(
GenesisJson::load(Path::new(env!("CARGO_MANIFEST_DIR")).join(".katana/genesis.json"))
.expect("Failed to load genesis.json, run `make katana-genesis`"),
)
.expect("Failed to convert GenesisJson to Genesis")
}

/// Returns a `StarknetConfig` instance customized for Kakarot.
Expand All @@ -53,7 +54,6 @@ pub fn katana_config() -> StarknetConfig {
chain_id: ChainId::parse("kaka_test").unwrap(),
invoke_max_steps: max_steps,
validate_max_steps: max_steps,
gas_price: GasPrices { eth: 1, strk: 0 },
},
genesis: load_genesis(),
..Default::default()
Expand Down

0 comments on commit 39f8fe6

Please sign in to comment.