Skip to content

Commit

Permalink
filecoin syscall
Browse files Browse the repository at this point in the history
  • Loading branch information
fridrik01 committed Nov 15, 2023
1 parent 0c16a91 commit ae8f628
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 36 deletions.
11 changes: 0 additions & 11 deletions fvm/src/kernel/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -593,17 +593,6 @@ where
}))
}

fn verify_post(&self, verify_info: &WindowPoStVerifyInfo) -> Result<bool> {
let t = self
.call_manager
.charge_gas(self.call_manager.price_list().on_verify_post(verify_info))?;

// This is especially important to catch as, otherwise, a bad "post" could be undisputable.
t.record(catch_and_log_panic("verifying post", || {
verify_post(verify_info)
}))
}

fn verify_consensus_fault(
&self,
h1: &[u8],
Expand Down
3 changes: 0 additions & 3 deletions fvm/src/kernel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,6 @@ pub trait CryptoOps {
pieces: &[PieceInfo],
) -> Result<Cid>;

/// Verifies a window proof of spacetime.
fn verify_post(&self, verify_info: &WindowPoStVerifyInfo) -> Result<bool>;

/// Verifies that two block headers provide proof of a consensus fault:
/// - both headers mined by the same actor
/// - headers are different
Expand Down
20 changes: 0 additions & 20 deletions fvm/src/syscalls/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use fvm_shared::crypto::signature::{
use fvm_shared::piece::PieceInfo;
use fvm_shared::sector::{
AggregateSealVerifyProofAndInfos, RegisteredSealProof, ReplicaUpdateInfo, SealVerifyInfo,
WindowPoStVerifyInfo,
};
use fvm_shared::sys;
use num_traits::FromPrimitive;
Expand Down Expand Up @@ -124,25 +123,6 @@ pub fn compute_unsealed_sector_cid(
context.memory.write_cid(&cid, cid_off, cid_len)
}

/// Verifies a window proof of spacetime.
///
/// The return i32 indicates the status code of the verification:
/// - 0: verification ok.
/// - -1: verification failed.
pub fn verify_post(
context: Context<'_, impl Kernel>,
info_off: u32, // WindowPoStVerifyInfo,
info_len: u32,
) -> Result<i32> {
let info = context
.memory
.read_cbor::<WindowPoStVerifyInfo>(info_off, info_len)?;
context
.kernel
.verify_post(&info)
.map(|v| if v { 0 } else { -1 })
}

/// Verifies that two block headers provide proof of a consensus fault:
/// - both headers mined by the same actor
/// - headers are different
Expand Down
25 changes: 25 additions & 0 deletions fvm/src/syscalls/filecoin.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use fvm_shared::sector::WindowPoStVerifyInfo;

use crate::kernel::FilecoinKernel;

use super::Context;
use crate::kernel::Result;

/// Verifies a window proof of spacetime.
///
/// The return i32 indicates the status code of the verification:
/// - 0: verification ok.
/// - -1: verification failed.
pub fn verify_post(
context: Context<'_, impl FilecoinKernel>,
info_off: u32, // WindowPoStVerifyInfo,
info_len: u32,
) -> Result<i32> {
let info = context
.memory
.read_cbor::<WindowPoStVerifyInfo>(info_off, info_len)?;
context
.kernel
.verify_post(&info)
.map(|v| if v { 0 } else { -1 })
}
4 changes: 2 additions & 2 deletions fvm/src/syscalls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ mod context;
mod crypto;
mod debug;
mod event;
mod filecoin;
mod gas;
mod ipld;
mod network;
Expand Down Expand Up @@ -301,7 +302,6 @@ where
crypto::recover_secp_public_key,
)?;
linker.bind("crypto", "hash", crypto::hash)?;
linker.bind("crypto", "verify_post", crypto::verify_post)?;
linker.bind(
"crypto",
"compute_unsealed_sector_cid",
Expand Down Expand Up @@ -355,7 +355,7 @@ where
self.0.bind_syscalls(linker)?;

// Now bind the crypto syscalls.
linker.bind("crypto", "verify_post", crypto::verify_post)?;
linker.bind("crypto", "verify_post", filecoin::verify_post)?;

Ok(())
}
Expand Down

0 comments on commit ae8f628

Please sign in to comment.