Skip to content

Commit

Permalink
add signed bundles
Browse files Browse the repository at this point in the history
  • Loading branch information
itamarreif committed Nov 19, 2024
1 parent b3fa694 commit 14c7b93
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
1 change: 1 addition & 0 deletions crates/astria-auctioneer/src/auction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ impl Auction {
.into_transaction_body(
nonce,
self.rollup_id,
self.sequencer_key.clone(),
self.fee_asset_denomination.clone(),
self.sequencer_chain_id,
);
Expand Down
49 changes: 44 additions & 5 deletions crates/astria-auctioneer/src/bundle/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use astria_core::{
crypto::{
Signature,
VerificationKey,
},
generated::bundle::v1alpha1::{
self as raw,
},
Expand All @@ -19,6 +23,8 @@ use bytes::Bytes;
pub(crate) use client::BundleStream;
use prost::Message as _;

use crate::sequencer_key::SequencerKey;

mod client;

// TODO: this should probably be moved to astria_core::bundle?
Expand Down Expand Up @@ -71,19 +77,18 @@ impl Bundle {
self,
nonce: u32,
rollup_id: RollupId,
sequencer_key: SequencerKey,
fee_asset: asset::Denom,
chain_id: String,
) -> TransactionBody {
let data = self.into_raw().encode_to_vec();

// TODO: sign the bundle data and put it in a `SignedBundle` message or something (need to
// update protos for this)
let allocation = Allocation::new(self, sequencer_key);
let allocation_data = allocation.into_raw().encode_to_vec();

TransactionBody::builder()
.actions(vec![
RollupDataSubmission {
rollup_id,
data: data.into(),
data: allocation_data.into(),
fee_asset,
}
.into(),
Expand All @@ -106,3 +111,37 @@ impl Bundle {
self.base_sequencer_block_hash
}
}

#[derive(Debug)]
pub(crate) struct Allocation {
signature: Signature,
verification_key: VerificationKey,
payload: Bundle,
}

impl Allocation {
fn new(bundle: Bundle, sequencer_key: SequencerKey) -> Self {
let bundle_data = bundle.clone().into_raw().encode_to_vec();
let signature = sequencer_key.signing_key().sign(&bundle_data);
let verification_key = sequencer_key.signing_key().verification_key();
Self {
signature,
verification_key,
payload: bundle,
}
}

fn into_raw(self) -> raw::Allocation {
let Self {
signature,
verification_key,
payload,
} = self;

raw::Allocation {
signature: Bytes::copy_from_slice(&signature.to_bytes()),
public_key: Bytes::copy_from_slice(&verification_key.to_bytes()),
payload: Some(payload.into_raw()),
}
}
}

0 comments on commit 14c7b93

Please sign in to comment.