Skip to content

Commit

Permalink
Return reference from SignedSoftConfirmation fields (#1431)
Browse files Browse the repository at this point in the history
  • Loading branch information
yaziciahmet authored Nov 5, 2024
1 parent 3cd79b6 commit 0b07b0a
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 27 deletions.
2 changes: 1 addition & 1 deletion crates/fullnode/tests/hash_stf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl<C: Context, Da: DaSpec, Vm: Zkvm, Cond: ValidityCondition> StfBlueprintTrai
fn apply_soft_confirmation_txs(
&mut self,
_soft_confirmation_info: HookSoftConfirmationInfo,
_txs: Vec<Vec<u8>>,
_txs: &[Vec<u8>],
_batch_workspace: sov_modules_api::WorkingSet<C>,
) -> (
sov_modules_api::WorkingSet<C>,
Expand Down
4 changes: 2 additions & 2 deletions crates/sequencer/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ where

let (sc_workspace, _) = self.stf.apply_soft_confirmation_txs(
soft_confirmation_info.clone(),
txs.clone(),
&txs,
working_set_to_discard,
);

Expand Down Expand Up @@ -453,7 +453,7 @@ where

(batch_workspace, tx_receipts) = self.stf.apply_soft_confirmation_txs(
soft_confirmation_info,
txs.clone(),
&txs,
batch_workspace,
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl HookSoftConfirmationInfo {
pre_state_root: pre_state_root.to_vec(),
current_spec,
pub_key: signed_soft_confirmation.sequencer_pub_key().to_vec(),
deposit_data: signed_soft_confirmation.deposit_data(),
deposit_data: signed_soft_confirmation.deposit_data().to_vec(),
l1_fee_rate: signed_soft_confirmation.l1_fee_rate(),
timestamp: signed_soft_confirmation.timestamp(),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ pub trait StfBlueprintTrait<C: Context, Da: DaSpec, Vm: Zkvm>:
fn apply_soft_confirmation_txs(
&mut self,
soft_confirmation: HookSoftConfirmationInfo,
txs: Vec<Vec<u8>>,
txs: &[Vec<u8>],
batch_workspace: WorkingSet<C>,
) -> (WorkingSet<C>, Vec<TransactionReceipt<TxEffect>>);

Expand Down Expand Up @@ -229,7 +229,7 @@ where
fn apply_soft_confirmation_txs(
&mut self,
soft_confirmation_info: HookSoftConfirmationInfo,
txs: Vec<Vec<u8>>,
txs: &[Vec<u8>],
batch_workspace: WorkingSet<C>,
) -> (WorkingSet<C>, Vec<TransactionReceipt<TxEffect>>) {
self.apply_sov_txs_inner(soft_confirmation_info, txs, batch_workspace)
Expand All @@ -252,8 +252,8 @@ where
soft_confirmation.da_slot_height(),
soft_confirmation.da_slot_hash(),
soft_confirmation.da_slot_txs_commitment(),
soft_confirmation.txs(),
soft_confirmation.deposit_data(),
soft_confirmation.txs().to_vec(),
soft_confirmation.deposit_data().to_vec(),
soft_confirmation.l1_fee_rate(),
soft_confirmation.timestamp(),
);
Expand All @@ -273,7 +273,7 @@ where
// verify signature
if verify_soft_confirmation_signature::<C>(
unsigned,
soft_confirmation.signature_as_ref(),
soft_confirmation.signature(),
sequencer_public_key,
)
.is_err()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,16 @@ where
pub fn apply_sov_txs_inner(
&mut self,
soft_confirmation_info: HookSoftConfirmationInfo,
txs: Vec<Vec<u8>>,
txs: &[Vec<u8>],
mut sc_workspace: WorkingSet<C>,
) -> (WorkingSet<C>, Vec<TransactionReceipt<TxEffect>>) {
let mut tx_receipts = Vec::with_capacity(txs.len());
for raw_tx in txs {
let raw_tx_hash = <C as Spec>::Hasher::digest(&raw_tx).into();
let raw_tx_hash = <C as Spec>::Hasher::digest(raw_tx).into();
// Stateless verification of transaction, such as signature check
// TODO: https://github.com/chainwayxyz/citrea/issues/1061
let tx = Transaction::<C>::deserialize_reader(&mut &*raw_tx)
let mut reader = std::io::Cursor::new(raw_tx);
let tx = Transaction::<C>::deserialize_reader(&mut reader)
.expect("Sequencer must not include non-deserializable transaction.");
tx.verify()
.expect("Sequencer must include correctly signed transaction.");
Expand Down Expand Up @@ -229,9 +230,9 @@ where
da_slot_height: soft_confirmation.da_slot_height(),
da_slot_hash: soft_confirmation.da_slot_hash().into(),
da_slot_txs_commitment: soft_confirmation.da_slot_txs_commitment().into(),
soft_confirmation_signature: soft_confirmation.signature(),
soft_confirmation_signature: soft_confirmation.signature().to_vec(),
pub_key: soft_confirmation.sequencer_pub_key().to_vec(),
deposit_data: soft_confirmation.deposit_data().clone(),
deposit_data: soft_confirmation.deposit_data().to_vec(),
l1_fee_rate: soft_confirmation.l1_fee_rate(),
timestamp: soft_confirmation.timestamp(),
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,23 +167,18 @@ impl SignedSoftConfirmation {
}

/// Txs of signed batch
pub fn txs(&self) -> Vec<Vec<u8>> {
self.txs.clone()
pub fn txs(&self) -> &[Vec<u8>] {
self.txs.as_slice()
}

/// Deposit data
pub fn deposit_data(&self) -> Vec<Vec<u8>> {
self.deposit_data.clone()
pub fn deposit_data(&self) -> &[Vec<u8>] {
self.deposit_data.as_slice()
}

/// Signature of the sequencer
pub fn signature(&self) -> Vec<u8> {
self.signature.clone()
}

/// Signature of the sequencer as ref
pub fn signature_as_ref(&self) -> &[u8] {
self.signature.as_ref()
pub fn signature(&self) -> &[u8] {
self.signature.as_slice()
}

/// Borsh serialized data
Expand All @@ -197,8 +192,8 @@ impl SignedSoftConfirmation {
}

/// Public key of sequencer
pub fn pub_key(&self) -> Vec<u8> {
self.pub_key.clone()
pub fn pub_key(&self) -> &[u8] {
self.pub_key.as_slice()
}

/// Sets l1 fee rate
Expand Down

0 comments on commit 0b07b0a

Please sign in to comment.