Skip to content

Commit

Permalink
feat(prover): BOSD Descriptor instead of X-only PK
Browse files Browse the repository at this point in the history
  • Loading branch information
storopoli committed Jan 13, 2025
1 parent 35180d0 commit 5471b8f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
3 changes: 2 additions & 1 deletion crates/proof-impl/evm-ee-stf/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ pub fn generate_exec_update(el_proof_pp: &EvmBlockStfOutput) -> ExecSegment {
.map(|intent| {
bridge_ops::WithdrawalIntent::new(
BitcoinAmount::from_sat(intent.amt),
XOnlyPk::new(intent.dest_pk.into()),
// FIXME: This should be a BOSD Descriptor.
intent.destination,
)
})
.collect::<Vec<_>>();
Expand Down
25 changes: 12 additions & 13 deletions crates/reth/evm/src/precompiles/bridge.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
use std::array::TryFromSliceError;

use revm::{
primitives::{PrecompileError, PrecompileErrors, PrecompileOutput, PrecompileResult},
ContextStatefulPrecompile, Database,
};
use revm_primitives::{Bytes, FixedBytes, Log, LogData, U256};
use revm_primitives::{Bytes, Log, LogData, U256};
use strata_primitives::bitcoin_bosd::Descriptor;
use strata_reth_primitives::WithdrawalIntentEvent;

pub use crate::constants::BRIDGEOUT_ADDRESS;
use crate::utils::wei_to_sats;

/// Ensure that input is exactly 32 bytes
fn try_into_pubkey(maybe_pubkey: &Bytes) -> Result<FixedBytes<32>, TryFromSliceError> {
maybe_pubkey.as_ref().try_into()
}

/// Custom precompile to burn rollup native token and add bridge out intent of equal amount.
/// Bridge out intent is created during block payload generation.
/// This precompile validates transaction and burns the bridge out amount.
Expand All @@ -30,16 +24,17 @@ impl BridgeoutPrecompile {
}
}

// TODO: Change this to a Binary Output Script Descriptor (BOSD) instead of a Schnorr pubkey.
impl<DB: Database> ContextStatefulPrecompile<DB> for BridgeoutPrecompile {
fn call(
&self,
dest_pk_bytes: &Bytes,
destination_bytes: &Bytes,
_gas_limit: u64,
evmctx: &mut revm::InnerEvmContext<DB>,
) -> PrecompileResult {
// Validate the length of the destination public key
let dest_pk = try_into_pubkey(dest_pk_bytes)
.map_err(|_| PrecompileError::other("Invalid public key length: expected 32 bytes"))?;
// Validate the descriptor
let destination = Descriptor::from_bytes(destination_bytes.as_ref())
.map_err(|_| PrecompileError::other("Invalid destination descriptor"))?;

// Verify that the transaction value matches the required withdrawal amount
let withdrawal_amount = evmctx.env.tx.value;
Expand All @@ -59,7 +54,11 @@ impl<DB: Database> ContextStatefulPrecompile<DB> for BridgeoutPrecompile {
})?;

// Log the bridge withdrawal intent
let evt = WithdrawalIntentEvent { amount, dest_pk };
let evt = WithdrawalIntentEvent {
amount,
// FIXME: How to make this work with a BOSD Descriptor.
destination,
};
let logdata = LogData::from(&evt);

evmctx.journaled_state.log(Log {
Expand Down
2 changes: 1 addition & 1 deletion crates/reth/evm/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub fn collect_withdrawal_intents(
WithdrawalIntentEvent::decode_log(&log, true)
.map(|evt| WithdrawalIntent {
amt: evt.amount,
dest_pk: evt.dest_pk,
destination: evt.destination,
})
.ok()
})
Expand Down
6 changes: 4 additions & 2 deletions crates/reth/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ pub struct WithdrawalIntent {
pub amt: u64,

/// Destination public key for the withdrawal
pub dest_pk: B256,
// FIXME: How do I use a BOSD Descriptor here?
pub destination: B256,
}

sol! {
Expand All @@ -22,6 +23,7 @@ sol! {
/// Withdrawal amount in sats
uint64 amount,
/// 32 bytes pubkey for withdrawal address in L1
bytes32 dest_pk,
// FIXME: How do I use a BOSD Descriptor here?
bytes32 destination,
);
}

0 comments on commit 5471b8f

Please sign in to comment.