Function grin_core::libtx::aggsig::verify_single_from_commit

source ·
pub fn verify_single_from_commit(
    secp: &Secp256k1,
    sig: &Signature,
    msg: &Message,
    commit: &Commitment
) -> Result<(), Error>
Expand description

Simple verification a single signature from a commitment. The public key used to verify the signature is derived from the commit. Returns Ok(()) if the signature is valid, or a Signature ErrorKind otherwise

§Arguments

  • secp - A Secp256k1 Context initialized for Verification
  • sig - The Signature to verify
  • msg - The message to sign (fee|lockheight).
  • commit - The commitment to verify. The actual public key used during verification is derived from this commit.

§Example

use core::consensus::reward;
use core::libtx::{aggsig, proof};
use util::secp::key::{PublicKey, SecretKey};
use util::secp::{ContextFlag, Secp256k1};
use core::core::transaction::KernelFeatures;
use core::core::{Output, OutputFeatures};
use keychain::{Keychain, ExtKeychain, SwitchCommitmentType};
use std::convert::TryInto;

// Create signature
let secp = Secp256k1::with_caps(ContextFlag::Commit);
let keychain = ExtKeychain::from_random_seed(false).unwrap();
let fees = 10_000;
let value = reward(fees);
let key_id = ExtKeychain::derive_key_id(1, 1, 0, 0, 0);
let switch = SwitchCommitmentType::Regular;
let commit = keychain.commit(value, &key_id, switch).unwrap();
let builder = proof::ProofBuilder::new(&keychain);
let proof = proof::create(&keychain, &builder, value, &key_id, switch, commit, None).unwrap();
let output = Output::new(OutputFeatures::Coinbase, commit, proof);
let height = 20;
let over_commit = secp.commit_value(reward(fees)).unwrap();
let out_commit = output.commitment();
let features = KernelFeatures::HeightLocked{fee: 1.into(), lock_height: height};
let msg = features.kernel_sig_msg().unwrap();
let excess = secp.commit_sum(vec![out_commit], vec![over_commit]).unwrap();
let pubkey = excess.to_pubkey(&secp).unwrap();
let sig = aggsig::sign_from_key_id(&secp, &keychain, &msg, value, &key_id, None, Some(&pubkey)).unwrap();

// Verify the signature from the excess commit
let sig_verifies =
    aggsig::verify_single_from_commit(&keychain.secp(), &sig, &msg, &excess);
assert!(!sig_verifies.is_err());