Skip to content

Commit 28d63a7

Browse files
committed
Add flashtestations builder transaction
1 parent fa9924e commit 28d63a7

File tree

12 files changed

+1043
-309
lines changed

12 files changed

+1043
-309
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
# TODO: change to rev from main once https://github.com/flashbots/rollup-boost/pull/401 is merged
131132
rollup-boost = { git = "http://github.com/flashbots/rollup-boost", rev = "0c1fb4ce7e00f0afc350f5bf7573b19da6d485ec" }

crates/op-rbuilder/src/builders/context.rs

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use alloy_consensus::{Eip658Value, Transaction, conditional::BlockConditionalAtt
22
use alloy_eips::Typed2718;
33
use alloy_evm::Database;
44
use alloy_op_evm::block::receipt_builder::OpReceiptBuilder;
5-
use alloy_primitives::{Bytes, U256};
5+
use alloy_primitives::{BlockHash, Bytes, U256};
66
use alloy_rpc_types_eth::Withdrawals;
77
use core::fmt::Debug;
88
use op_alloy_consensus::OpDepositReceipt;
@@ -75,41 +75,51 @@ pub struct OpPayloadBuilderCtx<ExtraCtx: Debug + Default = ()> {
7575

7676
impl<ExtraCtx: Debug + Default> OpPayloadBuilderCtx<ExtraCtx> {
7777
/// Returns the parent block the payload will be build on.
78-
pub(super) fn parent(&self) -> &SealedHeader {
78+
pub(crate) fn parent(&self) -> &SealedHeader {
7979
&self.config.parent_header
8080
}
8181

82+
/// Returns the parent hash
83+
pub(crate) fn parent_hash(&self) -> BlockHash {
84+
self.parent().hash()
85+
}
86+
87+
/// Returns the timestamp
88+
pub(crate) fn timestamp(&self) -> u64 {
89+
self.attributes().timestamp()
90+
}
91+
8292
/// Returns the builder attributes.
83-
pub(super) const fn attributes(&self) -> &OpPayloadBuilderAttributes<OpTransactionSigned> {
93+
pub(crate) const fn attributes(&self) -> &OpPayloadBuilderAttributes<OpTransactionSigned> {
8494
&self.config.attributes
8595
}
8696

8797
/// Returns the withdrawals if shanghai is active.
88-
pub(super) fn withdrawals(&self) -> Option<&Withdrawals> {
98+
pub(crate) fn withdrawals(&self) -> Option<&Withdrawals> {
8999
self.chain_spec
90100
.is_shanghai_active_at_timestamp(self.attributes().timestamp())
91101
.then(|| &self.attributes().payload_attributes.withdrawals)
92102
}
93103

94104
/// Returns the block gas limit to target.
95-
pub(super) fn block_gas_limit(&self) -> u64 {
105+
pub(crate) fn block_gas_limit(&self) -> u64 {
96106
self.attributes()
97107
.gas_limit
98108
.unwrap_or(self.evm_env.block_env.gas_limit)
99109
}
100110

101111
/// Returns the block number for the block.
102-
pub(super) fn block_number(&self) -> u64 {
112+
pub(crate) fn block_number(&self) -> u64 {
103113
as_u64_saturated!(self.evm_env.block_env.number)
104114
}
105115

106116
/// Returns the current base fee
107-
pub(super) fn base_fee(&self) -> u64 {
117+
pub(crate) fn base_fee(&self) -> u64 {
108118
self.evm_env.block_env.basefee
109119
}
110120

111121
/// Returns the current blob gas price.
112-
pub(super) fn get_blob_gasprice(&self) -> Option<u64> {
122+
pub(crate) fn get_blob_gasprice(&self) -> Option<u64> {
113123
self.evm_env
114124
.block_env
115125
.blob_gasprice()
@@ -119,7 +129,7 @@ impl<ExtraCtx: Debug + Default> OpPayloadBuilderCtx<ExtraCtx> {
119129
/// Returns the blob fields for the header.
120130
///
121131
/// This will always return `Some(0)` after ecotone.
122-
pub(super) fn blob_fields(&self) -> (Option<u64>, Option<u64>) {
132+
pub(crate) fn blob_fields(&self) -> (Option<u64>, Option<u64>) {
123133
// OP doesn't support blobs/EIP-4844.
124134
// https://specs.optimism.io/protocol/exec-engine.html#ecotone-disable-blob-transactions
125135
// Need [Some] or [None] based on hardfork to match block hash.
@@ -133,7 +143,7 @@ impl<ExtraCtx: Debug + Default> OpPayloadBuilderCtx<ExtraCtx> {
133143
/// Returns the extra data for the block.
134144
///
135145
/// After holocene this extracts the extradata from the paylpad
136-
pub(super) fn extra_data(&self) -> Result<Bytes, PayloadBuilderError> {
146+
pub(crate) fn extra_data(&self) -> Result<Bytes, PayloadBuilderError> {
137147
if self.is_holocene_active() {
138148
self.attributes()
139149
.get_holocene_extra_data(
@@ -148,47 +158,47 @@ impl<ExtraCtx: Debug + Default> OpPayloadBuilderCtx<ExtraCtx> {
148158
}
149159

150160
/// Returns the current fee settings for transactions from the mempool
151-
pub(super) fn best_transaction_attributes(&self) -> BestTransactionsAttributes {
161+
pub(crate) fn best_transaction_attributes(&self) -> BestTransactionsAttributes {
152162
BestTransactionsAttributes::new(self.base_fee(), self.get_blob_gasprice())
153163
}
154164

155165
/// Returns the unique id for this payload job.
156-
pub(super) fn payload_id(&self) -> PayloadId {
166+
pub(crate) fn payload_id(&self) -> PayloadId {
157167
self.attributes().payload_id()
158168
}
159169

160170
/// Returns true if regolith is active for the payload.
161-
pub(super) fn is_regolith_active(&self) -> bool {
171+
pub(crate) fn is_regolith_active(&self) -> bool {
162172
self.chain_spec
163173
.is_regolith_active_at_timestamp(self.attributes().timestamp())
164174
}
165175

166176
/// Returns true if ecotone is active for the payload.
167-
pub(super) fn is_ecotone_active(&self) -> bool {
177+
pub(crate) fn is_ecotone_active(&self) -> bool {
168178
self.chain_spec
169179
.is_ecotone_active_at_timestamp(self.attributes().timestamp())
170180
}
171181

172182
/// Returns true if canyon is active for the payload.
173-
pub(super) fn is_canyon_active(&self) -> bool {
183+
pub(crate) fn is_canyon_active(&self) -> bool {
174184
self.chain_spec
175185
.is_canyon_active_at_timestamp(self.attributes().timestamp())
176186
}
177187

178188
/// Returns true if holocene is active for the payload.
179-
pub(super) fn is_holocene_active(&self) -> bool {
189+
pub(crate) fn is_holocene_active(&self) -> bool {
180190
self.chain_spec
181191
.is_holocene_active_at_timestamp(self.attributes().timestamp())
182192
}
183193

184194
/// Returns true if isthmus is active for the payload.
185-
pub(super) fn is_isthmus_active(&self) -> bool {
195+
pub(crate) fn is_isthmus_active(&self) -> bool {
186196
self.chain_spec
187197
.is_isthmus_active_at_timestamp(self.attributes().timestamp())
188198
}
189199

190200
/// Returns the chain id
191-
pub(super) fn chain_id(&self) -> u64 {
201+
pub(crate) fn chain_id(&self) -> u64 {
192202
self.chain_spec.chain_id()
193203
}
194204
}

crates/op-rbuilder/src/builders/flashblocks/builder_tx.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::{
1414
BuilderTransactionCtx, BuilderTransactionError, BuilderTransactions,
1515
context::OpPayloadBuilderCtx, flashblocks::payload::FlashblocksExtraCtx,
1616
},
17-
flashtestations::service::FlashtestationsBuilderTx,
17+
flashtestations::builder_tx::FlashtestationsBuilderTx,
1818
primitives::reth::ExecutionInfo,
1919
tx_signer::Signer,
2020
};

crates/op-rbuilder/src/builders/standard/builder_tx.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::{
1414
BuilderTransactionCtx, BuilderTransactionError, BuilderTransactions,
1515
context::OpPayloadBuilderCtx,
1616
},
17-
flashtestations::service::FlashtestationsBuilderTx,
17+
flashtestations::builder_tx::FlashtestationsBuilderTx,
1818
primitives::reth::ExecutionInfo,
1919
tx_signer::Signer,
2020
};

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
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: 13 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);
@@ -47,19 +47,21 @@ impl AttestationProvider for DebugAttestationProvider {
4747
}
4848
}
4949

50+
#[allow(clippy::if_same_then_else)]
5051
pub fn get_attestation_provider(
5152
config: AttestationConfig,
5253
) -> Box<dyn AttestationProvider + Send + Sync> {
5354
if config.debug {
54-
Box::new(DebugAttestationProvider::new(
55+
Box::new(RemoteAttestationProvider::new(
5556
config
56-
.debug_url
57+
.quote_provider
5758
.unwrap_or(DEBUG_QUOTE_SERVICE_URL.to_string()),
5859
))
5960
} else {
60-
// TODO: replace with real attestation provider
61-
Box::new(DebugAttestationProvider::new(
62-
DEBUG_QUOTE_SERVICE_URL.to_string(),
61+
Box::new(RemoteAttestationProvider::new(
62+
config
63+
.quote_provider
64+
.unwrap_or(DEBUG_QUOTE_SERVICE_URL.to_string()), // TODO: remove this once we have a real quote provider
6365
))
6466
}
6567
}

0 commit comments

Comments
 (0)