Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: evm sequencer #316

Merged
merged 24 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
name: Workflow - CI

on:
push:
branches: [main]
pull_request:
branches:
- main

permissions: read-all

jobs:
trunk:
name: Trunk
uses: ./.github/workflows/trunk-check.yml
permissions:
checks: write
contents: read

submodules:
name: Compile Kakarot contracts
uses: ./.github/workflows/kakarot.yml

tests:
name: Rust tests
uses: ./.github/workflows/test.yml
needs: submodules
35 changes: 35 additions & 0 deletions .github/workflows/kakarot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Kakarot compilation caching

on:
workflow_call: {}

permissions: read-all

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-submodules
cancel-in-progress: true

jobs:
submodules:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.9
uses: actions/setup-python@v4
with:
python-version: 3.9
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
- name: pull kakarot submodule and setup
run: make setup-kakarot
- name: Save compiled kakarot contracts
id: cached-contracts
uses: actions/cache/save@v3
with:
path: ./lib/kakarot/build
key: ${{ runner.os }}-contracts
19 changes: 10 additions & 9 deletions .github/workflows/test.yml
greged93 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
name: test

on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_call: {}

permissions: read-all

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
group: ${{ github.workflow }}-${{ github.ref }}-test
cancel-in-progress: true

jobs:
test:
runs-on: ubuntu-latest
# trunk-ignore(actionlint/runner-label)
runs-on: ubuntu-latest-16-cores
greged93 marked this conversation as resolved.
Show resolved Hide resolved
timeout-minutes: 120
steps:
- uses: actions/checkout@v3
- name: Load compiled kakarot contracts
id: cached-contracts
uses: actions/cache/restore@v3
with:
path: ./lib/kakarot/build
key: ${{ runner.os }}-contracts
- name: Setup rust env
uses: actions-rs/toolchain@v1
with:
Expand All @@ -26,13 +30,10 @@ jobs:
override: true
- name: Retrieve cached dependencies
uses: Swatinem/rust-cache@v2
# fetch ef tests
- name: fetch ef tests
run: make setup
# fetch dump
- name: fetch dump
run: GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} make fetch-dump
- uses: taiki-e/install-action@nextest
# run tests
- name: run tests
run: make ef-tests
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
name: Trunk

on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_call: {}

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
group: ${{ github.workflow }}-${{ github.ref }}-trunk
cancel-in-progress: true

permissions: read-all

jobs:
trunk_check:
name: Trunk Check Runner
runs-on: ubuntu-latest
# trunk-ignore(checkov/CKV2_GHA_1)
permissions:
checks: write # For trunk to post annotations
contents: read # For repo checkout
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "kakarot"]
path = lib/kakarot
url = https://github.com/kkrt-labs/kakarot.git
1 change: 1 addition & 0 deletions .trunk/trunk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ lint:
cargo clippy --message-format json --locked --workspace
--all-features --all-targets -- --cap-lints=warn --no-deps -D
warnings
run_timeout: 20m
enabled:
- actionlint@1.6.26
- checkov@2.4.9
Expand Down
8 changes: 6 additions & 2 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ kakarot-rpc-core = { git = "https://github.com/kkrt-labs/kakarot-rpc.git", rev =
kakarot-test-utils = { git = "https://github.com/kkrt-labs/kakarot-rpc.git", rev = "ae5e220" }

# Starknet deps
cairo-vm = "0.8.2"
blockifier = { package = "blockifier", git = "https://github.com/starkware-libs/blockifier.git", tag = "v0.3.0-rc0" }
ClementWalter marked this conversation as resolved.
Show resolved Hide resolved
katana-core = { git = 'https://github.com/dojoengine/dojo', rev = "b924dac" }
dojo-test-utils = { git = 'https://github.com/dojoengine/dojo', rev = "b924dac" }

Expand Down
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ KAKAROT_COMMIT := .katana/remote_kakarot_sha

# Ensures the commands for $(EF_TESTS_DIR) always run on `make setup`, regardless if the directory exists
.PHONY: $(EF_TESTS_DIR)
setup: $(EF_TESTS_DIR)
setup: $(EF_TESTS_DIR)

setup-kakarot: pull-kakarot
cd lib/kakarot && make setup && make build

pull-kakarot:
git submodule update --init --recursive

fetch-dump: fetch-kakarot-submodule-commit
cargo run --features dump --bin fetch-dump-katana
Expand Down
3 changes: 3 additions & 0 deletions crates/ef-testing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ reth-rlp = { workspace = true }
# Kakarot deps
kakarot-rpc-core = { workspace = true }
kakarot-test-utils = { workspace = true }
sequencer = { path = "../sequencer" }

# Starknet deps
blockifier = { workspace = true }
cairo-vm = { workspace = true }
dojo-test-utils = { workspace = true }
katana-core = { workspace = true }
starknet_api = { workspace = true }
Expand Down
100 changes: 100 additions & 0 deletions crates/ef-testing/src/evm_sequencer/constants.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
use std::{collections::HashMap, sync::Arc};

use blockifier::block_context::BlockContext;
use lazy_static::lazy_static;
use starknet::core::types::{contract::legacy::LegacyContractClass, FieldElement};
use starknet_api::{
block::{BlockNumber, BlockTimestamp},
core::{ChainId, ClassHash, ContractAddress, PatriciaKey},
hash::StarkFelt,
};

lazy_static! {
// Chain params
pub static ref CHAIN_ID: u64 = 0x4b4b5254;

// Vm resources: maps resource name to fee cost.
pub static ref VM_RESOURCES: HashMap<String, f64> = [
(String::from("n_steps"), 1_f64),
("pedersen_builtin".to_string(), 1_f64),
("range_check_builtin".to_string(), 1_f64),
("ecdsa_builtin".to_string(), 1_f64),
("bitwise_builtin".to_string(), 1_f64),
("poseidon_builtin".to_string(), 1_f64),
("output_builtin".to_string(), 1_f64),
("ec_op_builtin".to_string(), 1_f64),
("keccak_builtin".to_string(), 1_f64),
("segment_arena_builtin".to_string(), 1_f64),
]
.into_iter()
.collect();

// Block context
pub static ref BLOCK_CONTEXT: BlockContext = BlockContext {
chain_id: ChainId(String::from_utf8(CHAIN_ID.to_be_bytes().to_vec()).unwrap()),
block_number: BlockNumber(0),
block_timestamp: BlockTimestamp(0),
sequencer_address: *SEQUENCER_ADDRESS,
fee_token_address: *FEE_TOKEN_ADDRESS,
vm_resource_fee_cost: Arc::new(VM_RESOURCES.clone()),
gas_price: 1,
invoke_tx_max_n_steps: 2_u32.pow(24),
validate_max_n_steps: 2_u32.pow(24),
max_recursion_depth: 1024,
};

// Main addresses
pub static ref SEQUENCER_ADDRESS: ContractAddress = ContractAddress(
TryInto::<PatriciaKey>::try_into(StarkFelt::from(
FieldElement::from_hex_be(
"0x01176a1bd84444c89232ec27754698e5d2e7e1a7f1539f12027f28b23ec9f3d8"
)
.unwrap()
))
.unwrap()
);
pub static ref FEE_TOKEN_ADDRESS: ContractAddress = ContractAddress(
TryInto::<PatriciaKey>::try_into(StarkFelt::from(
FieldElement::from_hex_be(
"0x049D36570D4e46f48e99674bd3fcc84644DdD6b96F7C741B1562B82f9e004dC7"
)
.unwrap()
))
.unwrap()
);
pub static ref KAKAROT_ADDRESS: ContractAddress =
ContractAddress(TryInto::<PatriciaKey>::try_into(StarkFelt::from(1_u8)).unwrap());
pub static ref KAKAROT_OWNER_ADDRESS: ContractAddress =
ContractAddress(TryInto::<PatriciaKey>::try_into(StarkFelt::from(2_u8)).unwrap());

// Main contract classes
pub static ref KAKAROT_CLASS: LegacyContractClass = serde_json::from_reader::<_, LegacyContractClass>(std::fs::File::open("../../lib/kakarot/build/kakarot.json").unwrap()).unwrap();
pub static ref CONTRACT_ACCOUNT_CLASS: LegacyContractClass = serde_json::from_reader::<_, LegacyContractClass>(std::fs::File::open("../../lib/kakarot/build/contract_account.json").unwrap()).unwrap();
pub static ref EOA_CLASS: LegacyContractClass = serde_json::from_reader::<_, LegacyContractClass>(std::fs::File::open("../../lib/kakarot/build/externally_owned_account.json").unwrap()).unwrap();
pub static ref PROXY_CLASS: LegacyContractClass = serde_json::from_reader::<_, LegacyContractClass>(std::fs::File::open("../../lib/kakarot/build/proxy.json").unwrap()).unwrap();

// Main class hashes
pub static ref KAKAROT_CLASS_HASH: ClassHash = ClassHash(KAKAROT_CLASS.class_hash().unwrap().into());
pub static ref CONTRACT_ACCOUNT_CLASS_HASH: ClassHash = ClassHash(CONTRACT_ACCOUNT_CLASS.class_hash().unwrap().into());
pub static ref EOA_CLASS_HASH: ClassHash = ClassHash(EOA_CLASS.class_hash().unwrap().into());
pub static ref PROXY_CLASS_HASH: ClassHash = ClassHash(PROXY_CLASS.class_hash().unwrap().into());

}

#[cfg(test)]
pub mod tests {
use std::str::FromStr;

use lazy_static::lazy_static;
use reth_primitives::Address;
use revm_primitives::B256;

lazy_static! {
pub static ref PRIVATE_KEY: B256 =
B256::from_str("0x6ae82d865482a203603ecbf25c865e082396d7705a6bbce92c1ff1d6ab9b503c")
.unwrap();
pub static ref PUBLIC_KEY: Address =
Address::from_str("0x7513A12F74fFF533ee12F20EE524e4883CBd1945").unwrap();
pub static ref TEST_CONTRACT_ADDRESS: Address = Address::from_low_u64_be(10);
}
}
Loading
Loading