From a8ae4bbde8e7acd8fb85738a954bc348524461cc Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Thu, 12 Sep 2024 18:08:31 -0700 Subject: [PATCH] chore: update safer-ffi --- rust/Cargo.lock | 255 ++++++++++++++++++++++++++++------------ rust/Cargo.toml | 2 +- rust/src/bls/api.rs | 38 +++--- rust/src/fvm/machine.rs | 21 ++-- rust/src/fvm/types.rs | 2 +- rust/src/proofs/api.rs | 152 ++++++++++++------------ rust/src/util/types.rs | 5 +- 7 files changed, 295 insertions(+), 180 deletions(-) diff --git a/rust/Cargo.lock b/rust/Cargo.lock index b3ccce85..4a4be5ef 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -1099,6 +1099,35 @@ version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "69dc321eb6be977f44674620ca3aa21703cb20ffbe560e1ae97da08401ffbcad" +[[package]] +name = "ext-trait" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d772df1c1a777963712fb68e014235e80863d6a91a85c4e06ba2d16243a310e5" +dependencies = [ + "ext-trait-proc_macros", +] + +[[package]] +name = "ext-trait-proc_macros" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ab7934152eaf26aa5aa9f7371408ad5af4c31357073c9e84c3b9d7f11ad639a" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "extension-traits" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a296e5a895621edf9fa8329c83aa1cb69a964643e36cf54d8d7a69b789089537" +dependencies = [ + "ext-trait", +] + [[package]] name = "fake-simd" version = "0.1.2" @@ -1667,17 +1696,6 @@ dependencies = [ "wasi", ] -[[package]] -name = "ghost" -version = "0.1.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0e085ded9f1267c32176b40921b9754c474f7dd96f7e808d4a982e48aa1e854" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.77", -] - [[package]] name = "gimli" version = "0.29.0" @@ -1892,25 +1910,9 @@ dependencies = [ [[package]] name = "inventory" -version = "0.1.11" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0eb5160c60ba1e809707918ee329adb99d222888155835c6feedba19f6c3fd4" -dependencies = [ - "ctor", - "ghost", - "inventory-impl", -] - -[[package]] -name = "inventory-impl" -version = "0.1.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e41b53715c6f0c4be49510bb82dee2c1e51c8586d885abe65396e82ed518548" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] +checksum = "f958d3d68f4167080a18141e10381e7634563984a537f2a49a30fd8e53ac5767" [[package]] name = "iowrap" @@ -2121,6 +2123,22 @@ dependencies = [ "libc", ] +[[package]] +name = "macro_rules_attribute" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf0c9b980bf4f3a37fd7b1c066941dd1b1d0152ce6ee6e8fe8c49b9f6810d862" +dependencies = [ + "macro_rules_attribute-proc_macro", + "paste", +] + +[[package]] +name = "macro_rules_attribute-proc_macro" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58093314a45e00c77d5c508f76e77c3396afbbc0d01506e7fae47b018bac2b1d" + [[package]] name = "memchr" version = "2.7.4" @@ -2171,21 +2189,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "mini_paste" -version = "0.1.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2499b7bd9834270bf24cfc4dd96be59020ba6fd7f3276b772aee2de66e82b63" -dependencies = [ - "mini_paste-proc_macro", -] - -[[package]] -name = "mini_paste-proc_macro" -version = "0.1.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c5f1f52e39b728e73af4b454f1b29173d4544607bd395dafe1918fd149db67" - [[package]] name = "minimal-lexical" version = "0.2.1" @@ -2248,7 +2251,7 @@ version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d6d4752e6230d8ef7adf7bd5d8c4b1f6561c1014c5ba9a37445ccefe18aa1db" dependencies = [ - "proc-macro-crate", + "proc-macro-crate 1.1.3", "proc-macro-error", "proc-macro2", "quote", @@ -2540,6 +2543,16 @@ dependencies = [ "yansi", ] +[[package]] +name = "prettyplease" +version = "0.1.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8646e95016a7a6c4adea95bafa8a16baab64b583356217f2c85db4a39d9a86" +dependencies = [ + "proc-macro2", + "syn 1.0.109", +] + [[package]] name = "proc-macro-crate" version = "1.1.3" @@ -2550,6 +2563,15 @@ dependencies = [ "toml", ] +[[package]] +name = "proc-macro-crate" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecf48c7ca261d60b74ab1a7b20da18bede46776b2e55535cb958eb595c5fa7b" +dependencies = [ + "toml_edit", +] + [[package]] name = "proc-macro-error" version = "1.0.4" @@ -2574,12 +2596,6 @@ dependencies = [ "version_check", ] -[[package]] -name = "proc-macro-hack" -version = "0.5.20+deprecated" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc375e1527247fe1a97d8b7156678dfe7c1af2fc075c9a4db3690ecd2a148068" - [[package]] name = "proc-macro2" version = "1.0.86" @@ -2729,17 +2745,6 @@ version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3a8614ee435691de62bcffcf4a66d91b3594bf1428a5722e79103249a095690" -[[package]] -name = "require_unsafe_in_body" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "296446f2214753e33792f632262451e8d037cd9697df15db2fd531bdce5a0138" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "ripemd" version = "0.1.3" @@ -2822,25 +2827,30 @@ checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" [[package]] name = "safer-ffi" -version = "0.0.7" +version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c52424d2271f2f5aae854241d76244d75194b3486c6714c8020cdb8384c6be22" +checksum = "614978f55c6e885794b44afb2e2378fe61b104ec4391f310d879edf3df9d874c" dependencies = [ "inventory", "libc", - "mini_paste", - "proc-macro-hack", - "require_unsafe_in_body", - "safer_ffi-proc_macro", + "macro_rules_attribute", + "paste", + "safer_ffi-proc_macros", + "scopeguard", + "stabby", + "uninit", + "unwind_safe", + "with_builtin_macros", ] [[package]] -name = "safer_ffi-proc_macro" -version = "0.0.7" +name = "safer_ffi-proc_macros" +version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a12d277e24f04228e8c56c5e4482d9dccd44a287746dbc57464d5f7aea2d2d07" +checksum = "7cdcb365894c49e42b5413def59ac644ea085bbbdee535d7c80b2b008a345686" dependencies = [ - "proc-macro-hack", + "macro_rules_attribute", + "prettyplease", "proc-macro2", "quote", "syn 1.0.109", @@ -2986,6 +2996,12 @@ dependencies = [ "cc", ] +[[package]] +name = "sha2-const-stable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f179d4e11094a893b82fff208f74d448a7512f99f5a0acbd5c679b705f83ed9" + [[package]] name = "sha2raw" version = "13.1.0" @@ -3057,6 +3073,40 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3b9b39299b249ad65f3b7e96443bad61c02ca5cd3589f46cb6d610a0fd6c0d6a" +[[package]] +name = "stabby" +version = "36.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "311d6bcf0070c462ff626122ec2246f42bd2acd44b28908eedbfd07d500c7d99" +dependencies = [ + "rustversion", + "stabby-abi", +] + +[[package]] +name = "stabby-abi" +version = "36.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6daae1a0707399f56d27fce7f212e50e31d215112a447e1bbcd837ae1bf5f49" +dependencies = [ + "rustversion", + "sha2-const-stable", + "stabby-macros", +] + +[[package]] +name = "stabby-macros" +version = "36.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43cf89a0cc9131279235baf8599b0e073fbcb096419204de0cc5d1a48ae73f74" +dependencies = [ + "proc-macro-crate 3.2.0", + "proc-macro2", + "quote", + "rand", + "syn 1.0.109", +] + [[package]] name = "stable_deref_trait" version = "1.2.0" @@ -3344,6 +3394,23 @@ dependencies = [ "serde", ] +[[package]] +name = "toml_datetime" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" + +[[package]] +name = "toml_edit" +version = "0.22.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "583c44c02ad26b0c3f3066fe629275e50627026c51ac2e595cca4c230ce1ce1d" +dependencies = [ + "indexmap 2.5.0", + "toml_datetime", + "winnow", +] + [[package]] name = "trait-set" version = "0.3.0" @@ -3394,6 +3461,15 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "229730647fbc343e3a80e463c1db7f78f3855d3f3739bee0dda773c9a037c90a" +[[package]] +name = "uninit" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e130f2ed46ca5d8ec13c7ff95836827f92f5f5f37fd2b2bf16f33c408d98bb6" +dependencies = [ + "extension-traits", +] + [[package]] name = "unsigned-varint" version = "0.7.2" @@ -3406,6 +3482,12 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eb066959b24b5196ae73cb057f45598450d2c5f71460e98c49b738086eff9c06" +[[package]] +name = "unwind_safe" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0976c77def3f1f75c4ef892a292c31c0bbe9e3d0702c63044d7c76db298171a3" + [[package]] name = "url" version = "2.5.2" @@ -3887,6 +3969,15 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" +[[package]] +name = "winnow" +version = "0.6.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68a9bda4691f099d435ad181000724da8e5899daa10713c2d432552b9ccd3a6f" +dependencies = [ + "memchr", +] + [[package]] name = "wit-parser" version = "0.215.0" @@ -3905,6 +3996,26 @@ dependencies = [ "wasmparser 0.215.0", ] +[[package]] +name = "with_builtin_macros" +version = "0.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a59d55032495429b87f9d69954c6c8602e4d3f3e0a747a12dea6b0b23de685da" +dependencies = [ + "with_builtin_macros-proc_macros", +] + +[[package]] +name = "with_builtin_macros-proc_macros" +version = "0.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15bd7679c15e22924f53aee34d4e448c45b674feb6129689af88593e129f8f42" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "wyz" version = "0.5.1" diff --git a/rust/Cargo.toml b/rust/Cargo.toml index eff1d9af..82a16513 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -46,7 +46,7 @@ cid = { version = "0.10.1", features = ["serde-codec"] } lazy_static = "1.4.0" serde = "1.0.117" serde_tuple = "0.5" -safer-ffi = { version = "0.0.7", features = ["proc_macros"] } +safer-ffi = { version = "0.1.12", features = ["proc_macros"] } filecoin-proofs-api = { version = "18.1", default-features = false } yastl = "0.1.2" diff --git a/rust/src/bls/api.rs b/rust/src/bls/api.rs index c442d9dd..74bcef90 100644 --- a/rust/src/bls/api.rs +++ b/rust/src/bls/api.rs @@ -58,12 +58,12 @@ fn destroy_box_bls_signature(ptr: repr_c::Box) { /// /// * `message` - reference to a message byte array #[ffi_export] -pub fn hash(message: c_slice::Ref) -> repr_c::Box { +pub fn hash(message: c_slice::Ref<'_, u8>) -> repr_c::Box { // call method let raw_digest = hash_sig(&message).to_bytes(); let digest: [u8; DIGEST_BYTES] = raw_digest.as_ref().try_into().expect("known size"); - repr_c::Box::new(digest) + Box::new(digest).into() } /// Aggregate signatures together into a new signature @@ -74,7 +74,7 @@ pub fn hash(message: c_slice::Ref) -> repr_c::Box { /// /// Returns `None` on error. Result must be freed using `destroy_aggregate_response`. #[ffi_export] -pub fn aggregate(flattened_signatures: c_slice::Ref) -> Option> { +pub fn aggregate(flattened_signatures: c_slice::Ref<'_, u8>) -> Option> { // prep request let signatures = try_ffi!( flattened_signatures @@ -91,7 +91,7 @@ pub fn aggregate(flattened_signatures: c_slice::Ref) -> Option) -> Option, - flattened_digests: c_slice::Ref, - flattened_public_keys: c_slice::Ref, + signature: c_slice::Ref<'_, u8>, + flattened_digests: c_slice::Ref<'_, u8>, + flattened_public_keys: c_slice::Ref<'_, u8>, ) -> bool { // prep request let signature = try_ffi!(Signature::from_bytes(&signature), false); @@ -157,10 +157,10 @@ pub fn verify( /// * `flattened_public_keys` - byte array containing public keys #[ffi_export] pub fn hash_verify( - signature: c_slice::Ref, - flattened_messages: c_slice::Ref, - message_sizes: c_slice::Ref, - flattened_public_keys: c_slice::Ref, + signature: c_slice::Ref<'_, u8>, + flattened_messages: c_slice::Ref<'_, u8>, + message_sizes: c_slice::Ref<'_, libc::size_t>, + flattened_public_keys: c_slice::Ref<'_, u8>, ) -> bool { // prep request let signature = try_ffi!(Signature::from_bytes(&signature), false); @@ -196,7 +196,7 @@ pub fn private_key_generate() -> repr_c::Box { .write_bytes(&mut raw_private_key.as_mut()) .expect("preallocated"); - repr_c::Box::new(raw_private_key) + Box::new(raw_private_key).into() } /// Generate a new private key with seed @@ -215,7 +215,7 @@ pub fn private_key_generate_with_seed(raw_seed: &[u8; 32]) -> repr_c::Box repr_c::Box, - message: c_slice::Ref, + raw_private_key: c_slice::Ref<'_, u8>, + message: c_slice::Ref<'_, u8>, ) -> Option> { let private_key = try_ffi!(PrivateKey::from_bytes(&raw_private_key), None); @@ -238,7 +238,7 @@ pub fn private_key_sign( .write_bytes(&mut raw_signature.as_mut()) .expect("preallocated"); - Some(repr_c::Box::new(raw_signature)) + Some(Box::new(raw_signature).into()) } /// Generate the public key for a private key @@ -250,7 +250,7 @@ pub fn private_key_sign( /// Returns `None` when passed invalid arguments. #[ffi_export] pub fn private_key_public_key( - raw_private_key: c_slice::Ref, + raw_private_key: c_slice::Ref<'_, u8>, ) -> Option> { let private_key = try_ffi!(PrivateKey::from_bytes(&raw_private_key), None); @@ -260,7 +260,7 @@ pub fn private_key_public_key( .write_bytes(&mut raw_public_key.as_mut()) .expect("preallocated"); - Some(repr_c::Box::new(raw_public_key)) + Some(Box::new(raw_public_key).into()) } /// Returns a zero signature, used as placeholder in Filecoin. @@ -275,7 +275,7 @@ pub fn create_zero_signature() -> repr_c::Box { sig.write_bytes(&mut raw_signature.as_mut()) .expect("preallocated"); - repr_c::Box::new(raw_signature) + Box::new(raw_signature).into() } #[cfg(test)] diff --git a/rust/src/fvm/machine.rs b/rust/src/fvm/machine.rs index f398a154..c12ae8ec 100644 --- a/rust/src/fvm/machine.rs +++ b/rust/src/fvm/machine.rs @@ -89,8 +89,8 @@ fn create_fvm_machine_generic( circulating_supply_hi: u64, circulating_supply_lo: u64, network_version: u32, - state_root: c_slice::Ref, - actor_redirect: Option>, + state_root: c_slice::Ref<'_, u8>, + actor_redirect: Option>, actor_debugging: bool, tracing: bool, blockstore_id: u64, @@ -142,9 +142,9 @@ fn create_fvm_machine_generic( let externs = CgoExterns::new(externs_id); let engine = ENGINES.get(network_version)?; - Ok(Some(repr_c::Box::new( - engine.new_executor(config, blockstore, externs)?, - ))) + Ok(Some( + Box::new(engine.new_executor(config, blockstore, externs)?).into(), + )) }) } } @@ -164,7 +164,7 @@ fn create_fvm_machine( circulating_supply_hi: u64, circulating_supply_lo: u64, network_version: u32, - state_root: c_slice::Ref, + state_root: c_slice::Ref<'_, u8>, tracing: bool, blockstore_id: u64, externs_id: u64, @@ -199,8 +199,8 @@ fn create_fvm_debug_machine( circulating_supply_hi: u64, circulating_supply_lo: u64, network_version: u32, - state_root: c_slice::Ref, - actor_redirect: c_slice::Ref, + state_root: c_slice::Ref<'_, u8>, + actor_redirect: c_slice::Ref<'_, u8>, tracing: bool, blockstore_id: u64, externs_id: u64, @@ -237,18 +237,19 @@ where pool.scoped(|scope| scope.execute(|| res = Some(catch_panic_response(name, callback)))); res.unwrap_or_else(|| { - repr_c::Box::new(Result::err( + Box::new(Result::::err( format!("failed to schedule {name}") .into_bytes() .into_boxed_slice(), )) + .into() }) } #[ffi_export] fn fvm_machine_execute_message( executor: &'_ InnerFvmMachine, - message: c_slice::Ref, + message: c_slice::Ref<'_, u8>, chain_len: u64, apply_kind: u64, /* 0: Explicit, _: Implicit */ ) -> repr_c::Box> { diff --git a/rust/src/fvm/types.rs b/rust/src/fvm/types.rs index 7aa9703a..4063a3e1 100644 --- a/rust/src/fvm/types.rs +++ b/rust/src/fvm/types.rs @@ -14,7 +14,7 @@ pub enum FvmRegisteredVersion { } #[derive_ReprC] -#[ReprC::opaque] +#[repr(opaque)] #[derive(Default)] pub struct InnerFvmMachine { pub(crate) machine: Option>>, diff --git a/rust/src/proofs/api.rs b/rust/src/proofs/api.rs index ecf6d9f6..f974e288 100644 --- a/rust/src/proofs/api.rs +++ b/rust/src/proofs/api.rs @@ -36,7 +36,7 @@ unsafe fn write_with_alignment( src_fd: libc::c_int, src_size: u64, dst_fd: libc::c_int, - existing_piece_sizes: c_slice::Ref, + existing_piece_sizes: c_slice::Ref<'_, u64>, ) -> repr_c::Box { catch_panic_response("write_with_alignment", || { let piece_sizes: Vec = existing_piece_sizes @@ -89,8 +89,8 @@ unsafe fn write_without_alignment( #[ffi_export] fn fauxrep( registered_proof: RegisteredSealProof, - cache_dir_path: c_slice::Ref, - sealed_sector_path: c_slice::Ref, + cache_dir_path: c_slice::Ref<'_, u8>, + sealed_sector_path: c_slice::Ref<'_, u8>, ) -> repr_c::Box { catch_panic_response("fauxrep", || { let res = seal::fauxrep( @@ -105,8 +105,8 @@ fn fauxrep( #[ffi_export] fn fauxrep2( registered_proof: RegisteredSealProof, - cache_dir_path: c_slice::Ref, - existing_p_aux_path: c_slice::Ref, + cache_dir_path: c_slice::Ref<'_, u8>, + existing_p_aux_path: c_slice::Ref<'_, u8>, ) -> repr_c::Box { catch_panic_response("fauxrep2", || { let result = seal::fauxrep2( @@ -123,13 +123,13 @@ fn fauxrep2( #[ffi_export] fn seal_pre_commit_phase1( registered_proof: RegisteredSealProof, - cache_dir_path: c_slice::Ref, - staged_sector_path: c_slice::Ref, - sealed_sector_path: c_slice::Ref, + cache_dir_path: c_slice::Ref<'_, u8>, + staged_sector_path: c_slice::Ref<'_, u8>, + sealed_sector_path: c_slice::Ref<'_, u8>, sector_id: u64, prover_id: &[u8; 32], ticket: &[u8; 32], - pieces: c_slice::Ref, + pieces: c_slice::Ref<'_, PublicPieceInfo>, ) -> repr_c::Box { catch_panic_response("seal_pre_commit_phase1", || { let public_pieces: Vec = pieces.iter().map(Into::into).collect(); @@ -157,7 +157,7 @@ fn seal_pre_commit_phase1( #[ffi_export] fn generate_sdr( registered_proof: RegisteredSealProof, - output_dir: c_slice::Ref, + output_dir: c_slice::Ref<'_, u8>, replica_id: &[u8; 32], ) -> repr_c::Box { catch_panic_response("generate_sdr", || { @@ -174,9 +174,9 @@ fn generate_sdr( /// TODO: document #[ffi_export] fn seal_pre_commit_phase2( - seal_pre_commit_phase1_output: c_slice::Ref, - cache_dir_path: c_slice::Ref, - sealed_sector_path: c_slice::Ref, + seal_pre_commit_phase1_output: c_slice::Ref<'_, u8>, + cache_dir_path: c_slice::Ref<'_, u8>, + sealed_sector_path: c_slice::Ref<'_, u8>, ) -> repr_c::Box { catch_panic_response("seal_pre_commit_phase2", || { let phase_1_output = serde_json::from_slice(&seal_pre_commit_phase1_output)?; @@ -202,8 +202,8 @@ fn seal_pre_commit_phase2( #[ffi_export] fn generate_tree_r_last( registered_proof: RegisteredSealProof, - replica_path: c_slice::Ref, - output_dir: c_slice::Ref, + replica_path: c_slice::Ref<'_, u8>, + output_dir: c_slice::Ref<'_, u8>, ) -> repr_c::Box { catch_panic_response("generate_tree_r_last", || { let comm_r_last = seal::generate_tree_r_last( @@ -227,8 +227,8 @@ fn generate_tree_r_last( #[ffi_export] fn generate_tree_c( registered_proof: RegisteredSealProof, - input_dir: c_slice::Ref, - output_dir: c_slice::Ref, + input_dir: c_slice::Ref<'_, u8>, + output_dir: c_slice::Ref<'_, u8>, ) -> repr_c::Box { catch_panic_response("generate_tree_c", || { let comm_c = seal::generate_tree_c( @@ -247,13 +247,13 @@ fn seal_commit_phase1( registered_proof: RegisteredSealProof, comm_r: &[u8; 32], comm_d: &[u8; 32], - cache_dir_path: c_slice::Ref, - replica_path: c_slice::Ref, + cache_dir_path: c_slice::Ref<'_, u8>, + replica_path: c_slice::Ref<'_, u8>, sector_id: u64, prover_id: &[u8; 32], ticket: &[u8; 32], seed: &[u8; 32], - pieces: c_slice::Ref, + pieces: c_slice::Ref<'_, PublicPieceInfo>, ) -> repr_c::Box { catch_panic_response("seal_commit_phase1", || { let spcp2o = seal::SealPreCommitPhase2Output { @@ -282,7 +282,7 @@ fn seal_commit_phase1( #[ffi_export] fn seal_commit_phase2( - seal_commit_phase1_output: c_slice::Ref, + seal_commit_phase1_output: c_slice::Ref<'_, u8>, sector_id: u64, prover_id: &[u8; 32], ) -> repr_c::Box { @@ -313,7 +313,7 @@ fn seal_commit_phase2( /// includes the proof generated in this phase of the sealing process. #[ffi_export] fn seal_commit_phase2_circuit_proofs( - seal_commit_phase1_output: c_slice::Ref, + seal_commit_phase1_output: c_slice::Ref<'_, u8>, sector_id: u64, ) -> repr_c::Box { catch_panic_response("seal_commit_phase2_circuit_proofs", || { @@ -330,12 +330,12 @@ fn generate_synth_proofs( registered_proof: RegisteredSealProof, comm_r: &[u8; 32], comm_d: &[u8; 32], - cache_dir_path: c_slice::Ref, - replica_path: c_slice::Ref, + cache_dir_path: c_slice::Ref<'_, u8>, + replica_path: c_slice::Ref<'_, u8>, sector_id: u64, prover_id: &[u8; 32], ticket: &[u8; 32], - pieces: c_slice::Ref, + pieces: c_slice::Ref<'_, PublicPieceInfo>, ) -> repr_c::Box { catch_panic_response("generate_synth_proofs", || { let spcp2o = seal::SealPreCommitPhase2Output { @@ -362,9 +362,9 @@ fn generate_synth_proofs( fn aggregate_seal_proofs( registered_proof: RegisteredSealProof, registered_aggregation: RegisteredAggregationProof, - comm_rs: c_slice::Ref<[u8; 32]>, - seeds: c_slice::Ref<[u8; 32]>, - seal_commit_responses: c_slice::Ref>, + comm_rs: c_slice::Ref<'_, [u8; 32]>, + seeds: c_slice::Ref<'_, [u8; 32]>, + seal_commit_responses: c_slice::Ref<'_, c_slice::Box>, ) -> repr_c::Box { catch_panic_response("aggregate_seal_proofs", || { let outputs: Vec = seal_commit_responses @@ -407,8 +407,8 @@ fn verify_aggregate_seal_proof( registered_proof: RegisteredSealProof, registered_aggregation: RegisteredAggregationProof, prover_id: &[u8; 32], - proof: c_slice::Ref, - commit_inputs: c_slice::Ref, + proof: c_slice::Ref<'_, u8>, + commit_inputs: c_slice::Ref<'_, AggregationInputs>, ) -> repr_c::Box { catch_panic_response("verify_aggregate_seal_proof", || { let inputs: Vec> = commit_inputs @@ -441,7 +441,7 @@ fn verify_aggregate_seal_proof( #[ffi_export] unsafe fn unseal_range( registered_proof: RegisteredSealProof, - cache_dir_path: c_slice::Ref, + cache_dir_path: c_slice::Ref<'_, u8>, sealed_sector_fd_raw: libc::c_int, unseal_output_fd_raw: libc::c_int, sector_id: u64, @@ -489,7 +489,7 @@ fn verify_seal( ticket: &[u8; 32], seed: &[u8; 32], sector_id: u64, - proof: c_slice::Ref, + proof: c_slice::Ref<'_, u8>, ) -> repr_c::Box { catch_panic_response("verify_seal", || { let proof_bytes: Vec = proof.to_vec(); @@ -539,7 +539,7 @@ fn generate_winning_post_sector_challenge( fn generate_fallback_sector_challenges( registered_proof: RegisteredPoStProof, randomness: &[u8; 32], - sector_ids: c_slice::Ref, + sector_ids: c_slice::Ref<'_, u64>, prover_id: &[u8; 32], ) -> repr_c::Box { catch_panic_response("generate_fallback_sector_challenges", || { @@ -570,7 +570,7 @@ fn generate_fallback_sector_challenges( #[ffi_export] fn generate_single_vanilla_proof( replica: PrivateReplicaInfo, - challenges: c_slice::Ref, + challenges: c_slice::Ref<'_, u64>, ) -> repr_c::Box { catch_panic_response("generate_single_vanilla_proof", || { let sector_id = SectorId::from(replica.sector_id); @@ -600,7 +600,7 @@ fn generate_winning_post_with_vanilla( registered_proof: RegisteredPoStProof, randomness: &[u8; 32], prover_id: &[u8; 32], - vanilla_proofs: c_slice::Ref, + vanilla_proofs: c_slice::Ref<'_, VanillaProof>, ) -> repr_c::Box { catch_panic_response("generate_winning_post_with_vanilla", || { let vanilla_proofs: Vec<_> = vanilla_proofs @@ -631,7 +631,7 @@ fn generate_winning_post_with_vanilla( #[ffi_export] fn generate_winning_post( randomness: &[u8; 32], - replicas: c_slice::Ref, + replicas: c_slice::Ref<'_, PrivateReplicaInfo>, prover_id: &[u8; 32], ) -> repr_c::Box { catch_panic_response("generate_winning_post", || { @@ -655,8 +655,8 @@ fn generate_winning_post( #[ffi_export] fn verify_winning_post( randomness: &[u8; 32], - replicas: c_slice::Ref, - proofs: c_slice::Ref, + replicas: c_slice::Ref<'_, PublicReplicaInfo>, + proofs: c_slice::Ref<'_, PoStProof>, prover_id: &[u8; 32], ) -> repr_c::Box { catch_panic_response("verify_winning_post", || { @@ -681,7 +681,7 @@ fn generate_window_post_with_vanilla( registered_proof: RegisteredPoStProof, randomness: &[u8; 32], prover_id: &[u8; 32], - vanilla_proofs: c_slice::Ref, + vanilla_proofs: c_slice::Ref<'_, VanillaProof>, ) -> repr_c::Box { catch_panic_response_raw("generate_window_post_with_vanilla", || { let vanilla_proofs: Vec<_> = vanilla_proofs @@ -737,7 +737,7 @@ fn generate_window_post_with_vanilla( #[ffi_export] fn generate_window_post( randomness: &[u8; 32], - replicas: c_slice::Ref, + replicas: c_slice::Ref<'_, PrivateReplicaInfo>, prover_id: &[u8; 32], ) -> repr_c::Box { catch_panic_response_raw("generate_window_post", || { @@ -785,8 +785,8 @@ fn generate_window_post( #[ffi_export] fn verify_window_post( randomness: &[u8; 32], - replicas: c_slice::Ref, - proofs: c_slice::Ref, + replicas: c_slice::Ref<'_, PublicReplicaInfo>, + proofs: c_slice::Ref<'_, PoStProof>, prover_id: &[u8; 32], ) -> repr_c::Box { catch_panic_response("verify_window_post", || { @@ -813,7 +813,7 @@ fn verify_window_post( #[ffi_export] fn merge_window_post_partition_proofs( registered_proof: RegisteredPoStProof, - partition_proofs: c_slice::Ref>, + partition_proofs: c_slice::Ref<'_, c_slice::Box>, ) -> repr_c::Box { catch_panic_response("merge_window_post_partition_proofs", || { let partition_proofs = partition_proofs @@ -854,7 +854,7 @@ fn generate_single_window_post_with_vanilla( registered_proof: RegisteredPoStProof, randomness: &[u8; 32], prover_id: &[u8; 32], - vanilla_proofs: c_slice::Ref, + vanilla_proofs: c_slice::Ref<'_, VanillaProof>, partition_index: libc::size_t, ) -> repr_c::Box { catch_panic_response_raw("generate_single_window_post_with_vanilla", || { @@ -909,12 +909,12 @@ fn generate_single_window_post_with_vanilla( #[ffi_export] fn empty_sector_update_encode_into( registered_proof: RegisteredUpdateProof, - new_replica_path: c_slice::Ref, - new_cache_dir_path: c_slice::Ref, - sector_key_path: c_slice::Ref, - sector_key_cache_dir_path: c_slice::Ref, - staged_data_path: c_slice::Ref, - pieces: c_slice::Ref, + new_replica_path: c_slice::Ref<'_, u8>, + new_cache_dir_path: c_slice::Ref<'_, u8>, + sector_key_path: c_slice::Ref<'_, u8>, + sector_key_cache_dir_path: c_slice::Ref<'_, u8>, + staged_data_path: c_slice::Ref<'_, u8>, + pieces: c_slice::Ref<'_, PublicPieceInfo>, ) -> repr_c::Box { catch_panic_response("empty_sector_update_encode_into", || { let public_pieces = pieces.iter().map(Into::into).collect::>(); @@ -941,10 +941,10 @@ fn empty_sector_update_encode_into( #[ffi_export] fn empty_sector_update_decode_from( registered_proof: RegisteredUpdateProof, - out_data_path: c_slice::Ref, - replica_path: c_slice::Ref, - sector_key_path: c_slice::Ref, - sector_key_cache_dir_path: c_slice::Ref, + out_data_path: c_slice::Ref<'_, u8>, + replica_path: c_slice::Ref<'_, u8>, + sector_key_path: c_slice::Ref<'_, u8>, + sector_key_cache_dir_path: c_slice::Ref<'_, u8>, comm_d_new: &[u8; 32], ) -> repr_c::Box { catch_panic_response("empty_sector_update_decode_from", || { @@ -1012,11 +1012,11 @@ unsafe fn empty_sector_update_decode_from_range( #[ffi_export] fn empty_sector_update_remove_encoded_data( registered_proof: RegisteredUpdateProof, - sector_key_path: c_slice::Ref, - sector_key_cache_dir_path: c_slice::Ref, - replica_path: c_slice::Ref, - replica_cache_path: c_slice::Ref, - data_path: c_slice::Ref, + sector_key_path: c_slice::Ref<'_, u8>, + sector_key_cache_dir_path: c_slice::Ref<'_, u8>, + replica_path: c_slice::Ref<'_, u8>, + replica_cache_path: c_slice::Ref<'_, u8>, + data_path: c_slice::Ref<'_, u8>, comm_d_new: &[u8; 32], ) -> repr_c::Box { catch_panic_response("empty_sector_update_remove_encoded_data", || { @@ -1041,10 +1041,10 @@ fn generate_empty_sector_update_partition_proofs( comm_r_old: &[u8; 32], comm_r_new: &[u8; 32], comm_d_new: &[u8; 32], - sector_key_path: c_slice::Ref, - sector_key_cache_dir_path: c_slice::Ref, - replica_path: c_slice::Ref, - replica_cache_path: c_slice::Ref, + sector_key_path: c_slice::Ref<'_, u8>, + sector_key_cache_dir_path: c_slice::Ref<'_, u8>, + replica_path: c_slice::Ref<'_, u8>, + replica_cache_path: c_slice::Ref<'_, u8>, ) -> repr_c::Box { catch_panic_response("generate_empty_sector_update_partition_proofs", || { let output = update::generate_partition_proofs( @@ -1072,7 +1072,7 @@ fn generate_empty_sector_update_partition_proofs( #[ffi_export] fn verify_empty_sector_update_partition_proofs( registered_proof: RegisteredUpdateProof, - proofs: c_slice::Ref, + proofs: c_slice::Ref<'_, ApiPartitionProof>, comm_r_old: &[u8; 32], comm_r_new: &[u8; 32], comm_d_new: &[u8; 32], @@ -1099,7 +1099,7 @@ fn verify_empty_sector_update_partition_proofs( #[ffi_export] fn generate_empty_sector_update_proof_with_vanilla( registered_proof: RegisteredUpdateProof, - vanilla_proofs: c_slice::Ref, + vanilla_proofs: c_slice::Ref<'_, ApiPartitionProof>, comm_r_old: &[u8; 32], comm_r_new: &[u8; 32], comm_d_new: &[u8; 32], @@ -1129,10 +1129,10 @@ fn generate_empty_sector_update_proof( comm_r_old: &[u8; 32], comm_r_new: &[u8; 32], comm_d_new: &[u8; 32], - sector_key_path: c_slice::Ref, - sector_key_cache_dir_path: c_slice::Ref, - replica_path: c_slice::Ref, - replica_cache_path: c_slice::Ref, + sector_key_path: c_slice::Ref<'_, u8>, + sector_key_cache_dir_path: c_slice::Ref<'_, u8>, + replica_path: c_slice::Ref<'_, u8>, + replica_cache_path: c_slice::Ref<'_, u8>, ) -> repr_c::Box { catch_panic_response("generate_empty_sector_update_proof", || { let result = update::generate_empty_sector_update_proof( @@ -1154,7 +1154,7 @@ fn generate_empty_sector_update_proof( #[ffi_export] fn verify_empty_sector_update_proof( registered_proof: RegisteredUpdateProof, - proof: c_slice::Ref, + proof: c_slice::Ref<'_, u8>, comm_r_old: &[u8; 32], comm_r_new: &[u8; 32], comm_d_new: &[u8; 32], @@ -1210,7 +1210,7 @@ unsafe fn generate_piece_commitment( #[ffi_export] fn generate_data_commitment( registered_proof: RegisteredSealProof, - pieces: c_slice::Ref, + pieces: c_slice::Ref<'_, PublicPieceInfo>, ) -> repr_c::Box { catch_panic_response("generate_data_commitment", || { let public_pieces: Vec = pieces.iter().map(Into::into).collect(); @@ -1223,7 +1223,7 @@ fn generate_data_commitment( #[ffi_export] fn clear_cache( sector_size: u64, - cache_dir_path: c_slice::Ref, + cache_dir_path: c_slice::Ref<'_, u8>, ) -> repr_c::Box { catch_panic_response("clear_cache", || { seal::clear_cache(sector_size, &as_path_buf(&cache_dir_path)?) @@ -1233,7 +1233,7 @@ fn clear_cache( #[ffi_export] fn clear_synthetic_proofs( sector_size: u64, - cache_dir_path: c_slice::Ref, + cache_dir_path: c_slice::Ref<'_, u8>, ) -> repr_c::Box { catch_panic_response("clear_synthetic_proofs", || { seal::clear_synthetic_proofs(sector_size, &as_path_buf(&cache_dir_path)?) @@ -1366,9 +1366,10 @@ fn registered_seal_proof_accessor( ) -> repr_c::Box { let rsp: api::RegisteredSealProof = registered_proof.into(); - repr_c::Box::new(StringResponse::from( + Box::new(StringResponse::from( op(rsp).map(|v| v.into_bytes().into_boxed_slice().into()), )) + .into() } fn registered_post_proof_accessor( @@ -1377,9 +1378,10 @@ fn registered_post_proof_accessor( ) -> repr_c::Box { let rsp: api::RegisteredPoStProof = registered_proof.into(); - repr_c::Box::new(StringResponse::from( + Box::new(StringResponse::from( op(rsp).map(|v| v.into_bytes().into_boxed_slice().into()), )) + .into() } destructor!( diff --git a/rust/src/util/types.rs b/rust/src/util/types.rs index 837c5b43..69f180ba 100644 --- a/rust/src/util/types.rs +++ b/rust/src/util/types.rs @@ -185,7 +185,7 @@ where } }; - repr_c::Box::new(result) + Box::new(result).into() } pub fn catch_panic_response_raw(name: &str, callback: F) -> repr_c::Box> @@ -218,7 +218,7 @@ where res }); - repr_c::Box::new(match result { + Box::new(match result { Ok(t) => match t { Ok(t) => Result::ok(t), Err(err) => Result::err_no_default(format!("{err:?}").into_bytes().into_boxed_slice()), @@ -236,6 +236,7 @@ where ) } }) + .into() } /// Generate a destructor for the given type wrapped in a `repr_c::Box`.