Skip to content

Commit

Permalink
Feat: rebase sequencer on blockifier fork (#549)
Browse files Browse the repository at this point in the history
* draft commit

* feat: rebase seqeuncer on top of our own blockifier fork

* dev: fix formatting

* dev: remove comments

---------

Co-authored-by: Harsh Bajpai <harshbajpai@Harshs-MacBook-Pro.local>
  • Loading branch information
bajpai244 and Harsh Bajpai authored Oct 18, 2023
1 parent acf81fe commit 4752f84
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 29 deletions.
15 changes: 6 additions & 9 deletions Cargo.lock

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

8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ revm-primitives = "1.1"
reth-rlp = { git = "https://github.com/paradigmxyz/reth.git", tag = "v0.1.0-alpha.7" }

# Starknet deps
cairo-vm = "0.8.2"
cairo-vm = "=0.8.2"
blockifier = { package = "blockifier", git = "https://github.com/starkware-libs/blockifier.git", tag = "v0.3.0-rc0" }
starknet = "0.6.0"
starknet_api = "0.5.0-rc1"
Expand Down Expand Up @@ -70,6 +70,12 @@ log4rs = "1.2.0"
[patch."https://github.com/ethereum/c-kzg-4844"]
c-kzg = { git = "https://github.com/rjected/c-kzg-4844", branch = "dan/add-serde-feature" }

[patch."https://github.com/starkware-libs/blockifier.git"]
blockifier = { package = "blockifier", git = "https://github.com/kkrt-labs/blockifier.git", branch = "v0.3.0-rc0" }


[patch.crates-io]
revm = { git = "https://github.com/bluealloy/revm/", branch = "release/v25" }
revm-primitives = { git = "https://github.com/bluealloy/revm/", branch = "release/v25" }
cairo-felt = { git = "https://github.com/kkrt-labs/cairo-vm.git", branch = "v0.8.2" }
cairo-vm = { git = "https://github.com/kkrt-labs/cairo-vm.git", branch = "v0.8.2" }
17 changes: 8 additions & 9 deletions crates/ef-testing/src/evm_sequencer/evm_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl EvmState for KakarotSequencer {
for ((var, keys), v) in storage {
(&mut self.0.state).set_storage_at(
starknet_address,
get_storage_var_address(var, &keys).unwrap(), // safe unwrap: all vars are ASCII
get_storage_var_address(var, &keys),
v,
);
}
Expand All @@ -120,7 +120,7 @@ impl EvmState for KakarotSequencer {
// Add the address to the Kakarot evm to starknet mapping
(&mut self.0.state).set_storage_at(
*KAKAROT_ADDRESS,
get_storage_var_address("evm_to_starknet_address", &[evm_address]).unwrap(),
get_storage_var_address("evm_to_starknet_address", &[evm_address]),
*starknet_address.0.key(),
);
Ok(())
Expand Down Expand Up @@ -185,7 +185,7 @@ impl EvmState for KakarotSequencer {
let implementation = (&mut self.0.state)
.get_storage_at(
starknet_address.try_into()?,
get_storage_var_address("_implementation", &[])?,
get_storage_var_address("_implementation", &[]),
)
.unwrap();

Expand All @@ -194,7 +194,7 @@ impl EvmState for KakarotSequencer {
.get_nonce_at(starknet_address.try_into()?)?
.0
} else if implementation == CONTRACT_ACCOUNT_CLASS_HASH.0 {
let key = get_storage_var_address("nonce", &[])?;
let key = get_storage_var_address("nonce", &[]);
(&mut self.0.state).get_storage_at(starknet_address.try_into()?, key)?
} else {
// We can't throw an error here, because it could just be an uninitialized account.
Expand All @@ -214,7 +214,7 @@ impl EvmState for KakarotSequencer {

let bytecode_len = (&mut self.0.state).get_storage_at(
starknet_address.try_into()?,
get_storage_var_address("bytecode_len_", &[])?,
get_storage_var_address("bytecode_len_", &[]),
)?;
let bytecode_len: u64 = bytecode_len.try_into()?;
if bytecode_len == 0 {
Expand All @@ -226,13 +226,13 @@ impl EvmState for KakarotSequencer {
let mut bytecode: Vec<u8> = Vec::new();

for chunk_index in 0..num_chunks {
let key = get_storage_var_address("bytecode_", &[StarkFelt::from(chunk_index)])?;
let key = get_storage_var_address("bytecode_", &[StarkFelt::from(chunk_index)]);
let code = (&mut self.0.state).get_storage_at(starknet_address.try_into()?, key)?;
bytecode.append(&mut high_16_bytes_of_felt_to_bytes(&code.into(), 16).to_vec());
}

let remainder = bytecode_len % 16;
let key = get_storage_var_address("bytecode_", &[StarkFelt::from(num_chunks)])?;
let key = get_storage_var_address("bytecode_", &[StarkFelt::from(num_chunks)]);
let code = (&mut self.0.state).get_storage_at(starknet_address.try_into()?, key)?;
bytecode
.append(&mut high_16_bytes_of_felt_to_bytes(&code.into(), remainder as usize).to_vec());
Expand Down Expand Up @@ -324,8 +324,7 @@ mod tests {
let storage = (&mut sequencer.0.state)
.get_storage_at(
contract_starknet_address,
get_storage_var_address("storage_", &[StarkFelt::from(0u8), StarkFelt::from(0u8)])
.unwrap(),
get_storage_var_address("storage_", &[StarkFelt::from(0u8), StarkFelt::from(0u8)]),
)
.unwrap();
assert_eq!(storage, StarkFelt::from(1u8));
Expand Down
2 changes: 1 addition & 1 deletion crates/ef-testing/src/evm_sequencer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl KakarotSequencer {
for (k, v) in storage {
(&mut self.0.state).set_storage_at(
*KAKAROT_ADDRESS,
get_storage_var_address(k, &[]).unwrap(), // safe unwrap: all vars are ASCII
get_storage_var_address(k, &[]),
v,
);
}
Expand Down
12 changes: 3 additions & 9 deletions crates/sequencer/src/sequencer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ mod tests {
fn fund(address: StarkFelt, mut state: &mut State) {
state.set_storage_at(
*ETH_FEE_TOKEN_ADDRESS,
get_storage_var_address("ERC20_balances", &[address]).unwrap(),
get_storage_var_address("ERC20_balances", &[address]),
StarkFelt::from(u128::MAX),
);
}
Expand Down Expand Up @@ -263,10 +263,7 @@ mod tests {
// Then
let expected = StarkFelt::from(1u8);
let actual = (&mut sequencer.state)
.get_storage_at(
*TEST_CONTRACT,
get_storage_var_address("counter", &[]).unwrap(),
)
.get_storage_at(*TEST_CONTRACT, get_storage_var_address("counter", &[]))
.unwrap();
assert_eq!(expected, actual);
}
Expand Down Expand Up @@ -303,10 +300,7 @@ mod tests {
// Then
let expected = StarkFelt::from(1u8);
let actual = (&mut sequencer.state)
.get_storage_at(
*TEST_CONTRACT,
get_storage_var_address("counter", &[]).unwrap(),
)
.get_storage_at(*TEST_CONTRACT, get_storage_var_address("counter", &[]))
.unwrap();
assert_eq!(expected, actual);
}
Expand Down

0 comments on commit 4752f84

Please sign in to comment.