Skip to content

Commit

Permalink
rusk-abi: add verify_bls_multisig host function
Browse files Browse the repository at this point in the history
  • Loading branch information
herr-seppia committed Sep 9, 2024
1 parent dc3c514 commit 6e13628
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
14 changes: 13 additions & 1 deletion rusk-abi/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ use alloc::vec::Vec;
use dusk_bytes::Serializable;
use execution_core::{
signatures::{
bls::{PublicKey as BlsPublicKey, Signature as BlsSignature},
bls::{
MultisigPublicKey, MultisigSignature, PublicKey as BlsPublicKey,
Signature as BlsSignature,
},
schnorr::{
PublicKey as SchnorrPublicKey, Signature as SchnorrSignature,
},
Expand Down Expand Up @@ -54,6 +57,15 @@ pub fn verify_bls(msg: Vec<u8>, pk: BlsPublicKey, sig: BlsSignature) -> bool {
host_query(Query::VERIFY_BLS, (msg, pk, sig))
}

/// Verify a BLS signature is valid for the given public key and message
pub fn verify_bls_multisig(
msg: Vec<u8>,
pk: MultisigPublicKey,
sig: MultisigSignature,
) -> bool {
host_query(Query::VERIFY_BLS_MULTISIG, (msg, pk, sig))
}

/// Get the chain ID.
pub fn chain_id() -> u8 {
meta_data(Metadata::CHAIN_ID).unwrap()
Expand Down
24 changes: 23 additions & 1 deletion rusk-abi/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ use dusk_poseidon::{Domain, Hash as PoseidonHash};
use execution_core::{
plonk::{Proof, Verifier},
signatures::{
bls::{PublicKey as BlsPublicKey, Signature as BlsSignature},
bls::{
MultisigPublicKey, MultisigSignature, PublicKey as BlsPublicKey,
Signature as BlsSignature,
},
schnorr::{
PublicKey as SchnorrPublicKey, Signature as SchnorrSignature,
},
Expand Down Expand Up @@ -78,6 +81,10 @@ fn register_host_queries(vm: &mut VM) {
vm.register_host_query(Query::VERIFY_PROOF, host_verify_proof);
vm.register_host_query(Query::VERIFY_SCHNORR, host_verify_schnorr);
vm.register_host_query(Query::VERIFY_BLS, host_verify_bls);
vm.register_host_query(
Query::VERIFY_BLS_MULTISIG,
host_verify_bls_multisig,
);
}

fn wrap_host_query<A, R, F>(arg_buf: &mut [u8], arg_len: u32, closure: F) -> u32
Expand Down Expand Up @@ -135,6 +142,12 @@ fn host_verify_bls(arg_buf: &mut [u8], arg_len: u32) -> u32 {
})
}

fn host_verify_bls_multisig(arg_buf: &mut [u8], arg_len: u32) -> u32 {
wrap_host_query(arg_buf, arg_len, |(msg, pk, sig)| {
verify_bls_multisig(msg, pk, sig);
})
}

/// Compute the blake2b hash of the given scalars, returning the resulting
/// scalar. The hash is computed in such a way that it will always return a
/// valid scalar.
Expand Down Expand Up @@ -176,3 +189,12 @@ pub fn verify_schnorr(
pub fn verify_bls(msg: Vec<u8>, pk: BlsPublicKey, sig: BlsSignature) -> bool {
pk.verify(&sig, &msg).is_ok()
}

/// Verify a BLS signature is valid for the given public key and message
pub fn verify_bls_multisig(
msg: Vec<u8>,
pk: MultisigPublicKey,
sig: MultisigSignature,
) -> bool {
pk.verify(&sig, &msg).is_ok()
}
7 changes: 5 additions & 2 deletions rusk-abi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ mod abi;
#[cfg(feature = "abi")]
pub use abi::{
block_height, chain_id, hash, owner, owner_raw, poseidon_hash, self_owner,
self_owner_raw, verify_bls, verify_proof, verify_schnorr,
self_owner_raw, verify_bls, verify_bls_multisig, verify_proof,
verify_schnorr,
};

#[cfg(feature = "abi")]
Expand All @@ -54,7 +55,8 @@ mod host;
#[cfg(feature = "host")]
pub use host::{
hash, new_ephemeral_vm, new_genesis_session, new_session, new_vm,
poseidon_hash, verify_bls, verify_proof, verify_schnorr,
poseidon_hash, verify_bls, verify_bls_multisig, verify_proof,
verify_schnorr,
};
#[cfg(feature = "host")]
pub use piecrust::{
Expand All @@ -79,4 +81,5 @@ impl Query {
pub const VERIFY_PROOF: &'static str = "verify_proof";
pub const VERIFY_SCHNORR: &'static str = "verify_schnorr";
pub const VERIFY_BLS: &'static str = "verify_bls";
pub const VERIFY_BLS_MULTISIG: &'static str = "verify_bls_multisig";
}

0 comments on commit 6e13628

Please sign in to comment.