Update to signature-scheme 0.5.2
This commit is contained in:
parent
977f3edfb6
commit
9c4a1f1d1f
@ -110,10 +110,11 @@ impl AttestationAggregator {
|
|||||||
Message::BadValidatorIndex
|
Message::BadValidatorIndex
|
||||||
);
|
);
|
||||||
|
|
||||||
if !free_attestation
|
if !free_attestation.signature.verify(
|
||||||
.signature
|
&signable_message,
|
||||||
.verify(&signable_message, spec.domain_attestation, &validator_record.pubkey)
|
spec.domain_attestation,
|
||||||
{
|
&validator_record.pubkey,
|
||||||
|
) {
|
||||||
return Ok(Outcome {
|
return Ok(Outcome {
|
||||||
valid: false,
|
valid: false,
|
||||||
message: Message::BadSignature,
|
message: Message::BadSignature,
|
||||||
|
@ -137,8 +137,10 @@ impl<T: SlotClock, U: BeaconNode, V: DutiesReader, W: Signer> Attester<T, U, V,
|
|||||||
fn sign_attestation_data(&mut self, attestation_data: &AttestationData) -> Option<Signature> {
|
fn sign_attestation_data(&mut self, attestation_data: &AttestationData) -> Option<Signature> {
|
||||||
self.store_produce(attestation_data);
|
self.store_produce(attestation_data);
|
||||||
|
|
||||||
self.signer
|
self.signer.sign_attestation_message(
|
||||||
.sign_attestation_message(&attestation_data.signable_message(PHASE_0_CUSTODY_BIT)[..], DOMAIN_ATTESTATION)
|
&attestation_data.signable_message(PHASE_0_CUSTODY_BIT)[..],
|
||||||
|
DOMAIN_ATTESTATION,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` if signing some attestation_data is safe (non-slashable).
|
/// Returns `true` if signing some attestation_data is safe (non-slashable).
|
||||||
|
@ -134,7 +134,10 @@ impl<T: SlotClock, U: BeaconNode, V: DutiesReader, W: Signer> BlockProducer<T, U
|
|||||||
// TODO: add domain, etc to this message. Also ensure result matches `into_to_bytes32`.
|
// TODO: add domain, etc to this message. Also ensure result matches `into_to_bytes32`.
|
||||||
let message = ssz_encode(&slot.epoch(self.spec.epoch_length));
|
let message = ssz_encode(&slot.epoch(self.spec.epoch_length));
|
||||||
|
|
||||||
match self.signer.sign_randao_reveal(&message, self.spec.domain_randao) {
|
match self
|
||||||
|
.signer
|
||||||
|
.sign_randao_reveal(&message, self.spec.domain_randao)
|
||||||
|
{
|
||||||
None => return Ok(PollOutcome::SignerRejection(slot)),
|
None => return Ok(PollOutcome::SignerRejection(slot)),
|
||||||
Some(signature) => signature,
|
Some(signature) => signature,
|
||||||
}
|
}
|
||||||
@ -166,10 +169,10 @@ impl<T: SlotClock, U: BeaconNode, V: DutiesReader, W: Signer> BlockProducer<T, U
|
|||||||
fn sign_block(&mut self, mut block: BeaconBlock) -> Option<BeaconBlock> {
|
fn sign_block(&mut self, mut block: BeaconBlock) -> Option<BeaconBlock> {
|
||||||
self.store_produce(&block);
|
self.store_produce(&block);
|
||||||
|
|
||||||
match self
|
match self.signer.sign_block_proposal(
|
||||||
.signer
|
&block.proposal_root(&self.spec)[..],
|
||||||
.sign_block_proposal(&block.proposal_root(&self.spec)[..], self.spec.domain_proposal)
|
self.spec.domain_proposal,
|
||||||
{
|
) {
|
||||||
None => None,
|
None => None,
|
||||||
Some(signature) => {
|
Some(signature) => {
|
||||||
block.signature = signature;
|
block.signature = signature;
|
||||||
|
@ -30,11 +30,8 @@ use fast_math::log2_raw;
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use types::{
|
use types::{
|
||||||
readers::BeaconBlockReader,
|
readers::BeaconBlockReader, slot_epoch::Slot, slot_height::SlotHeight,
|
||||||
slot_epoch::Slot,
|
validator_registry::get_active_validator_indices, BeaconBlock, Hash256,
|
||||||
slot_height::SlotHeight,
|
|
||||||
validator_registry::get_active_validator_indices,
|
|
||||||
BeaconBlock, Hash256,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//TODO: Pruning - Children
|
//TODO: Pruning - Children
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
|
@ -27,8 +27,11 @@ impl Attestation {
|
|||||||
custody_bit: bool,
|
custody_bit: bool,
|
||||||
domain: u64,
|
domain: u64,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
self.aggregate_signature
|
self.aggregate_signature.verify(
|
||||||
.verify(&self.signable_message(custody_bit), domain, group_public_key)
|
&self.signable_message(custody_bit),
|
||||||
|
domain,
|
||||||
|
group_public_key,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
use crate::test_utils::TestRandom;
|
use crate::test_utils::TestRandom;
|
||||||
use crate::{
|
use crate::{
|
||||||
validator::StatusFlags, validator_registry::get_active_validator_indices, AttestationData,
|
validator::StatusFlags, validator_registry::get_active_validator_indices, AttestationData,
|
||||||
Bitfield, ChainSpec, Crosslink, Deposit, DepositInput, Epoch, Eth1Data, Eth1DataVote, Fork, Hash256,
|
Bitfield, ChainSpec, Crosslink, Deposit, DepositInput, Epoch, Eth1Data, Eth1DataVote, Fork,
|
||||||
PendingAttestation, PublicKey, Signature, Slot, Validator,
|
Hash256, PendingAttestation, PublicKey, Signature, Slot, Validator,
|
||||||
};
|
};
|
||||||
use honey_badger_split::SplitExt;
|
use honey_badger_split::SplitExt;
|
||||||
use rand::RngCore;
|
use rand::RngCore;
|
||||||
@ -593,7 +593,7 @@ impl BeaconState {
|
|||||||
pubkey: PublicKey,
|
pubkey: PublicKey,
|
||||||
proof_of_possession: Signature,
|
proof_of_possession: Signature,
|
||||||
withdrawal_credentials: Hash256,
|
withdrawal_credentials: Hash256,
|
||||||
spec: &ChainSpec
|
spec: &ChainSpec,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let proof_of_possession_data = DepositInput {
|
let proof_of_possession_data = DepositInput {
|
||||||
pubkey: pubkey.clone(),
|
pubkey: pubkey.clone(),
|
||||||
@ -603,15 +603,12 @@ impl BeaconState {
|
|||||||
|
|
||||||
proof_of_possession.verify(
|
proof_of_possession.verify(
|
||||||
&proof_of_possession_data.hash_tree_root(),
|
&proof_of_possession_data.hash_tree_root(),
|
||||||
self.fork.get_domain(
|
self.fork
|
||||||
self.slot.epoch(spec.epoch_length),
|
.get_domain(self.slot.epoch(spec.epoch_length), spec.domain_deposit),
|
||||||
spec.domain_deposit,
|
|
||||||
),
|
|
||||||
&pubkey,
|
&pubkey,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Process a validator deposit, returning the validator index if the deposit is valid.
|
/// Process a validator deposit, returning the validator index if the deposit is valid.
|
||||||
///
|
///
|
||||||
/// Spec v0.2.0
|
/// Spec v0.2.0
|
||||||
@ -623,7 +620,12 @@ impl BeaconState {
|
|||||||
withdrawal_credentials: Hash256,
|
withdrawal_credentials: Hash256,
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
) -> Result<usize, ()> {
|
) -> Result<usize, ()> {
|
||||||
if !self.validate_proof_of_possession(pubkey.clone(), proof_of_possession, withdrawal_credentials, &spec) {
|
if !self.validate_proof_of_possession(
|
||||||
|
pubkey.clone(),
|
||||||
|
proof_of_possession,
|
||||||
|
withdrawal_credentials,
|
||||||
|
&spec,
|
||||||
|
) {
|
||||||
return Err(());
|
return Err(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ impl Fork {
|
|||||||
/// Get the domain number that represents the fork meta and signature domain.
|
/// Get the domain number that represents the fork meta and signature domain.
|
||||||
pub fn get_domain(&self, epoch: Epoch, domain_type: u64) -> u64 {
|
pub fn get_domain(&self, epoch: Epoch, domain_type: u64) -> u64 {
|
||||||
let fork_version = self.get_fork_version(epoch);
|
let fork_version = self.get_fork_version(epoch);
|
||||||
fork_version * u64::pow(2,32) + domain_type
|
fork_version * u64::pow(2, 32) + domain_type
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ authors = ["Paul Hauner <paul@paulhauner.com>"]
|
|||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bls-aggregates = { git = "https://github.com/sigp/signature-schemes", tag = "0.4.1" }
|
bls-aggregates = { git = "https://github.com/sigp/signature-schemes", tag = "0.5.2" }
|
||||||
hashing = { path = "../hashing" }
|
hashing = { path = "../hashing" }
|
||||||
hex = "0.3"
|
hex = "0.3"
|
||||||
serde = "1.0"
|
serde = "1.0"
|
||||||
|
@ -27,7 +27,12 @@ impl AggregateSignature {
|
|||||||
///
|
///
|
||||||
/// Only returns `true` if the set of keys in the `AggregatePublicKey` match the set of keys
|
/// Only returns `true` if the set of keys in the `AggregatePublicKey` match the set of keys
|
||||||
/// that signed the `AggregateSignature`.
|
/// that signed the `AggregateSignature`.
|
||||||
pub fn verify(&self, msg: &[u8], domain: u64, aggregate_public_key: &AggregatePublicKey) -> bool {
|
pub fn verify(
|
||||||
|
&self,
|
||||||
|
msg: &[u8],
|
||||||
|
domain: u64,
|
||||||
|
aggregate_public_key: &AggregatePublicKey,
|
||||||
|
) -> bool {
|
||||||
self.0.verify(msg, domain, aggregate_public_key)
|
self.0.verify(msg, domain, aggregate_public_key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,6 @@ fn extend_if_needed(hash: &mut Vec<u8>) {
|
|||||||
/// For some signature and public key, ensure that the signature message was the public key and it
|
/// For some signature and public key, ensure that the signature message was the public key and it
|
||||||
/// was signed by the secret key that corresponds to that public key.
|
/// was signed by the secret key that corresponds to that public key.
|
||||||
|
|
||||||
|
|
||||||
pub fn create_proof_of_possession(keypair: &Keypair) -> Signature {
|
pub fn create_proof_of_possession(keypair: &Keypair) -> Signature {
|
||||||
Signature::new(&ssz_encode(&keypair.pk), 0, &keypair.sk)
|
Signature::new(&ssz_encode(&keypair.pk), 0, &keypair.sk)
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,11 @@ impl Signature {
|
|||||||
/// Instantiate a new Signature from a message and a SecretKey, where the message has already
|
/// Instantiate a new Signature from a message and a SecretKey, where the message has already
|
||||||
/// been hashed.
|
/// been hashed.
|
||||||
pub fn new_hashed(x_real_hashed: &[u8], x_imaginary_hashed: &[u8], sk: &SecretKey) -> Self {
|
pub fn new_hashed(x_real_hashed: &[u8], x_imaginary_hashed: &[u8], sk: &SecretKey) -> Self {
|
||||||
Signature(RawSignature::new_hashed(x_real_hashed, x_imaginary_hashed, sk.as_raw()))
|
Signature(RawSignature::new_hashed(
|
||||||
|
x_real_hashed,
|
||||||
|
x_imaginary_hashed,
|
||||||
|
sk.as_raw(),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Verify the Signature against a PublicKey.
|
/// Verify the Signature against a PublicKey.
|
||||||
@ -30,8 +34,14 @@ impl Signature {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Verify the Signature against a PublicKey, where the message has already been hashed.
|
/// Verify the Signature against a PublicKey, where the message has already been hashed.
|
||||||
pub fn verify_hashed(&self, x_real_hashed: &[u8], x_imaginary_hashed: &[u8], pk: &PublicKey) -> bool {
|
pub fn verify_hashed(
|
||||||
self.0.verify_hashed(x_real_hashed, x_imaginary_hashed, pk.as_raw())
|
&self,
|
||||||
|
x_real_hashed: &[u8],
|
||||||
|
x_imaginary_hashed: &[u8],
|
||||||
|
pk: &PublicKey,
|
||||||
|
) -> bool {
|
||||||
|
self.0
|
||||||
|
.verify_hashed(x_real_hashed, x_imaginary_hashed, pk.as_raw())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the underlying signature.
|
/// Returns the underlying signature.
|
||||||
@ -41,7 +51,9 @@ impl Signature {
|
|||||||
|
|
||||||
/// Returns a new empty signature.
|
/// Returns a new empty signature.
|
||||||
pub fn empty_signature() -> Self {
|
pub fn empty_signature() -> Self {
|
||||||
let empty: Vec<u8> = vec![0; 96];
|
let mut empty: Vec<u8> = vec![0; 96];
|
||||||
|
// TODO: Modify the way flags are used (b_flag should not be used for empty_signature in the future)
|
||||||
|
empty[0] += u8::pow(2, 6);
|
||||||
Signature(RawSignature::from_bytes(&empty).unwrap())
|
Signature(RawSignature::from_bytes(&empty).unwrap())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -99,9 +111,13 @@ mod tests {
|
|||||||
|
|
||||||
let sig_as_bytes: Vec<u8> = sig.as_raw().as_bytes();
|
let sig_as_bytes: Vec<u8> = sig.as_raw().as_bytes();
|
||||||
|
|
||||||
assert_eq!(sig_as_bytes.len(), 97);
|
assert_eq!(sig_as_bytes.len(), 96);
|
||||||
for one_byte in sig_as_bytes.iter() {
|
for (i, one_byte) in sig_as_bytes.iter().enumerate() {
|
||||||
assert_eq!(*one_byte, 0);
|
if i == 0 {
|
||||||
|
assert_eq!(*one_byte, u8::pow(2, 6));
|
||||||
|
} else {
|
||||||
|
assert_eq!(*one_byte, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user