diff --git a/Makefile b/Makefile index 06d250d67..e9e23cb80 100644 --- a/Makefile +++ b/Makefile @@ -28,7 +28,7 @@ setup: .gitmodules chmod +x ./scripts/extract_abi.sh git submodule update --init --recursive cp .env.example .env - cd lib/kakarot && uv sync --all-extras --dev && make build && make build-sol && \ + cd lib/kakarot && make setup && uv sync --all-extras --dev && make build && make build-sol && \ mv build/ssj/contracts_Cairo1Helpers.contract_class.json build/cairo1_helpers.json && rm -fr build/ssj ./scripts/extract_abi.sh diff --git a/deployments/karnot/deployment-config.yaml b/deployments/karnot/deployment-config.yaml index fd0aa1897..40ab2b2b9 100644 --- a/deployments/karnot/deployment-config.yaml +++ b/deployments/karnot/deployment-config.yaml @@ -29,7 +29,7 @@ environments: id: 4912672c-533c-4198-9834-a8999c0b2db0 repos: kakarot-rpc: - image: ghcr.io/kkrt-labs/kakarot-rpc/node:v0.7.6 + image: ghcr.io/kkrt-labs/kakarot-rpc/node:v0.7.6-2 config: KAKAROT_ADDRESS: "0x48fc2888aad166304e63af35a48e00e32da9831e49fe30a22148fdecdb7e66f" UNINITIALIZED_ACCOUNT_CLASS_HASH: "0x7b2de5e73ff7eb338d76c967dd5aa3f3004574d326b8c1402bb819d4983b8b6" @@ -39,7 +39,7 @@ environments: MAX_LOGS: "10000" RPC_MAX_CONNECTIONS: "5000" kakarot-indexer: - image: ghcr.io/kkrt-labs/kakarot-rpc/indexer:v0.7.6 + image: ghcr.io/kkrt-labs/kakarot-rpc/indexer:v0.7.6-2 config: KAKAROT_ADDRESS: "0x48fc2888aad166304e63af35a48e00e32da9831e49fe30a22148fdecdb7e66f" ALLOW_ENV_FROM_ENV: "DEBUG,APIBARA_AUTH_TOKEN,STARTING_BLOCK,STREAM_URL,SINK_TYPE,MONGO_CONNECTION_STRING,MONGO_DATABASE_NAME,STARKNET_NETWORK,KAKAROT_ADDRESS,ALLOW_NET,PERSIST_TO_REDIS,SINK_ID,UNINITIALIZED_ACCOUNT_CLASS_HASH,ACCOUNT_CONTRACT_CLASS_HASH,DEFAULT_BLOCK_GAS_LIMIT,MAX_FELTS_IN_CALLDATA" diff --git a/lib/kakarot b/lib/kakarot index 8f5c25899..2121e997f 160000 --- a/lib/kakarot +++ b/lib/kakarot @@ -1 +1 @@ -Subproject commit 8f5c25899f785682bf018411459988ad82cf9228 +Subproject commit 2121e997ffae4d563099373c740edb09988125f5 diff --git a/src/bin/hive_genesis.rs b/src/bin/hive_genesis.rs index 784430c1a..1a02cd260 100644 --- a/src/bin/hive_genesis.rs +++ b/src/bin/hive_genesis.rs @@ -32,12 +32,13 @@ fn main() { let hive_genesis_content = std::fs::read_to_string(hive_genesis_path).expect("Failed to read hive genesis file"); let hive_genesis: HiveGenesisConfig = serde_json::from_str(&hive_genesis_content).expect("Failed to parse hive genesis json"); + let chain_id = hive_genesis.config.chain_id.into(); // Convert the hive genesis to a katana genesis. let genesis_json = hive_genesis.try_into_genesis_json(builder.clone()).expect("Failed to convert hive genesis to katana genesis"); - let builder = builder.with_kakarot(Felt::ZERO).expect("Failed to set up Kakarot"); + let builder = builder.with_kakarot(Felt::ZERO, chain_id).expect("Failed to set up Kakarot"); let manifest = builder.manifest(); // Write the genesis json to the file. diff --git a/src/bin/katana_genesis.rs b/src/bin/katana_genesis.rs index 2ea5305da..046a0e20c 100644 --- a/src/bin/katana_genesis.rs +++ b/src/bin/katana_genesis.rs @@ -20,6 +20,8 @@ static KAKAROT_CONTRACTS_PATH: LazyLock = /// Mock coinbase address. static COINBASE_ADDRESS: LazyLock = LazyLock::new(|| 0x12345u32.into()); +static CHAIN_ID: LazyLock = LazyLock::new(|| Felt::from_str("0xb615f74ebad2c").expect("Invalid chain ID")); + fn main() { // Load the env vars. dotenv().ok(); @@ -31,7 +33,7 @@ fn main() { // Read all the classes. let mut builder = KatanaGenesisBuilder::default() .load_classes(KAKAROT_CONTRACTS_PATH.clone()) - .with_kakarot(*COINBASE_ADDRESS) + .with_kakarot(*COINBASE_ADDRESS, *CHAIN_ID) .expect("Failed to set up Kakarot"); builder = builder.with_eoa(pk).expect("Failed to set up EOA").fund(pk, U256::from(u128::MAX)).unwrap(); builder = builder.with_dev_allocation(10); diff --git a/src/test_utils/constants.rs b/src/test_utils/constants.rs index 879ef80ad..a187a7ddd 100644 --- a/src/test_utils/constants.rs +++ b/src/test_utils/constants.rs @@ -19,3 +19,4 @@ pub const KAKAROT_COINBASE: &str = "Kakarot_coinbase"; pub const KAKAROT_BASE_FEE: &str = "Kakarot_base_fee"; pub const KAKAROT_PREV_RANDAO: &str = "Kakarot_prev_randao"; pub const KAKAROT_BLOCK_GAS_LIMIT: &str = "Kakarot_block_gas_limit"; +pub const KAKAROT_CHAIN_ID: &str = "Kakarot_chain_id"; diff --git a/src/test_utils/hive/mod.rs b/src/test_utils/hive/mod.rs index cbc4bfb73..8da4a7e76 100644 --- a/src/test_utils/hive/mod.rs +++ b/src/test_utils/hive/mod.rs @@ -53,7 +53,7 @@ impl HiveGenesisConfig { /// marker type indicates that the Kakarot contract classes need to have been loaded into the builder. pub fn try_into_genesis_json(self, builder: KatanaGenesisBuilder) -> Result { let coinbase_address = Felt::from_bytes_be_slice(self.coinbase.as_slice()); - let builder = builder.with_kakarot(coinbase_address)?; + let builder = builder.with_kakarot(coinbase_address, self.config.chain_id.into())?; // Get the current state of the builder. let kakarot_address = builder.cache_load("kakarot_address")?; @@ -151,8 +151,10 @@ mod tests { }); static GENESIS_BUILDER_LOADED: LazyLock> = LazyLock::new(|| KatanaGenesisBuilder::default().load_classes(ROOT.join("lib/kakarot/build"))); - static GENESIS_BUILDER: LazyLock> = - LazyLock::new(|| GENESIS_BUILDER_LOADED.clone().with_kakarot(Felt::ZERO).unwrap()); + static GENESIS_BUILDER: LazyLock> = LazyLock::new(|| { + // The chain ID is hardcoded in the hive genesis file src/test_utils/hive/test_data/genesis.json + GENESIS_BUILDER_LOADED.clone().with_kakarot(Felt::ZERO, Felt::from_hex_unchecked("7")).unwrap() + }); static GENESIS: LazyLock = LazyLock::new(|| HIVE_GENESIS.clone().try_into_genesis_json(GENESIS_BUILDER_LOADED.clone()).unwrap()); diff --git a/src/test_utils/katana/genesis.rs b/src/test_utils/katana/genesis.rs index 6dcce4eb9..a1384223d 100644 --- a/src/test_utils/katana/genesis.rs +++ b/src/test_utils/katana/genesis.rs @@ -3,8 +3,8 @@ use crate::{ test_utils::constants::{ ACCOUNT_AUTHORIZED_MESSAGE_HASHES, ACCOUNT_CAIRO1_HELPERS_CLASS_HASH, ACCOUNT_EVM_ADDRESS, ACCOUNT_IMPLEMENTATION, EIP_155_AUTHORIZED_MESSAGE_HASHES, KAKAROT_ACCOUNT_CONTRACT_CLASS_HASH, - KAKAROT_BASE_FEE, KAKAROT_BLOCK_GAS_LIMIT, KAKAROT_CAIRO1_HELPERS_CLASS_HASH, KAKAROT_COINBASE, - KAKAROT_EVM_TO_STARKNET_ADDRESS, KAKAROT_NATIVE_TOKEN_ADDRESS, KAKAROT_PREV_RANDAO, + KAKAROT_BASE_FEE, KAKAROT_BLOCK_GAS_LIMIT, KAKAROT_CAIRO1_HELPERS_CLASS_HASH, KAKAROT_CHAIN_ID, + KAKAROT_COINBASE, KAKAROT_EVM_TO_STARKNET_ADDRESS, KAKAROT_NATIVE_TOKEN_ADDRESS, KAKAROT_PREV_RANDAO, KAKAROT_UNINITIALIZED_ACCOUNT_CLASS_HASH, OWNABLE_OWNER, }, }; @@ -152,6 +152,11 @@ impl KatanaGenesisBuilder { .par_bridge() .filter_map(|entry| { let path = entry.unwrap().path().to_path_buf(); + // Skip class_hashes.json file + if path.file_name().map_or(false, |name| name == "class_hashes.json") { + return None; + } + let artifact = fs::read_to_string(&path).expect("Failed to read artifact"); let artifact = serde_json::from_str(&artifact).expect("Failed to parse artifact"); let class_hash = compute_class_hash(&artifact) @@ -186,13 +191,14 @@ impl KatanaGenesisBuilder { impl KatanaGenesisBuilder { /// Add the Kakarot contract to the genesis. Updates the state to [Initialized]. /// Once in the [Initialized] status, the builder can be built. - pub fn with_kakarot(mut self, coinbase_address: Felt) -> Result> { + pub fn with_kakarot(mut self, coinbase_address: Felt, chain_id: Felt) -> Result> { let kakarot_class_hash = self.kakarot_class_hash()?; let account_contract_class_hash = self.account_contract_class_hash()?; let uninitialized_account_class_hash = self.uninitialized_account_class_hash()?; let cairo1_helpers_class_hash = self.cairo1_helpers_class_hash()?; let block_gas_limit = 20_000_000u64.into(); + // Construct the kakarot contract address. Based on the constructor args from // https://github.com/kkrt-labs/kakarot/blob/main/src/kakarot/kakarot.cairo#L23 let kakarot_address = ContractAddress::new(get_udc_deployed_address( @@ -205,8 +211,8 @@ impl KatanaGenesisBuilder { account_contract_class_hash, uninitialized_account_class_hash, cairo1_helpers_class_hash, - coinbase_address, block_gas_limit, + chain_id, ], )); // Cache the address for later use. @@ -223,6 +229,7 @@ impl KatanaGenesisBuilder { (storage_addr(KAKAROT_BASE_FEE)?, Felt::ZERO), (storage_addr(KAKAROT_PREV_RANDAO)?, Felt::ZERO), (storage_addr(KAKAROT_BLOCK_GAS_LIMIT)?, block_gas_limit), + (storage_addr(KAKAROT_CHAIN_ID)?, chain_id), ] .into_iter() .collect(); diff --git a/tests/tests/eth_provider.rs b/tests/tests/eth_provider.rs index 2a150b656..43ec43185 100644 --- a/tests/tests/eth_provider.rs +++ b/tests/tests/eth_provider.rs @@ -73,7 +73,7 @@ async fn test_chain_id(#[future] katana: Katana, _setup: ()) { let chain_id = eth_provider.chain_id().await.unwrap().unwrap_or_default(); // Then - // Chain ID should correspond to "kaka_test" + // Chain ID should correspond to "kaka_test" % max safe chain id assert_eq!(chain_id, U64::from_str_radix("b615f74ebad2c", 16).unwrap()); }