Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions cgo/extern.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ import (
"github.com/filecoin-project/go-address"

"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/crypto"
)

//export cgo_extern_get_chain_randomness
func cgo_extern_get_chain_randomness(
handle C.uint64_t, pers C.int64_t, round C.int64_t,
entropy C.buf_t, entropyLen C.int32_t,
handle C.uint64_t, round C.int64_t,
output C.buf_t,
) (res C.int32_t) {
defer func() {
Expand All @@ -33,11 +31,11 @@ func cgo_extern_get_chain_randomness(
return ErrInvalidHandle
}

rand, err := externs.GetChainRandomness(ctx, crypto.DomainSeparationTag(pers), abi.ChainEpoch(round), C.GoBytes(unsafe.Pointer(entropy), entropyLen))
rand, err := externs.GetChainRandomness(ctx, abi.ChainEpoch(round))

switch err {
case nil:
copy(out[:], rand)
copy(out[:], rand[:])
return 0
default:
return ErrIO
Expand All @@ -46,8 +44,7 @@ func cgo_extern_get_chain_randomness(

//export cgo_extern_get_beacon_randomness
func cgo_extern_get_beacon_randomness(
handle C.uint64_t, pers C.int64_t, round C.int64_t,
entropy C.buf_t, entropyLen C.int32_t,
handle C.uint64_t, round C.int64_t,
output C.buf_t,
) (res C.int32_t) {
defer func() {
Expand All @@ -63,11 +60,11 @@ func cgo_extern_get_beacon_randomness(
return ErrInvalidHandle
}

rand, err := externs.GetBeaconRandomness(ctx, crypto.DomainSeparationTag(pers), abi.ChainEpoch(round), C.GoBytes(unsafe.Pointer(entropy), entropyLen))
rand, err := externs.GetBeaconRandomness(ctx, abi.ChainEpoch(round))

switch err {
case nil:
copy(out[:], rand)
copy(out[:], rand[:])
return 0
default:
return ErrIO
Expand Down
5 changes: 2 additions & 3 deletions cgo/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/crypto"
"github.com/ipfs/go-cid"
blockstore "github.com/ipfs/go-ipfs-blockstore"
)
Expand All @@ -29,8 +28,8 @@ const (
)

type Externs interface {
GetChainRandomness(ctx context.Context, personalization crypto.DomainSeparationTag, epoch abi.ChainEpoch, entropy []byte) ([]byte, error)
GetBeaconRandomness(ctx context.Context, personalization crypto.DomainSeparationTag, epoch abi.ChainEpoch, entropy []byte) ([]byte, error)
GetChainRandomness(ctx context.Context, epoch abi.ChainEpoch) ([32]byte, error)
GetBeaconRandomness(ctx context.Context, epoch abi.ChainEpoch) ([32]byte, error)
VerifyConsensusFault(ctx context.Context, h1, h2, extra []byte) (*ConsensusFault, int64)
TipsetCid(ctx context.Context, epoch abi.ChainEpoch) (cid.Cid, error)

Expand Down
49 changes: 35 additions & 14 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ anyhow = "1.0.23"
serde_json = "1.0.46"
rust-gpu-tools = { version = "0.6", optional = true, default-features = false }
fr32 = { version = "~6.0", default-features = false }
fvm3 = { package = "fvm", version = "~3.5.0", default-features = false }
fvm3_shared = { package = "fvm_shared", version = "~3.4.0" }
fvm2 = { package = "fvm", version = "~2.5", default-features = false }
fvm3 = { package = "fvm", version = "~3.6.0", default-features = false, features = ["nv21-dev"] }
fvm3_shared = { package = "fvm_shared", version = "~3.5.0" }
fvm2 = { package = "fvm", version = "~2.6", default-features = false }
fvm2_shared = { package = "fvm_shared", version = "~2.5" }
fvm_ipld_encoding = "0.4.0"
fvm_ipld_blockstore = "0.2.0"
Expand Down
6 changes: 0 additions & 6 deletions rust/src/fvm/cgo/externs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,13 @@ extern "C" {

pub fn cgo_extern_get_chain_randomness(
handle: u64,
pers: i64,
round: i64,
entropy: *const u8,
entropy_len: i32,
randomness: *mut [u8; 32],
) -> i32;

pub fn cgo_extern_get_beacon_randomness(
handle: u64,
pers: i64,
round: i64,
entropy: *const u8,
entropy_len: i32,
randomness: *mut [u8; 32],
) -> i32;

Expand Down
2 changes: 1 addition & 1 deletion rust/src/fvm/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl TryFrom<u32> for EngineVersion {
fn try_from(value: u32) -> Result<Self, Self::Error> {
match value {
16 | 17 => Ok(EngineVersion::V1),
18 | 19 | 20 => Ok(EngineVersion::V2),
18 | 19 | 20 | 21 => Ok(EngineVersion::V2),
_ => return Err(anyhow!("network version not supported")),
}
}
Expand Down
50 changes: 8 additions & 42 deletions rust/src/fvm/externs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,10 @@ impl CgoExterns {
}

impl Rand3 for CgoExterns {
fn get_chain_randomness(
&self,
pers: i64,
round: ChainEpoch,
entropy: &[u8],
) -> anyhow::Result<[u8; 32]> {
fn get_chain_randomness(&self, round: ChainEpoch) -> anyhow::Result<[u8; 32]> {
unsafe {
let mut buf = [0u8; 32];
match cgo_extern_get_chain_randomness(
self.handle,
pers,
round,
entropy.as_ptr(),
entropy.len() as i32,
&mut buf,
) {
match cgo_extern_get_chain_randomness(self.handle, round, &mut buf) {
0 => Ok(buf),
r @ 1.. => panic!("invalid return value from has: {}", r),
x if x == FvmError::InvalidHandle as i32 => {
Expand All @@ -63,22 +51,10 @@ impl Rand3 for CgoExterns {
}
}

fn get_beacon_randomness(
&self,
pers: i64,
round: ChainEpoch,
entropy: &[u8],
) -> anyhow::Result<[u8; 32]> {
fn get_beacon_randomness(&self, round: ChainEpoch) -> anyhow::Result<[u8; 32]> {
unsafe {
let mut buf = [0u8; 32];
match cgo_extern_get_beacon_randomness(
self.handle,
pers,
round,
entropy.as_ptr(),
entropy.len() as i32,
&mut buf,
) {
match cgo_extern_get_beacon_randomness(self.handle, round, &mut buf) {
0 => Ok(buf),
r @ 1.. => panic!("invalid return value from has: {}", r),
x if x == FvmError::InvalidHandle as i32 => {
Expand All @@ -94,22 +70,12 @@ impl Rand3 for CgoExterns {
}

impl Rand2 for CgoExterns {
fn get_chain_randomness(
&self,
pers: i64,
round: ChainEpoch,
entropy: &[u8],
) -> anyhow::Result<[u8; 32]> {
Rand3::get_chain_randomness(self, pers, round, entropy)
fn get_chain_randomness(&self, round: ChainEpoch) -> anyhow::Result<[u8; 32]> {
Rand3::get_chain_randomness(self, round)
}

fn get_beacon_randomness(
&self,
pers: i64,
round: ChainEpoch,
entropy: &[u8],
) -> anyhow::Result<[u8; 32]> {
Rand3::get_beacon_randomness(self, pers, round, entropy)
fn get_beacon_randomness(&self, round: ChainEpoch) -> anyhow::Result<[u8; 32]> {
Rand3::get_beacon_randomness(self, round)
}
}

Expand Down