Skip to content
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
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions crates/op-rbuilder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ http = "1.0"
sha3 = "0.10"
hex = "0.4"
ureq = "2.10"
k256 = "0.13.4"

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

Expand Down
23 changes: 15 additions & 8 deletions crates/op-rbuilder/src/flashtestations/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,24 @@ pub struct FlashtestationsArgs {
)]
pub debug: bool,

// Debug url for attestations
#[arg(long = "flashtestations.debug-url", env = "FLASHTESTATIONS_DEBUG_URL")]
pub debug_url: Option<String>,
// Debug static key for the tee key. DO NOT USE IN PRODUCTION
#[arg(
long = "flashtestations.debug-tee-key-seed",
env = "FLASHTESTATIONS_DEBUG_TEE_KEY_SEED",
default_value = "debug"
)]
pub debug_tee_key_seed: String,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be Option?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also mark somehow that it's not for production

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it has a default value and won't be used if debug not enabled so it won't be a required arg. Option will be same logic by having .unwrap_else("debug")


/// The rpc url to post the onchain attestation requests to
// Remote url for attestations
#[arg(
long = "flashtestations.rpc-url",
env = "FLASHTESTATIONS_RPC_URL",
default_value = "http://localhost:8545"
long = "flashtestations.quote-provider",
env = "FLASHTESTATIONS_QUOTE_PROVIDER"
)]
pub rpc_url: String,
pub quote_provider: Option<String>,

/// The rpc url to post the onchain attestation requests to
#[arg(long = "flashtestations.rpc-url", env = "FLASHTESTATIONS_RPC_URL")]
pub rpc_url: Option<String>,

/// Funding key for the TEE key
#[arg(
Expand Down
23 changes: 12 additions & 11 deletions crates/op-rbuilder/src/flashtestations/attestation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,27 @@ const DEBUG_QUOTE_SERVICE_URL: &str = "http://ns31695324.ip-141-94-163.eu:10080/
pub struct AttestationConfig {
/// If true, uses the debug HTTP service instead of real TDX hardware
pub debug: bool,
/// The URL of the debug HTTP service
pub debug_url: Option<String>,
/// The URL of the quote provider
pub quote_provider: Option<String>,
}

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

/// Debug HTTP service attestation provider
pub struct DebugAttestationProvider {
/// Remote attestation provider
pub struct RemoteAttestationProvider {
service_url: String,
}

impl DebugAttestationProvider {
impl RemoteAttestationProvider {
pub fn new(service_url: String) -> Self {
Self { service_url }
}
}

impl AttestationProvider for DebugAttestationProvider {
impl AttestationProvider for RemoteAttestationProvider {
fn get_attestation(&self, report_data: [u8; 64]) -> eyre::Result<Vec<u8>> {
let report_data_hex = hex::encode(report_data);
let url = format!("{}/{}", self.service_url, report_data_hex);
Expand All @@ -51,15 +51,16 @@ pub fn get_attestation_provider(
config: AttestationConfig,
) -> Box<dyn AttestationProvider + Send + Sync> {
if config.debug {
Box::new(DebugAttestationProvider::new(
Box::new(RemoteAttestationProvider::new(
config
.debug_url
.quote_provider
.unwrap_or(DEBUG_QUOTE_SERVICE_URL.to_string()),
))
} else {
// TODO: replace with real attestation provider
Box::new(DebugAttestationProvider::new(
DEBUG_QUOTE_SERVICE_URL.to_string(),
Box::new(RemoteAttestationProvider::new(
config
.quote_provider
.expect("remote quote provider must be specified when not in debug mode"),
))
}
}
5 changes: 3 additions & 2 deletions crates/op-rbuilder/src/flashtestations/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,15 @@ impl FlashtestationsService {

let attestation_provider = Arc::new(get_attestation_provider(AttestationConfig {
debug: args.debug,
debug_url: args.debug_url,
quote_provider: args.quote_provider,
}));

let tx_manager = TxManager::new(
tee_service_signer,
args.funding_key
.expect("funding key required when flashtestations enabled"),
args.rpc_url,
args.rpc_url
.expect("external rpc url required when flashtestations enabled"),
args.registry_address
.expect("registry address required when flashtestations enabled"),
args.builder_policy_address
Expand Down
18 changes: 18 additions & 0 deletions crates/op-rbuilder/src/tx_signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::str::FromStr;

use alloy_consensus::SignableTransaction;
use alloy_primitives::{Address, B256, Signature, U256};
use k256::sha2::Sha256;
use op_alloy_consensus::OpTypedTransaction;
use reth_optimism_primitives::OpTransactionSigned;
use reth_primitives::Recovered;
Expand Down Expand Up @@ -100,6 +101,23 @@ pub fn public_key_to_address(public_key: &PublicKey) -> Address {
Address::from_slice(&hash[12..32])
}

// Generate a key deterministically from a seed for debug and testing
// Do not use in production
pub fn generate_key_from_seed(seed: &str) -> (SecretKey, PublicKey, Address) {
// Hash the seed
let mut hasher = Sha256::new();
hasher.update(seed.as_bytes());
let hash = hasher.finalize();

// Create signing key
let secp = Secp256k1::new();
let private_key = SecretKey::from_slice(&hash).expect("Failed to create private key");
let public_key = PublicKey::from_secret_key(&secp, &private_key);
let address = public_key_to_address(&public_key);

(private_key, public_key, address)
}

#[cfg(test)]
mod test {
use super::*;
Expand Down
Loading