Skip to content

Commit

Permalink
hook up market actor to call new authenticate_message method
Browse files Browse the repository at this point in the history
  • Loading branch information
arajasek committed Aug 29, 2022
1 parent cd6f38f commit 04f0e63
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 6 deletions.
17 changes: 17 additions & 0 deletions actors/market/src/ext.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use fvm_ipld_encoding::serde_bytes;
use fvm_ipld_encoding::tuple::*;
use fvm_shared::address::Address;
use fvm_shared::bigint::bigint_ser;
Expand All @@ -6,6 +7,20 @@ use fvm_shared::econ::TokenAmount;
use fvm_shared::sector::StoragePower;
use fvm_shared::smooth::FilterEstimate;

pub mod account {
use super::*;

pub const AUTHENTICATE_MESSAGE_METHOD: u64 = 3;

#[derive(Serialize_tuple, Deserialize_tuple)]
pub struct AuthenticateMessageParams {
#[serde(with = "serde_bytes")]
pub signature: Vec<u8>,
#[serde(with = "serde_bytes")]
pub message: Vec<u8>,
}
}

pub mod miner {
use super::*;

Expand All @@ -25,6 +40,7 @@ pub mod verifreg {
// based on fil_actor_verifreg
pub const USE_BYTES_METHOD: u64 = 5;
pub const RESTORE_BYTES_METHOD: u64 = 6;

pub type UseBytesParams = BytesParams;
pub type RestoreBytesParams = BytesParams;

Expand All @@ -44,6 +60,7 @@ pub mod reward {

pub mod power {
use super::*;

pub const CURRENT_TOTAL_POWER_METHOD: u64 = 9;

#[derive(Serialize_tuple, Deserialize_tuple)]
Expand Down
18 changes: 13 additions & 5 deletions actors/market/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1282,12 +1282,20 @@ where
BS: Blockstore,
RT: Runtime<BS>,
{
let signature_bytes = proposal.client_signature.bytes.clone();
// Generate unsigned bytes
let sv_bz = serialize_vec(&proposal.proposal, "deal proposal")?;
rt.verify_signature(&proposal.client_signature, &proposal.proposal.client, &sv_bz).map_err(
|e| e.downcast_default(ExitCode::USR_ILLEGAL_ARGUMENT, "signature proposal invalid"),
)?;

let proposal_bytes = serialize_vec(&proposal.proposal, "deal proposal")?;

rt.send(
proposal.proposal.client,
ext::account::AUTHENTICATE_MESSAGE_METHOD,
RawBytes::serialize(ext::account::AuthenticateMessageParams {
signature: signature_bytes,
message: proposal_bytes,
})?,
TokenAmount::zero(),
)
.map_err(|e| e.wrap(format!("proposal authentication failed")))?;
Ok(())
}

Expand Down
49 changes: 48 additions & 1 deletion test_vm/tests/publish_deals_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,50 @@ fn psd_all_deals_are_bad() {
v.assert_state_invariants();
}

#[test]
fn psd_bad_sig() {
let store = MemoryBlockstore::new();
let (v, a, deal_start) = setup(&store);
let (storage_price_per_epoch, provider_collateral, client_collateral) = token_defaults();

let deal_label = "deal0".to_string();
let proposal = DealProposal {
piece_cid: make_piece_cid(deal_label.as_bytes()),
piece_size: PaddedPieceSize(1 << 30),
verified_deal: false,
client: a.client1,
provider: a.maddr,
label: Label::String(deal_label),
start_epoch: deal_start,
end_epoch: deal_start + DEAL_LIFETIME,
storage_price_per_epoch,
provider_collateral,
client_collateral,
};

let publish_params = PublishStorageDealsParams {
deals: vec![ClientDealProposal {
proposal: proposal,
client_signature: Signature {
sig_type: SignatureType::BLS,
bytes: "very_invalid_sig".as_bytes().to_vec(),
},
}],
};
let ret = v
.apply_message(
a.worker,
*STORAGE_MARKET_ACTOR_ADDR,
TokenAmount::zero(),
MarketMethod::PublishStorageDeals as u64,
publish_params,
)
.unwrap();
assert_eq!(ExitCode::USR_ILLEGAL_ARGUMENT, ret.code);

v.assert_state_invariants();
}

#[test]
fn psd_all_deals_are_good() {
let store = MemoryBlockstore::new();
Expand Down Expand Up @@ -631,7 +675,10 @@ impl<'bs> DealBatcher<'bs> {
.iter_mut()
.map(|deal| ClientDealProposal {
proposal: deal.clone(),
client_signature: Signature { sig_type: SignatureType::BLS, bytes: vec![] },
client_signature: Signature {
sig_type: SignatureType::BLS,
bytes: serialize(deal, "serializing deal proposal").unwrap().to_vec(),
},
})
.collect();
let publish_params = PublishStorageDealsParams { deals: params_deals };
Expand Down

0 comments on commit 04f0e63

Please sign in to comment.