Skip to content

Commit a817850

Browse files
committed
Add remote quote provider arg for flashtestations
1 parent 36260c6 commit a817850

File tree

6 files changed

+50
-21
lines changed

6 files changed

+50
-21
lines changed

Cargo.lock

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

crates/op-rbuilder/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ http = "1.0"
126126
sha3 = "0.10"
127127
hex = "0.4"
128128
ureq = "2.10"
129+
k256 = "0.13.4"
129130

130131
rollup-boost = { git = "https://github.com/flashbots/rollup-boost", rev = "b86af43969557bee18f17ec1d6bcd3e984f910b2" }
131132

crates/op-rbuilder/src/flashtestations/args.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,24 @@ pub struct FlashtestationsArgs {
2323
)]
2424
pub debug: bool,
2525

26-
// Debug url for attestations
27-
#[arg(long = "flashtestations.debug-url", env = "FLASHTESTATIONS_DEBUG_URL")]
28-
pub debug_url: Option<String>,
26+
// Debug static key for the tee key. DO NOT USE IN PRODUCTION
27+
#[arg(
28+
long = "flashtestations.debug-tee-key-seed",
29+
env = "FLASHTESTATIONS_DEBUG_TEE_KEY_SEED",
30+
default_value = "debug"
31+
)]
32+
pub debug_tee_key_seed: String,
2933

30-
/// The rpc url to post the onchain attestation requests to
34+
// Remote url for attestations
3135
#[arg(
32-
long = "flashtestations.rpc-url",
33-
env = "FLASHTESTATIONS_RPC_URL",
34-
default_value = "http://localhost:8545"
36+
long = "flashtestations.quote-provider",
37+
env = "FLASHTESTATIONS_QUOTE_PROVIDER"
3538
)]
36-
pub rpc_url: String,
39+
pub quote_provider: Option<String>,
40+
41+
/// The rpc url to post the onchain attestation requests to
42+
#[arg(long = "flashtestations.rpc-url", env = "FLASHTESTATIONS_RPC_URL")]
43+
pub rpc_url: Option<String>,
3744

3845
/// Funding key for the TEE key
3946
#[arg(

crates/op-rbuilder/src/flashtestations/attestation.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,27 @@ const DEBUG_QUOTE_SERVICE_URL: &str = "http://ns31695324.ip-141-94-163.eu:10080/
99
pub struct AttestationConfig {
1010
/// If true, uses the debug HTTP service instead of real TDX hardware
1111
pub debug: bool,
12-
/// The URL of the debug HTTP service
13-
pub debug_url: Option<String>,
12+
/// The URL of the quote provider
13+
pub quote_provider: Option<String>,
1414
}
1515

1616
/// Trait for attestation providers
1717
pub trait AttestationProvider {
1818
fn get_attestation(&self, report_data: [u8; 64]) -> eyre::Result<Vec<u8>>;
1919
}
2020

21-
/// Debug HTTP service attestation provider
22-
pub struct DebugAttestationProvider {
21+
/// Remote attestation provider
22+
pub struct RemoteAttestationProvider {
2323
service_url: String,
2424
}
2525

26-
impl DebugAttestationProvider {
26+
impl RemoteAttestationProvider {
2727
pub fn new(service_url: String) -> Self {
2828
Self { service_url }
2929
}
3030
}
3131

32-
impl AttestationProvider for DebugAttestationProvider {
32+
impl AttestationProvider for RemoteAttestationProvider {
3333
fn get_attestation(&self, report_data: [u8; 64]) -> eyre::Result<Vec<u8>> {
3434
let report_data_hex = hex::encode(report_data);
3535
let url = format!("{}/{}", self.service_url, report_data_hex);
@@ -51,15 +51,16 @@ pub fn get_attestation_provider(
5151
config: AttestationConfig,
5252
) -> Box<dyn AttestationProvider + Send + Sync> {
5353
if config.debug {
54-
Box::new(DebugAttestationProvider::new(
54+
Box::new(RemoteAttestationProvider::new(
5555
config
56-
.debug_url
56+
.quote_provider
5757
.unwrap_or(DEBUG_QUOTE_SERVICE_URL.to_string()),
5858
))
5959
} else {
60-
// TODO: replace with real attestation provider
61-
Box::new(DebugAttestationProvider::new(
62-
DEBUG_QUOTE_SERVICE_URL.to_string(),
60+
Box::new(RemoteAttestationProvider::new(
61+
config
62+
.quote_provider
63+
.expect("remote quote provider must be specified when not in debug mode"),
6364
))
6465
}
6566
}

crates/op-rbuilder/src/flashtestations/service.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,15 @@ impl FlashtestationsService {
4747

4848
let attestation_provider = Arc::new(get_attestation_provider(AttestationConfig {
4949
debug: args.debug,
50-
debug_url: args.debug_url,
50+
quote_provider: args.quote_provider,
5151
}));
5252

5353
let tx_manager = TxManager::new(
5454
tee_service_signer,
5555
args.funding_key
5656
.expect("funding key required when flashtestations enabled"),
57-
args.rpc_url,
57+
args.rpc_url
58+
.expect("external rpc url required when flashtestations enabled"),
5859
args.registry_address
5960
.expect("registry address required when flashtestations enabled"),
6061
args.builder_policy_address

crates/op-rbuilder/src/tx_signer.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::str::FromStr;
22

33
use alloy_consensus::SignableTransaction;
44
use alloy_primitives::{Address, B256, Signature, U256};
5+
use k256::sha2::Sha256;
56
use op_alloy_consensus::OpTypedTransaction;
67
use reth_optimism_primitives::OpTransactionSigned;
78
use reth_primitives::Recovered;
@@ -100,6 +101,23 @@ pub fn public_key_to_address(public_key: &PublicKey) -> Address {
100101
Address::from_slice(&hash[12..32])
101102
}
102103

104+
// Generate a key deterministically from a seed for debug and testing
105+
// Do not use in production
106+
pub fn generate_key_from_seed(seed: &str) -> (SecretKey, PublicKey, Address) {
107+
// Hash the seed
108+
let mut hasher = Sha256::new();
109+
hasher.update(seed.as_bytes());
110+
let hash = hasher.finalize();
111+
112+
// Create signing key
113+
let secp = Secp256k1::new();
114+
let private_key = SecretKey::from_slice(&hash).expect("Failed to create private key");
115+
let public_key = PublicKey::from_secret_key(&secp, &private_key);
116+
let address = public_key_to_address(&public_key);
117+
118+
(private_key, public_key, address)
119+
}
120+
103121
#[cfg(test)]
104122
mod test {
105123
use super::*;

0 commit comments

Comments
 (0)