Skip to content

Commit 5c7a304

Browse files
ManuelBilbaojrchatrucfedackingavilagaston9
authored
feat(l2): add support for web3signer (#2714)
**Motivation** <!-- Why does this pull request exist? What are its goals? --> Many operators will want to use a remote signer instead of having the private keys on the same server as the sequencer. **Description** <!-- A clear and concise general description of the changes this PR introduces --> Replace all uses of a private key with a new `Signer` enum. This signer can be either `Local` or `Remote` and can be lately extended. This aims to standardise the way all kind of messages are signed across the L2 and facilitate the setup via flags or environment <!-- Link to issues: Resolves #111, Resolves #222 --> --------- Co-authored-by: Javier Rodríguez Chatruc <[email protected]> Co-authored-by: fedacking <[email protected]> Co-authored-by: Avila Gastón <[email protected]>
1 parent fd98ef0 commit 5c7a304

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1528
-604
lines changed

.github/workflows/pr-main_l2.yaml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,16 @@ jobs:
5858
include:
5959
- name: "Validium"
6060
validium: true
61+
web3signer: false
62+
compose_targets: [docker-compose-l2.yaml]
6163
- name: "Vanilla"
6264
validium: false
65+
web3signer: false
66+
compose_targets: [docker-compose-l2.yaml]
67+
- name: "Vanilla with Web3signer"
68+
validium: false
69+
web3signer: true
70+
compose_targets: [docker-compose-l2.yaml, docker-compose-l2-web3signer.yaml]
6371
steps:
6472
- name: Checkout sources
6573
uses: actions/checkout@v4
@@ -83,6 +91,12 @@ jobs:
8391
run: |
8492
cargo test l2 --no-run --release
8593
94+
- name: Start Web3Signer
95+
if: matrix.web3signer
96+
run: |
97+
cd crates/l2
98+
docker compose -f ${{ join(matrix.compose_targets, ' -f ') }} up --detach web3signer
99+
86100
- name: Build L1 docker image
87101
uses: docker/build-push-action@v6
88102
with:
@@ -109,7 +123,7 @@ jobs:
109123
CI_ETHREX_WORKDIR=/usr/local/bin \
110124
ETHREX_L2_VALIDIUM=${{ matrix.validium }} \
111125
ETHREX_WATCHER_BLOCK_DELAY=0 \
112-
docker compose -f docker-compose-l2.yaml up --detach ethrex_l2
126+
docker compose -f ${{ join(matrix.compose_targets, ' -f ') }} up --detach ethrex_l2
113127
114128
- name: Run test
115129
run: |

Cargo.lock

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ axum = "0.8.1"
9696
clap = { version = "4.3", features = ["derive", "env"] }
9797
clap_complete = "4.5.17"
9898
eyre = "0.6.12"
99+
rustc-hex = "2.1.0"
100+
url = "2.5.4"
99101
kzg-rs = "0.2.6"
100102
libsql = "0.9.10"
101103
futures = "0.3.31"

cmd/ethrex/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,15 @@ lazy_static.workspace = true
4141
secp256k1 = { workspace = true }
4242
keccak-hash.workspace = true
4343
reqwest.workspace = true
44+
thiserror.workspace = true
4445
itertools = "0.14.0"
4546
tui-logger.workspace = true
4647

4748
cfg-if = "1.0.0"
4849

4950
ethrex-dev = { path = "../../crates/blockchain/dev", optional = true }
5051
ethrex-metrics = { path = "../../crates/blockchain/metrics" }
52+
url.workspace = true
5153

5254
[[bin]]
5355
name = "ethrex"

cmd/ethrex/bench/build_block_benchmark.rs

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ use ethrex_blockchain::{
1414
payload::{BuildPayloadArgs, PayloadBuildResult, create_payload},
1515
};
1616
use ethrex_common::{
17-
Address, H160, U256,
17+
Address, H160,
1818
types::{
19-
Block, EIP1559Transaction, Genesis, GenesisAccount, LegacyTransaction, Signable,
20-
Transaction, TxKind, payload::PayloadBundle,
19+
Block, EIP1559Transaction, Genesis, GenesisAccount, Transaction, TxKind,
20+
payload::PayloadBundle,
2121
},
2222
};
23+
use ethrex_l2_rpc::signer::{LocalSigner, Signable, Signer};
2324
use ethrex_storage::{EngineType, Store};
2425
use ethrex_vm::EvmEngine;
2526
use secp256k1::SecretKey;
@@ -112,19 +113,8 @@ fn read_private_keys() -> Vec<SecretKey> {
112113
}
113114

114115
fn recover_address_for_sk(sk: &SecretKey) -> Address {
115-
let mut tx = Transaction::LegacyTransaction(LegacyTransaction {
116-
nonce: 0,
117-
gas_price: 1,
118-
to: TxKind::Call(H160::random()),
119-
value: U256::zero(),
120-
data: Bytes::new(),
121-
v: U256::one(),
122-
r: U256::one(),
123-
s: U256::one(),
124-
gas: 21000,
125-
});
126-
tx.sign_inplace(sk).expect("Unreachable error: Digest to sign should be correct size since it's calculated with the keccak algorithm");
127-
tx.sender().expect("Failed to recover sender's address")
116+
let signer = Signer::Local(LocalSigner::new(*sk));
117+
signer.address()
128118
}
129119

130120
async fn setup_genesis(accounts: &Vec<Address>) -> (Store, Genesis) {
@@ -171,6 +161,7 @@ async fn create_payload_block(genesis_block: &Block, store: &Store) -> (Block, u
171161
async fn fill_mempool(b: &Blockchain, accounts: Vec<SecretKey>) {
172162
let mut txs = vec![];
173163
for sk in accounts {
164+
let signer = Signer::Local(LocalSigner::new(sk));
174165
for n in 0..1000 {
175166
let mut tx = Transaction::EIP1559Transaction(EIP1559Transaction {
176167
nonce: n,
@@ -182,7 +173,7 @@ async fn fill_mempool(b: &Blockchain, accounts: Vec<SecretKey>) {
182173
to: TxKind::Call(H160::random()),
183174
..Default::default()
184175
});
185-
tx.sign_inplace(&sk).expect("Unreachable error: Digest to sign should be correct size since it's calculated with the keccak algorithm");
176+
let _ = tx.sign_inplace(&signer).await;
186177
txs.push(tx);
187178
}
188179
}

cmd/ethrex/l2/command.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use std::{
4141
};
4242
use tokio::sync::Mutex;
4343
use tokio_util::task::TaskTracker;
44-
use tracing::info;
44+
use tracing::{error, info};
4545

4646
#[allow(clippy::large_enum_variant)]
4747
#[derive(Subcommand)]
@@ -199,7 +199,10 @@ impl Command {
199199
info!("P2P is disabled");
200200
}
201201

202-
let l2_sequencer_cfg = SequencerConfig::from(opts.sequencer_opts);
202+
let l2_sequencer_cfg =
203+
SequencerConfig::try_from(opts.sequencer_opts).inspect_err(|err| {
204+
error!("{err}");
205+
})?;
203206

204207
let l2_sequencer = ethrex_l2::start_l2(
205208
store,

0 commit comments

Comments
 (0)