Skip to content

Commit 73376df

Browse files
authored
Injectable primitives (#1470)
* injectable extern behaviour * shift Verifier trait methods into primitives * implement overrides for all methods in FakePrimitives * implement overrides in TestVM for verifier functionality * remove redundant VM trait fields * additional comments * MockPrimitives (#1473) * export FakePrimitives from fakes * export FakePrimitives
1 parent fa1ff23 commit 73376df

File tree

7 files changed

+386
-170
lines changed

7 files changed

+386
-170
lines changed

runtime/src/runtime/fvm.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use fvm_sdk::NO_DATA_BLOCK_ID;
1111
use fvm_shared::address::{Address, Payload};
1212
use fvm_shared::chainid::ChainID;
1313
use fvm_shared::clock::ChainEpoch;
14+
use fvm_shared::consensus::ConsensusFault;
1415
use fvm_shared::crypto::hash::SupportedHashes;
1516
use fvm_shared::crypto::signature::{
1617
Signature, SECP_PUB_LEN, SECP_SIG_LEN, SECP_SIG_MESSAGE_HASH_SIZE,
@@ -38,8 +39,7 @@ use crate::runtime::actor_blockstore::ActorBlockstore;
3839
use crate::runtime::builtins::Type;
3940
use crate::runtime::randomness::draw_randomness;
4041
use crate::runtime::{
41-
ActorCode, ConsensusFault, DomainSeparationTag, MessageInfo, Policy, Primitives, RuntimePolicy,
42-
Verifier,
42+
ActorCode, DomainSeparationTag, MessageInfo, Policy, Primitives, RuntimePolicy,
4343
};
4444
use crate::{actor_error, ActorError, AsActorError, Runtime, SendError};
4545

@@ -443,13 +443,10 @@ where
443443
fvm::crypto::recover_secp_public_key(hash, signature)
444444
.map_err(|e| anyhow!("failed to recover pubkey; exit code: {}", e))
445445
}
446-
}
447446

448-
#[cfg(not(feature = "fake-proofs"))]
449-
impl<B> Verifier for FvmRuntime<B>
450-
where
451-
B: Blockstore,
452-
{
447+
// FVM Verifier methods
448+
449+
#[cfg(not(feature = "fake-proofs"))]
453450
fn verify_post(&self, verify_info: &WindowPoStVerifyInfo) -> Result<(), Error> {
454451
match fvm::crypto::verify_post(verify_info) {
455452
Ok(true) => Ok(()),
@@ -458,6 +455,7 @@ where
458455
}
459456
}
460457

458+
#[cfg(not(feature = "fake-proofs"))]
461459
fn verify_consensus_fault(
462460
&self,
463461
h1: &[u8],
@@ -468,11 +466,13 @@ where
468466
.map_err(|e| anyhow!("failed to verify fault: {}", e))
469467
}
470468

469+
#[cfg(not(feature = "fake-proofs"))]
471470
fn batch_verify_seals(&self, batch: &[SealVerifyInfo]) -> anyhow::Result<Vec<bool>> {
472471
fvm::crypto::batch_verify_seals(batch)
473472
.map_err(|e| anyhow!("failed to verify batch seals: {}", e))
474473
}
475474

475+
#[cfg(not(feature = "fake-proofs"))]
476476
fn verify_aggregate_seals(
477477
&self,
478478
aggregate: &AggregateSealVerifyProofAndInfos,
@@ -484,20 +484,18 @@ where
484484
}
485485
}
486486

487+
#[cfg(not(feature = "fake-proofs"))]
487488
fn verify_replica_update(&self, replica: &ReplicaUpdateInfo) -> Result<(), Error> {
488489
match fvm::crypto::verify_replica_update(replica) {
489490
Ok(true) => Ok(()),
490491
Ok(false) => Err(Error::msg("invalid replica")),
491492
Err(e) => Err(anyhow!("failed to verify replica: {}", e)),
492493
}
493494
}
494-
}
495495

496-
#[cfg(feature = "fake-proofs")]
497-
impl<B> Verifier for FvmRuntime<B>
498-
where
499-
B: Blockstore,
500-
{
496+
// Fake Verifier methods
497+
498+
#[cfg(feature = "fake-proofs")]
501499
fn verify_post(&self, verify_info: &WindowPoStVerifyInfo) -> Result<(), Error> {
502500
let mut info = verify_info.clone();
503501
if info.proofs.len() != 1 {
@@ -521,6 +519,7 @@ where
521519
Err(Error::msg("[fake-post-validation] window post was invalid"))
522520
}
523521

522+
#[cfg(feature = "fake-proofs")]
524523
fn verify_consensus_fault(
525524
&self,
526525
_h1: &[u8],
@@ -530,17 +529,20 @@ where
530529
Ok(None)
531530
}
532531

532+
#[cfg(feature = "fake-proofs")]
533533
fn batch_verify_seals(&self, batch: &[SealVerifyInfo]) -> anyhow::Result<Vec<bool>> {
534534
Ok(batch.iter().map(|_| true).collect())
535535
}
536536

537+
#[cfg(feature = "fake-proofs")]
537538
fn verify_aggregate_seals(
538539
&self,
539540
_aggregate: &AggregateSealVerifyProofAndInfos,
540541
) -> Result<(), Error> {
541542
Ok(())
542543
}
543544

545+
#[cfg(feature = "fake-proofs")]
544546
fn verify_replica_update(&self, _replica: &ReplicaUpdateInfo) -> Result<(), Error> {
545547
Ok(())
546548
}

runtime/src/runtime/mod.rs

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,8 @@ use fvm_ipld_blockstore::Blockstore;
66
use fvm_ipld_encoding::CborStore;
77
use fvm_shared::address::Address;
88
use fvm_shared::clock::ChainEpoch;
9-
use fvm_shared::consensus::ConsensusFault;
109
use fvm_shared::econ::TokenAmount;
1110
use fvm_shared::randomness::RANDOMNESS_LENGTH;
12-
use fvm_shared::sector::{
13-
AggregateSealVerifyProofAndInfos, ReplicaUpdateInfo, SealVerifyInfo, WindowPoStVerifyInfo,
14-
};
1511
use fvm_shared::version::NetworkVersion;
1612
use fvm_shared::{ActorID, MethodNum, Response};
1713
use serde::de::DeserializeOwned;
@@ -47,7 +43,7 @@ pub use vm_api::Primitives;
4743

4844
/// Runtime is the VM's internal runtime object.
4945
/// this is everything that is accessible to actors, beyond parameters.
50-
pub trait Runtime: Primitives + Verifier + RuntimePolicy {
46+
pub trait Runtime: Primitives + RuntimePolicy {
5147
type Blockstore: Blockstore;
5248

5349
/// The network protocol version number at the current epoch.
@@ -275,35 +271,3 @@ pub trait MessageInfo {
275271
/// The message gas premium
276272
fn gas_premium(&self) -> TokenAmount;
277273
}
278-
279-
/// filcrypto verification primitives provided by the runtime
280-
pub trait Verifier {
281-
/// Verifies a window proof of spacetime.
282-
fn verify_post(&self, verify_info: &WindowPoStVerifyInfo) -> Result<(), anyhow::Error>;
283-
284-
/// Verifies that two block headers provide proof of a consensus fault:
285-
/// - both headers mined by the same actor
286-
/// - headers are different
287-
/// - first header is of the same or lower epoch as the second
288-
/// - at least one of the headers appears in the current chain at or after epoch `earliest`
289-
/// - the headers provide evidence of a fault (see the spec for the different fault types).
290-
/// The parameters are all serialized block headers. The third "extra" parameter is consulted only for
291-
/// the "parent grinding fault", in which case it must be the sibling of h1 (same parent tipset) and one of the
292-
/// blocks in the parent of h2 (i.e. h2's grandparent).
293-
/// Returns nil and an error if the headers don't prove a fault.
294-
fn verify_consensus_fault(
295-
&self,
296-
h1: &[u8],
297-
h2: &[u8],
298-
extra: &[u8],
299-
) -> Result<Option<ConsensusFault>, anyhow::Error>;
300-
301-
fn batch_verify_seals(&self, batch: &[SealVerifyInfo]) -> anyhow::Result<Vec<bool>>;
302-
303-
fn verify_aggregate_seals(
304-
&self,
305-
aggregate: &AggregateSealVerifyProofAndInfos,
306-
) -> Result<(), anyhow::Error>;
307-
308-
fn verify_replica_update(&self, replica: &ReplicaUpdateInfo) -> Result<(), anyhow::Error>;
309-
}

0 commit comments

Comments
 (0)