Skip to content

Commit b3fba92

Browse files
authored
feat: simplify the verify-signatures feature (#2020)
* feat: simplify the verify-signatures feature A new ambassador crate was released so we can now use attributes inside delegable traits (and some macros that were previously unexported are now exported by default). Basically, I'm just deleting code. * chore: update changelog
1 parent 5659196 commit b3fba92

File tree

5 files changed

+13
-55
lines changed

5 files changed

+13
-55
lines changed

Cargo.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ arbitrary = "1.3.0"
6464
itertools = "0.11.0"
6565
once_cell = "1.18.0"
6666
unsigned-varint = "0.7.2"
67-
ambassador = "0.3.5"
67+
ambassador = "0.4.0"
6868

6969
# dev/tools/tests
7070
criterion = "0.5.1"

fvm/CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Changes to the reference FVM implementation.
44

55
## [Unreleased]
66

7+
- **BREAKING**: Simplify the verify-signtures feature and update ambassador. This is a minor-breaking change because the ambassador macros are now only exported from the prelude/kernel module, not the crate root as they previously were.
8+
79
## 4.3.0 [2023-06-12]
810

911
- feat: FIP-0079: syscall for aggregated bls verification [#2003](https://github.com/filecoin-project/ref-fvm/pull/2003)

fvm/src/kernel/mod.rs

+7-51
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,11 @@ pub trait ActorOps {
220220
fn balance_of(&self, actor_id: ActorID) -> Result<TokenAmount>;
221221
}
222222

223-
#[cfg(feature = "verify-signature")]
224223
/// Cryptographic primitives provided by the kernel.
225224
#[delegatable_trait]
226225
pub trait CryptoOps {
227226
/// Verifies that a signature is valid for an address and plaintext.
227+
#[cfg(feature = "verify-signature")]
228228
fn verify_signature(
229229
&self,
230230
sig_type: SignatureType,
@@ -263,40 +263,6 @@ pub trait CryptoOps {
263263
fn hash(&self, code: u64, data: &[u8]) -> Result<Multihash>;
264264
}
265265

266-
#[cfg(not(feature = "verify-signature"))]
267-
/// Cryptographic primitives provided by the kernel.
268-
#[delegatable_trait]
269-
pub trait CryptoOps {
270-
/// Verifies a BLS aggregate signature. In the case where there is one signer/signed plaintext,
271-
/// this is equivalent to verifying a non-aggregated BLS signature.
272-
///
273-
/// Returns:
274-
/// - `Ok(true)` on a valid signature.
275-
/// - `Ok(false)` on an invalid signature or if the signature or public keys' bytes represent an
276-
/// invalid curve point.
277-
/// - `Err(IllegalArgument)` if `pub_keys.len() != plaintexts.len()`.
278-
fn verify_bls_aggregate(
279-
&self,
280-
aggregate_sig: &[u8; fvm_shared::crypto::signature::BLS_SIG_LEN],
281-
pub_keys: &[[u8; fvm_shared::crypto::signature::BLS_PUB_LEN]],
282-
plaintexts_concat: &[u8],
283-
plaintext_lens: &[u32],
284-
) -> Result<bool>;
285-
286-
/// Given a message hash and its signature, recovers the public key of the signer.
287-
fn recover_secp_public_key(
288-
&self,
289-
hash: &[u8; SECP_SIG_MESSAGE_HASH_SIZE],
290-
signature: &[u8; SECP_SIG_LEN],
291-
) -> Result<[u8; SECP_PUB_LEN]>;
292-
293-
/// Hashes input `data_in` using with the specified hash function, writing the output to
294-
/// `digest_out`, returning the size of the digest written to `digest_out`. If `digest_out` is
295-
/// to small to fit the entire digest, it will be truncated. If too large, the leftover space
296-
/// will not be overwritten.
297-
fn hash(&self, code: u64, data: &[u8]) -> Result<Multihash>;
298-
}
299-
300266
/// Randomness queries.
301267
#[delegatable_trait]
302268
pub trait RandomnessOps {
@@ -341,19 +307,15 @@ pub trait EventOps {
341307
) -> Result<()>;
342308
}
343309

344-
// Unfortunately, I need to do this to make it possible to name these macros by path. I'm hiding
345-
// this because I really don't want users to glob import the `kernel` module.
346-
#[doc(hidden)]
347-
pub use {
348-
ambassador_impl_CryptoOps, ambassador_impl_DebugOps, ambassador_impl_EventOps,
349-
ambassador_impl_IpldBlockOps, ambassador_impl_MessageOps, ambassador_impl_NetworkOps,
350-
ambassador_impl_RandomnessOps, ambassador_impl_SelfOps, ambassador_impl_SendOps,
351-
ambassador_impl_UpgradeOps,
352-
};
353-
354310
/// Import this module (with a glob) if you're implementing a kernel, _especially_ if you want to
355311
/// use ambassador to delegate the implementation.
356312
pub mod prelude {
313+
pub use super::{
314+
ambassador_impl_ActorOps, ambassador_impl_CryptoOps, ambassador_impl_DebugOps,
315+
ambassador_impl_EventOps, ambassador_impl_IpldBlockOps, ambassador_impl_MessageOps,
316+
ambassador_impl_NetworkOps, ambassador_impl_RandomnessOps, ambassador_impl_SelfOps,
317+
ambassador_impl_SendOps, ambassador_impl_UpgradeOps,
318+
};
357319
pub use super::{
358320
ActorOps, CryptoOps, DebugOps, EventOps, IpldBlockOps, MessageOps, NetworkOps,
359321
RandomnessOps, SelfOps, SendOps, UpgradeOps,
@@ -376,12 +338,6 @@ pub mod prelude {
376338
pub use fvm_shared::version::NetworkVersion;
377339
pub use fvm_shared::{ActorID, MethodNum};
378340
pub use multihash::Multihash;
379-
pub use {
380-
ambassador_impl_ActorOps, ambassador_impl_CryptoOps, ambassador_impl_DebugOps,
381-
ambassador_impl_EventOps, ambassador_impl_IpldBlockOps, ambassador_impl_MessageOps,
382-
ambassador_impl_NetworkOps, ambassador_impl_RandomnessOps, ambassador_impl_SelfOps,
383-
ambassador_impl_SendOps, ambassador_impl_UpgradeOps,
384-
};
385341
}
386342

387343
use prelude::*;

testing/test_actors/actors/fil-syscall-actor/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ publish = false
66

77
[target.'cfg(target_arch = "wasm32")'.dependencies]
88
fvm_ipld_encoding = { workspace = true }
9-
fvm_sdk = { workspace = true, default-features = false }
9+
fvm_sdk = { workspace = true }
1010
fvm_shared = { workspace = true }
1111
multihash = { workspace = true, features = ["sha3", "sha2", "ripemd"] }
1212
minicov = {version = "0.3", optional = true}

0 commit comments

Comments
 (0)