Skip to content

Commit

Permalink
Add ViewNumber to marketplace builder fee signature (#3793)
Browse files Browse the repository at this point in the history
  • Loading branch information
QuentinI authored Oct 30, 2024
1 parent f942200 commit 04e7bd0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
3 changes: 2 additions & 1 deletion crates/testing/src/block_builder/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ where
&self,
_parent_view: u64,
_parent_hash: &VidCommitment,
_view_number: u64,
view_number: u64,
) -> Result<Bundle<TYPES>, BuildError> {
let transactions = self
.transactions
Expand Down Expand Up @@ -170,6 +170,7 @@ where
fee_signature: TYPES::BuilderSignatureKey::sign_sequencing_fee_marketplace(
&self.priv_key.clone(),
fee_amount,
view_number,
)
.expect("Failed to sign fee!"),
};
Expand Down
9 changes: 6 additions & 3 deletions crates/types/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ pub mod null_block {
use crate::{
traits::{
block_contents::BuilderFee,
node_implementation::{NodeType, Versions},
node_implementation::{ConsensusTime, NodeType, Versions},
signature_key::BuilderSignatureKey,
BlockPayload,
},
Expand Down Expand Up @@ -840,8 +840,11 @@ pub mod null_block {
);

if version >= V::Marketplace::VERSION {
match TYPES::BuilderSignatureKey::sign_sequencing_fee_marketplace(&priv_key, FEE_AMOUNT)
{
match TYPES::BuilderSignatureKey::sign_sequencing_fee_marketplace(
&priv_key,
FEE_AMOUNT,
*TYPES::View::genesis(),
) {
Ok(sig) => Some(BuilderFee {
fee_amount: FEE_AMOUNT,
fee_account: pub_key,
Expand Down
21 changes: 18 additions & 3 deletions crates/types/src/traits/signature_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,12 @@ pub trait BuilderSignatureKey:
&self,
signature: &Self::BuilderSignature,
fee_amount: u64,
view_number: u64,
) -> bool {
self.validate_builder_signature(signature, &fee_amount.to_be_bytes())
self.validate_builder_signature(
signature,
&aggregate_fee_data_marketplace(fee_amount, view_number),
)
}

/// validate the bundle's signature using the builder's public key
Expand Down Expand Up @@ -285,12 +289,15 @@ pub trait BuilderSignatureKey:
/// sign fee offer for proposed payload (marketplace version)
/// # Errors
/// If unable to sign the data with the key
// TODO: this should include view number
fn sign_sequencing_fee_marketplace(
private_key: &Self::BuilderPrivateKey,
fee_amount: u64,
view_number: u64,
) -> Result<Self::BuilderSignature, Self::SignError> {
Self::sign_builder_message(private_key, &fee_amount.to_be_bytes())
Self::sign_builder_message(
private_key,
&aggregate_fee_data_marketplace(fee_amount, view_number),
)
}

/// sign transactions (marketplace version)
Expand Down Expand Up @@ -340,6 +347,14 @@ fn aggregate_fee_data<Metadata: EncodeBytes>(
fee_info
}

/// Aggregate all inputs used for signature over fee data
fn aggregate_fee_data_marketplace(fee_amount: u64, view_number: u64) -> Vec<u8> {
let mut fee_info = Vec::new();
fee_info.extend_from_slice(fee_amount.to_be_bytes().as_ref());
fee_info.extend_from_slice(view_number.to_be_bytes().as_ref());
fee_info
}

/// Aggregate all inputs used for signature over block info
fn aggregate_block_info_data(
block_size: u64,
Expand Down

0 comments on commit 04e7bd0

Please sign in to comment.