Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
18c7d88
adding boilerplate for adding bls crypto
drskalman Dec 9, 2021
b86768c
First scratches to add bls crypto to primities/core and beefy.
drskalman Dec 10, 2021
fd75c93
suggested solution during BEEFY meeting for making BEEFY BLS compatible
drskalman Feb 15, 2022
322ad00
Merge remote-tracking branch 'origin/master' into skalman-bls-beefy
drskalman Feb 15, 2022
f7fca6d
- fix dependencies on arkwork and bls library.
drskalman Mar 10, 2022
5e8f2ea
to discuss HKDK with Al
drskalman May 9, 2022
2912fa1
resolve compilation errors for primitives/core/src/bls.rs
drskalman May 26, 2022
86b1e3a
resolve bls test compilation error, 6 tests still failing
drskalman May 31, 2022
2b59fa0
- change dependancy patches to repos available on github.
drskalman Jun 1, 2022
b602e7a
Merge branch 'master' of https://github.com/paritytech/substrate into…
drskalman Jun 1, 2022
68fd3a2
overwrite Cargo.lock from upstream and cargo-update to reslove Cargo.…
drskalman Jun 1, 2022
59d665e
add `bls_generate_new` and `bls_public_keys` to CryptoStore
drskalman Jun 14, 2022
857f85e
- implement host api `bls_public_keys, bls_generate, bls_sign,
drskalman Jun 14, 2022
a1ed112
- Adapt `primitives/beefy/src/commitment.rs and witness.rs` to have
drskalman Jun 28, 2022
b936150
implement TestNOPAggregatableSignature for Merkle based commitment.
drskalman Jul 4, 2022
1df925c
adapt an pass test for merkle root aggregator
drskalman Jul 5, 2022
28596f2
rust-fmtize
drskalman Jul 5, 2022
577cc68
add test for commitment containing aggregated bls signature.
drskalman Jul 7, 2022
0f53f28
make different traits for keystore for ecdsa-only and ecdsa-bls beefy…
drskalman Jul 18, 2022
fed0bbc
reverse the idea of validator aggregating received bls signature
drskalman Jul 21, 2022
7de89ae
make beefy primitve test compile and pass
drskalman Jul 23, 2022
5379e62
implement `should_convert_dually_signed_commitment_to_witness` test
drskalman Jul 25, 2022
7bdb082
Merge branch 'skalman-bls-beefy' into skalman-bls-beefy-client
drskalman Jul 25, 2022
1661c19
separate impl for ECDSA and BLS keystore
drskalman Aug 5, 2022
6a1c26f
Merge branch 'skalman-bls-beefy-client' of https://github.com/drskalm…
drskalman Aug 11, 2022
ab682ce
add bls support to LocalKeyStore
drskalman Aug 16, 2022
231a38e
implement `BeefyBLSKeystore` and `BeefyBLSnECDSAKeystore`
drskalman Aug 16, 2022
1847516
Make BeefyKeyStore generic for Beefy Worker
drskalman Aug 24, 2022
cc3a9d6
add BeefyKeystore generic type to GossipValidator so it can turn
drskalman Aug 30, 2022
e0d8740
adapt BEEFY GossipValidator to a generic Keystore
drskalman Sep 1, 2022
ea40ab9
- resolve errors in ECDSAnBLSKeystore implementation.
drskalman Sep 9, 2022
9349cac
clone keys on the fly while iterating.
drskalman Sep 12, 2022
787f80d
- rename `beefy::crypto` to `beefy:ecdsa_crypto`.
drskalman Sep 16, 2022
ab1c2f3
Merge branch 'skalman-bls-beefy' into skalman-bls-beefy-client
drskalman Sep 16, 2022
f48c8eb
- Make `BeefyApi` trait to distinguish between AuthorityId and PublicKey
drskalman Sep 19, 2022
d7044f8
share changes to beefy client to find solution to authority id problem
drskalman Sep 21, 2022
524debf
adapt Beefy Worker, GossipValidator and Round to Generic AuthId and T…
drskalman Sep 22, 2022
c8db18f
- Resolve conflict between Public and AuthId
drskalman Sep 24, 2022
95f6845
Merge branch 'master' into skalman-beefy-authority-id-adventures
drskalman Sep 26, 2022
50b2f9b
- updated tests to new bls library changes.
drskalman Oct 17, 2022
4c905a8
Merge branch 'master' into skalman-beefy-authority-id-adventures
drskalman Oct 18, 2022
5c89709
make all new Network and Communication objects depends on `AuthId` a…
drskalman Oct 18, 2022
782734d
- do not depend on rand default features (std).
drskalman Oct 26, 2022
2b9cc3c
minor changes and remove patching parity common.
drskalman Oct 27, 2022
8ebb239
move bls-like branch specification from patch to dep due to the cargo
drskalman Oct 29, 2022
a147238
- make all beefy tests generic over AuthityId, Signature and Keystore.
drskalman Oct 31, 2022
6cdc680
make `create_worker` generic on Keystore
drskalman Nov 4, 2022
95e283a
make Keyring generic over key type - down to 97 errors
drskalman Nov 25, 2022
d93fca0
implement keyring enum instead of wrapping it in a struct
drskalman Dec 8, 2022
accfaf7
- Re-apply BeefyVerify changes.
drskalman Dec 8, 2022
61d5168
First step in implementing Pair trait for ECDSAnBLS crypto
drskalman Dec 11, 2022
b03a4ce
- introduce `SimpleKeyPair` to make `Keyring` generic over key pair type
drskalman Dec 16, 2022
015e2a9
fix over hashing for bls_sign in the keystore
drskalman Dec 16, 2022
5022b7e
beefy `public_keys_works` test fails because the keystore forgets the…
drskalman Dec 19, 2022
2add57c
make testing infrastructure in `client/beefy/src/tests.rs` generic ov…
drskalman Jan 11, 2023
670c0cf
implement `beefy_finalizing_blocks_using_ecdsa_signature` though it o…
drskalman Jan 16, 2023
c6acac6
- implement beefy_finalizing_blocks_using_ecdsa_n_bls_signature
drskalman Jan 17, 2023
789a5a8
- making `new_finality_proof`,`lagging_validators`,`correct_beefy_pay…
drskalman Jan 17, 2023
1165d7c
make `voter_initialization`, `on_demand_beefy_justification_sync` gen…
drskalman Jan 17, 2023
1aaf6be
- Re-active tests and make helpers in beefy/worker.rs to crypto
drskalman Jan 18, 2023
59f10a4
implement keystore_vs_validator_set test for ecdsa and ecdsa_n_bls pa…
drskalman Jan 18, 2023
84a9902
depends on arkworks 0.4.0
drskalman Jan 25, 2023
744fe42
- use `store.authority_id` istead of key.contains in `keystore::publi…
drskalman Jan 29, 2023
6eaa95d
make beefy justification tests generic over keytype
drskalman Jan 30, 2023
18d5a59
- make rounds tests generic over key type
drskalman Jan 30, 2023
a010852
Merge branch 'master' into skalman-beefy-authority-id-adventures
drskalman Jan 31, 2023
d323ca7
make beefy client build after merging with master.
drskalman Feb 2, 2023
e53c9c8
adapt old test to new tokio style. new tests has been commented out.
drskalman Feb 3, 2023
d0c790a
new beefy tests in worker and tests adapted to generic key model
drskalman Feb 3, 2023
e08387f
- specify `AuthId` and `TSignature` when calling `load_persitent` oth…
drskalman Feb 4, 2023
3be0a82
get rid of redundant imports and fix all warnings.
drskalman Feb 4, 2023
42c894b
cargo fmt beefy primitives
drskalman Feb 4, 2023
469aadb
cargo fmt beefy client, keystore client and primitives, primitives
drskalman Feb 4, 2023
73657c5
Add `AuthoritySetCommitment` field to `BeefyAuthoritySet` needed by A…
drskalman Feb 24, 2023
096f94d
- depend on default branch of bls-like and apk-proofs.
drskalman Mar 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
cargo fmt beefy primitives
  • Loading branch information
drskalman committed Feb 4, 2023
commit 42c894b0079090781b42111282cbf29037d9826e
69 changes: 31 additions & 38 deletions primitives/beefy/src/commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,7 @@ pub struct SignedCommitment<TBlockNumber, TSignature> {
pub signatures: Vec<Option<TSignature>>,
}

impl<TBlockNumber, TSignature>
SignedCommitment<TBlockNumber, TSignature>
{
impl<TBlockNumber, TSignature> SignedCommitment<TBlockNumber, TSignature> {
/// Return the number of collected signatures.
pub fn no_of_signatures(&self) -> usize {
self.signatures.iter().filter(|x| x.is_some()).count()
Expand Down Expand Up @@ -135,15 +133,11 @@ struct CompactSignedCommitment<TBlockNumber, TSignature> {
signatures_compact: Vec<TSignature>,
}

impl<'a, TBlockNumber: Clone, TSignature>
CompactSignedCommitment<TBlockNumber, &'a TSignature>
{
impl<'a, TBlockNumber: Clone, TSignature> CompactSignedCommitment<TBlockNumber, &'a TSignature> {
/// Packs a `SignedCommitment` into the compressed `CompactSignedCommitment` format for
/// efficient network transport.
fn pack(
signed_commitment: &'a SignedCommitment<TBlockNumber, TSignature>,
) -> Self {
let SignedCommitment { commitment, signatures} = signed_commitment;
fn pack(signed_commitment: &'a SignedCommitment<TBlockNumber, TSignature>) -> Self {
let SignedCommitment { commitment, signatures } = signed_commitment;
let validator_set_len = signatures.len() as u32;

let signatures_compact: Vec<&'a TSignature> =
Expand Down Expand Up @@ -182,10 +176,7 @@ impl<'a, TBlockNumber: Clone, TSignature>

/// Unpacks a `CompactSignedCommitment` into the uncompressed `SignedCommitment` form.
fn unpack(
temporary_signatures: CompactSignedCommitment<
TBlockNumber,
TSignature,
>,
temporary_signatures: CompactSignedCommitment<TBlockNumber, TSignature>,
) -> SignedCommitment<TBlockNumber, TSignature> {
let CompactSignedCommitment {
commitment,
Expand Down Expand Up @@ -213,8 +204,7 @@ impl<'a, TBlockNumber: Clone, TSignature>
}
}

impl<TBlockNumber, TSignature> Encode
for SignedCommitment<TBlockNumber, TSignature>
impl<TBlockNumber, TSignature> Encode for SignedCommitment<TBlockNumber, TSignature>
where
TBlockNumber: Encode + Clone,
TSignature: Encode,
Expand All @@ -225,8 +215,7 @@ where
}
}

impl<TBlockNumber, TSignature> Decode
for SignedCommitment<TBlockNumber, TSignature>
impl<TBlockNumber, TSignature> Decode for SignedCommitment<TBlockNumber, TSignature>
where
TBlockNumber: Decode + Clone,
TSignature: Decode,
Expand Down Expand Up @@ -267,32 +256,31 @@ mod tests {
use crate::{crypto, known_payloads, KEY_TYPE};
use codec::Decode;

use crate::{ecdsa_crypto, KEY_TYPE, bls_crypto::{Signature as BLSSignature}};
use bls_like::{Keypair, SignedMessage as BLSSignedMessage, Signed, pop::SignatureAggregatorAssumingPoP, BLS377, SerializableToBytes};
use crate::{bls_crypto::Signature as BLSSignature, ecdsa_crypto, KEY_TYPE};
use bls_like::{
pop::SignatureAggregatorAssumingPoP, Keypair, SerializableToBytes, Signed,
SignedMessage as BLSSignedMessage, BLS377,
};

type TestCommitment = Commitment<u128>;

const LARGE_RAW_COMMITMENT: &[u8] = include_bytes!("../test-res/large-raw-commitment");

///types for bls-less commitment
///types for bls-less commitment

type TestSignedCommitment =
SignedCommitment<u128, ecdsa_crypto::Signature>;
type TestVersionedFinalityProof =
VersionedFinalityProof<u128, ecdsa_crypto::Signature>;
type TestSignedCommitment = SignedCommitment<u128, ecdsa_crypto::Signature>;
type TestVersionedFinalityProof = VersionedFinalityProof<u128, ecdsa_crypto::Signature>;

///types for commitment supporting aggregatable bls signature
#[derive(Clone, Debug, PartialEq, codec::Encode, codec::Decode)]
struct BLSAggregatableSignature(BLSSignature);

#[derive(Clone, Debug, PartialEq, codec::Encode, codec::Decode)]
struct ECDSABLSSignaturePair (ecdsa_crypto::Signature, BLSSignature);
struct ECDSABLSSignaturePair(ecdsa_crypto::Signature, BLSSignature);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: concatenation ECDSABLS is hard to decipher. I'd either go with ECDSAnBLS/BLSnECDSA, as you've done here and here, or break style convention with #[allow(non_camel_case_types)] & BLS_ECDSA_SignaturePair, which I find useful for crypto acronyms.


type TestBLSSignedCommitment = SignedCommitment<u128, ECDSABLSSignaturePair>;
type TestVersionedBLSFinalityProof = VersionedFinalityProof<u128, ECDSABLSSignaturePair>;

type TestBLSSignedCommitment =
SignedCommitment<u128, ECDSABLSSignaturePair>;
type TestVersionedBLSFinalityProof =
VersionedFinalityProof<u128, ECDSABLSSignaturePair>;

// The mock signatures are equivalent to the ones produced by the BEEFY keystore
fn mock_ecdsa_signatures() -> (ecdsa_crypto::Signature, ecdsa_crypto::Signature) {
let store: SyncCryptoStorePtr = KeyStore::new().into();
Expand All @@ -317,7 +305,7 @@ mod tests {

///generates mock aggregatable bls signature for generating test commitment
///BLS signatures
fn mock_bls_signatures() -> (BLSSignature, BLSSignature) {
fn mock_bls_signatures() -> (BLSSignature, BLSSignature) {
let store: SyncCryptoStorePtr = KeyStore::new().into();

let mut alice = sp_core::bls::Pair::from_string("//Alice", None).unwrap();
Expand Down Expand Up @@ -400,11 +388,18 @@ mod tests {
//aggregatedsigs.aggregate(&bls_signed_msgs.0);
//aggregatedsigs.aggregate(&bls_signed_msgs.1);

//let aggregated_signature = (&aggregatedsigs).signature(); //<SignatureAggregatorAssumingPoP<BLS377>) as Signed>::signature(&aggregatedsigs.signature());
//let aggregated_signature = (&aggregatedsigs).signature();
// //<SignatureAggregatorAssumingPoP<BLS377>) as
// Signed>::signature(&aggregatedsigs.signature());

let ecdsa_and_bls_signed = SignedCommitment {
commitment,
signatures: vec![None, None, Some(ECDSABLSSignaturePair(ecdsa_sigs.0, bls_signed_msgs.0)), Some(ECDSABLSSignaturePair(ecdsa_sigs.1, bls_signed_msgs.1))],
signatures: vec![
None,
None,
Some(ECDSABLSSignaturePair(ecdsa_sigs.0, bls_signed_msgs.0)),
Some(ECDSABLSSignaturePair(ecdsa_sigs.1, bls_signed_msgs.1)),
],
};

//when
Expand All @@ -415,15 +410,13 @@ mod tests {

// then
assert_eq!(decoded, Ok(ecdsa_and_bls_signed));
assert_eq!(
assert_eq!(
encoded,
hex_literal::hex!(
"046d68343048656c6c6f20576f726c642105000000000000000000000000000000000000000000000004300400000008558455ad81279df0795cc985580e4fb75d72d948d1107b2ac80a09abed4da8480c746cc321f2319a5e99a830e314d10dd3cd68ce3dc0c33c86e99bcb7816f9ba0134835b340f62cb1bcb58f2cbdb4435a0e1780c5ec56c88ec198f9300581712a1d4876ce82befeeaf97d72351b25b9c002c729c651768c11f692807fb5ee5e8c50c1f07576fe705b406bc677e706304e92438b80e1bc87e0591ed99273a5a46012d6e1f8105c337a86cdd9aaacdc496577f3db8c55ef9e6fd48f2c5c05a2274707491635d8ba3df64f324575b7b2a34487bca2324b6a0046395a71681be3d0c2a0084c79ad33c5c69de77c1242167b1b11469df914306073696dbedd1d03805c917a9fb0074d2003dad4bb476f1f560650085fb69b3c2cedfbbd8d3aa8b80ac9525fe5cafbd585d84c0e49052df577e85602bb892a3bfd8525d15478e05a0f47b80"
)
);


}
}

#[test]
fn signed_commitment_count_signatures() {
Expand Down
29 changes: 13 additions & 16 deletions primitives/beefy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,20 @@ pub trait BeefyAuthorityId<MsgHash: Hash>: RuntimeAppPublic {
///
/// Your code should use the above types as concrete types for all crypto related
/// functionality.
///
pub mod ecdsa_crypto {
use super::{BeefyAuthorityId, Hash, RuntimeAppPublic};
use sp_application_crypto::{app_crypto, ecdsa};
use sp_core::crypto::Wraps;
app_crypto!(ecdsa, crate::KEY_TYPE);
use super::{BeefyAuthorityId, Hash, RuntimeAppPublic};
use sp_application_crypto::{app_crypto, ecdsa};
use sp_core::crypto::Wraps;
app_crypto!(ecdsa, crate::KEY_TYPE);

/// Identity of a BEEFY authority using ECDSA as its crypto.
pub type AuthorityId = Public;
/// Identity of a BEEFY authority using ECDSA as its crypto.
pub type AuthorityId = Public;

/// Signature for a BEEFY authority using ECDSA as its crypto.
pub type AuthoritySignature = Signature;
/// Signature for a BEEFY authority using ECDSA as its crypto.
pub type AuthoritySignature = Signature;

impl<MsgHash: Hash> BeefyAuthorityId<MsgHash> for AuthorityId
where
impl<MsgHash: Hash> BeefyAuthorityId<MsgHash> for AuthorityId
where
<MsgHash as Hash>::Output: Into<[u8; 32]>,
{
fn verify(&self, signature: &<Self as RuntimeAppPublic>::Signature, msg: &[u8]) -> bool {
Expand All @@ -97,7 +96,6 @@ pub mod ecdsa_crypto {
}
}
}

}

/// BEEFY cryptographic types for BLS crypto
Expand All @@ -109,7 +107,6 @@ pub mod ecdsa_crypto {
///
/// Your code should use the above types as concrete types for all crypto related
/// functionality.
///
pub mod bls_crypto {
use sp_application_crypto::{app_crypto, bls};
app_crypto!(bls, crate::KEY_TYPE);
Expand Down Expand Up @@ -219,7 +216,7 @@ impl<AuthorityId> OnNewValidatorSet<AuthorityId> for () {
}

sp_api::decl_runtime_apis! {
/// API necessary for BEEFY voters with only ECDSA key.
/// API necessary for BEEFY voters with only ECDSA key.
pub trait BeefyApi<AuthorityId> where AuthorityId : Encode + Decode
{
/// Return the current active BEEFY validator set
Expand Down Expand Up @@ -248,8 +245,8 @@ mod tests {
assert_eq!(validators.validators(), &vec![alice.public()]);
}

#[test]
fn beefy_verify_works() {
#[test]
fn beefy_verify_works() {
let msg = &b"test-message"[..];
let (pair, _) = crypto::Pair::generate();

Expand Down
93 changes: 54 additions & 39 deletions primitives/beefy/src/witness.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

// This file is part of Substrate.

// Copyright (C) 2021-2022 Parity Technologies (UK) Ltd.
Expand Down Expand Up @@ -66,8 +65,7 @@ impl<TBlockNumber, TAggregatedSignature>
aggregator: TSignatureAggregator,
) -> (Self, Vec<Option<TSignature>>)
where
TSignatureAggregator:
FnOnce(&[Option<TSignature>]) -> TAggregatedSignature,
TSignatureAggregator: FnOnce(&[Option<TSignature>]) -> TAggregatedSignature,
{
let SignedCommitment { commitment, signatures } = signed;
let signed_by = signatures.iter().map(|s| s.is_some()).collect();
Expand All @@ -86,23 +84,25 @@ mod tests {
use super::*;
use codec::Decode;

use crate::{ecdsa_crypto, known_payloads, Payload, KEY_TYPE, bls_crypto::{Signature as BLSSignature}};
use bls_like::{pop::SignatureAggregatorAssumingPoP, Signed, EngineBLS, BLS377, SerializableToBytes};
use crate::{
bls_crypto::Signature as BLSSignature, ecdsa_crypto, known_payloads, Payload, KEY_TYPE,
};
use bls_like::{
pop::SignatureAggregatorAssumingPoP, EngineBLS, SerializableToBytes, Signed, BLS377,
};
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see pub type BLS377 = UsualBLS<ark_bls12_377::Bls12_377, ark_bls12_377::Config>; and UsualBLS uses 48 byte keys and hashes-to-G2, but..

We do not want to hash-to-G2. We want to both hash-to-G1 and also run apk proofs on G1.

This requires that public keys be on both G1 and G2 and contain a DLEQ proof between them. This is the point of https://eprint.iacr.org/2022/1611


type TestCommitment = Commitment<u128>;

///types for ecdsa signed commitment
type TestSignedCommitment =
SignedCommitment<u128, ecdsa_crypto::Signature>;
type TestSignedCommitment = SignedCommitment<u128, ecdsa_crypto::Signature>;
type TestSignedCommitmentWitness =
SignedCommitmentWitness<u128, Vec<Option<ecdsa_crypto::Signature>>>;

#[derive(Clone, Debug, PartialEq, codec::Encode, codec::Decode)]
struct ECDSABLSSignaturePair (ecdsa_crypto::Signature, BLSSignature);
struct ECDSABLSSignaturePair(ecdsa_crypto::Signature, BLSSignature);

///types for commitment containing bls signature along side ecdsa signature
type TestBLSSignedCommitment =
SignedCommitment<u128, ECDSABLSSignaturePair>;
type TestBLSSignedCommitment = SignedCommitment<u128, ECDSABLSSignaturePair>;
type TestBLSSignedCommitmentWitness =
SignedCommitmentWitness<u128, [u8; BLS377::SIGNATURE_SERIALIZED_SIZE]>;

Expand Down Expand Up @@ -130,7 +130,7 @@ mod tests {

///generates mock aggregatable bls signature for generating test commitment
///BLS signatures
fn mock_bls_signatures() -> (BLSSignature, BLSSignature) {
fn mock_bls_signatures() -> (BLSSignature, BLSSignature) {
let store: SyncCryptoStorePtr = KeyStore::new().into();

let mut alice = sp_core::bls::Pair::from_string("//Alice", None).unwrap();
Expand All @@ -157,10 +157,7 @@ mod tests {

let sigs = mock_ecdsa_signatures();

SignedCommitment {
commitment,
signatures: vec![None, None, Some(sigs.0), Some(sigs.1)],
}
SignedCommitment { commitment, signatures: vec![None, None, Some(sigs.0), Some(sigs.1)] }
}

fn ecdsa_and_bls_signed_commitment() -> TestBLSSignedCommitment {
Expand All @@ -174,8 +171,12 @@ mod tests {

SignedCommitment {
commitment,
signatures: vec![None, None, Some(ECDSABLSSignaturePair(ecdsa_sigs.0, bls_sigs.0)), Some(ECDSABLSSignaturePair(ecdsa_sigs.1, bls_sigs.1))],

signatures: vec![
None,
None,
Some(ECDSABLSSignaturePair(ecdsa_sigs.0, bls_sigs.0)),
Some(ECDSABLSSignaturePair(ecdsa_sigs.1, bls_sigs.1)),
],
}
}

Expand All @@ -185,12 +186,11 @@ mod tests {
let signed = ecdsa_signed_commitment();

// when
let (witness, signatures) = TestSignedCommitmentWitness::from_signed::<_,_,Vec<Option<ecdsa_crypto::Signature>>>(
signed,
|sigs| {
sigs.to_vec()
},
);
let (witness, signatures) = TestSignedCommitmentWitness::from_signed::<
_,
_,
Vec<Option<ecdsa_crypto::Signature>>,
>(signed, |sigs| sigs.to_vec());

// then
assert_eq!(witness.aggregated_signature, signatures);
Expand All @@ -202,30 +202,45 @@ mod tests {
let signed = ecdsa_and_bls_signed_commitment();

// when
let (witness, signatures) = TestBLSSignedCommitmentWitness::from_signed::<_,_,[u8; BLS377::SIGNATURE_SERIALIZED_SIZE]>(
signed,
|sigs| {
//we are going to aggregate the signatures here
let mut aggregatedsigs : SignatureAggregatorAssumingPoP<BLS377> = SignatureAggregatorAssumingPoP::new();
sigs.iter().filter_map(|sig| sig.clone().map(|sig| aggregatedsigs.add_signature(&(bls_like::Signature::from_bytes(<BLSSignature as AsRef<[u8]>>::as_ref(&sig.1.clone()).try_into().unwrap())).unwrap())));
(&aggregatedsigs).signature().to_bytes()
}
);
let (witness, signatures) = TestBLSSignedCommitmentWitness::from_signed::<
_,
_,
[u8; BLS377::SIGNATURE_SERIALIZED_SIZE],
>(signed, |sigs| {
//we are going to aggregate the signatures here
let mut aggregatedsigs: SignatureAggregatorAssumingPoP<BLS377> =
SignatureAggregatorAssumingPoP::new();
sigs.iter().filter_map(|sig| {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not only I assumed the commitment is the aggregated signature, I tought is should be computed only by the prover not each validator. I think @AlistairStewart says that this is the commitment and it should be computed and sign by all validators:
commitment-to-public-keys

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the commitment to the set of public keys here: https://github.com/paritytech/substrate/pull/13311/files#diff-90d0377841064e4bcca6f0956bf16bd71e11159f9dd6d5975b91f2b4d901b0a4R200

It is not clear for me where it should be actually computed and updated.

sig.clone().map(|sig| {
aggregatedsigs.add_signature(
&(bls_like::Signature::from_bytes(
<BLSSignature as AsRef<[u8]>>::as_ref(&sig.1.clone())
.try_into()
.unwrap(),
))
.unwrap(),
)
})
});
(&aggregatedsigs).signature().to_bytes()
});
// then
BLSSignature::try_from(witness.aggregated_signature.as_slice()).unwrap();
//, signatures.iter().filter_map(|sig| sig.map(|sig| (bls_like::Signature::<BLS377>::from_bytes(<BLSSignature as AsRef<[u8]>>::as_ref(&sig.1).try_into().unwrap())).unwrap())).collect::<Vec<bls_like::Signature::<BLS377>>>().iter().sum());
//, signatures.iter().filter_map(|sig| sig.map(|sig|
//, (bls_like::Signature::<BLS377>::from_bytes(<BLSSignature as
//, AsRef<[u8]>>::as_ref(&sig.1).try_into().unwrap())).unwrap())).
//, collect::<Vec<bls_like::Signature::<BLS377>>>().iter().sum());
}

#[test]
fn should_encode_and_decode_witness() {
// given
let signed = ecdsa_signed_commitment();
let (witness, _) = TestSignedCommitmentWitness::from_signed::<_,_,Vec<Option<ecdsa_crypto::Signature>>>(
signed,
|sigs: &[std::option::Option<ecdsa_crypto::Signature>]| {
sigs.to_vec()
},
);
let (witness, _) =
TestSignedCommitmentWitness::from_signed::<_, _, Vec<Option<ecdsa_crypto::Signature>>>(
signed,
|sigs: &[std::option::Option<ecdsa_crypto::Signature>]| sigs.to_vec(),
);

// when
let encoded = codec::Encode::encode(&witness);
Expand Down