Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make BEEFY client keystore generic over BEEFY AuthorityId type #2258

Merged
Show file tree
Hide file tree
Changes from 50 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
0541cb0
Fix `BeefyAuthorityId::verify` for `ecdsa_bls_crypto` not to use `ecd…
drskalman Oct 27, 2023
099b86d
Fix comment in `primitives/consensus/beefy/src/lib.rs`
drskalman Oct 27, 2023
033ff57
- implement `sign/verify_with_hasher` for `ecdsa_bls377` `Pair` with …
drskalman Oct 31, 2023
76831b7
Fix typos and improve comment quality
drskalman Nov 1, 2023
a0c6d83
Add ecdsa_bls377_sign_with_keccak256 to the keystore
drskalman Nov 2, 2023
102ad62
add and implement `ecdsa_bls377_sign_with_keccak256`
drskalman Nov 3, 2023
25d1afc
- Make BEEFY Keyring to be generic over `AuthorityId`.
drskalman Nov 9, 2023
05a3ebd
Merge remote-tracking branch 'origin/master' into skalman--beefy-clie…
drskalman Nov 9, 2023
c860dd0
Improve documention and comments
drskalman Nov 9, 2023
8958fde
Remove unused SimpleKeyPair Trait
drskalman Nov 9, 2023
5ef71c8
Merge branch 'skalman--fix-ecdsa-bls-verify-in-beefy-primitives' of h…
drskalman Nov 13, 2023
3b8eded
add reasoning on why in BEEFY we want the ECDSA signature on Keccak …
drskalman Nov 13, 2023
efb350d
Merge branch 'master' into skalman--fix-ecdsa-bls-verify-in-beefy-pri…
drskalman Nov 13, 2023
8cfccd8
fmt
drskalman Nov 13, 2023
a15a60d
Improve documentation
drskalman Nov 13, 2023
85f8999
Merge branch 'master' into skalman--beefy-client-keystore-supporting-…
drskalman Nov 13, 2023
9667c1b
Merge branch 'skalman--beefy-client-keystore-supporting-both-ecdsa-an…
drskalman Nov 13, 2023
b18e2f4
Merge branch 'skalman--fix-ecdsa-bls-verify-in-beefy-primitives' into…
drskalman Nov 13, 2023
00b62ef
fmt
drskalman Nov 13, 2023
3ef0f65
Improve comment quality
drskalman Nov 27, 2023
a80264c
Merge branch 'master' into skalman--beefy-client-keystore-supporting-…
drskalman Dec 5, 2023
3f8d533
drop 'perhaps' from generate_with_phrase_should_be_recoverable_with_f…
drskalman Dec 5, 2023
1b48d48
Merge remote-tracking branch 'origin/master' into skalman--beefy-clie…
Lederstrumpf Dec 5, 2023
5f09d22
fmt
Lederstrumpf Dec 5, 2023
b04880d
Merge branch 'skalman--beefy-client-keystore-supporting-both-ecdsa-an…
drskalman Dec 5, 2023
6304d1e
Apply suggestions from code review
drskalman Jan 19, 2024
7fc1326
Apply suggestions from code review
drskalman Jan 19, 2024
6401a97
use std instead of sp_std as we are not in the Runtime
drskalman Jan 19, 2024
425c3d3
remove sp-std fro Cargo.lock
drskalman Jan 19, 2024
e98945f
Merge branch 'skalman--beefy-client-keystore-supporting-both-ecdsa-an…
drskalman Jan 20, 2024
59a4b5f
Do not re-export internal of primitives/consensus/beefy/src/test_utils
drskalman Jan 20, 2024
f2956c0
fix wrong doc for `BeefySignerAuthority::sign_with_hasher`
drskalman Jan 20, 2024
3422057
Make BEEFY Keyring itself generic over AuthId using PhantomData.
drskalman Jan 24, 2024
7454b6d
Compatiblize all client/beefy tests to Keyring<AuthorityId> enum model
drskalman Jan 25, 2024
dd686dc
Remove Sync + Send Bound from <AuthorityIdBound as RuntimeAppPublic>…
drskalman Jan 26, 2024
34d80cf
do `cargo fmt`
drskalman Jan 26, 2024
10089f1
Merge branch 'skalman--beefy-client-keystore-supporting-both-ecdsa-an…
drskalman Jan 26, 2024
0885c2a
Move function closer to the test
davxy Jan 29, 2024
edc6a9c
Fix some warnings
davxy Jan 29, 2024
9ec36d7
Merge branch 'master' into skalman--beefy-client-keystore-supporting-…
davxy Jan 29, 2024
cd35b5d
Fix std feat propagation
davxy Jan 29, 2024
3d5cc36
Fix beefy pallet
davxy Jan 29, 2024
77bdcfa
Make taplo happy
davxy Jan 29, 2024
ec1ef13
Add reference for the BLS implementation used in substrate
drskalman Jan 30, 2024
e4ad716
BEEFY keystore should error if asked to sign with any key beside ECDS…
drskalman Jan 30, 2024
018f13a
Improve `bls.rs` docs
drskalman Feb 1, 2024
98a8721
Test the private key constructed from phrase is the same as construct…
drskalman Feb 1, 2024
2271268
Verify secret (in)equality in key recovery tests.
drskalman Feb 1, 2024
d0dc187
Merge remote-tracking branch 'origin/master' into skalman--beefy-clie…
drskalman Feb 1, 2024
3cf2c72
discipline rogue "hash to field"s
Lederstrumpf Feb 1, 2024
0bca732
Merge branch 'master' into skalman--beefy-client-keystore-supporting-…
drskalman Feb 7, 2024
10f2f99
Merge branch 'master' into skalman--beefy-client-keystore-supporting-…
drskalman Feb 8, 2024
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions substrate/client/consensus/beefy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,12 @@ sp-consensus-grandpa = { path = "../../../primitives/consensus/grandpa" }
sp-keyring = { path = "../../../primitives/keyring" }
sp-tracing = { path = "../../../primitives/tracing" }
substrate-test-runtime-client = { path = "../../../test-utils/runtime/client" }

[features]
# This feature adds BLS crypto primitives. It should not be used in production since
# the BLS implementation and interface may still be subject to significant change.
bls-experimental = [
"sp-application-crypto/bls-experimental",
"sp-consensus-beefy/bls-experimental",
"sp-core/bls-experimental",
]
18 changes: 12 additions & 6 deletions substrate/client/consensus/beefy/src/communication/gossip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,8 +485,8 @@ pub(crate) mod tests {
use sc_network_test::Block;
use sp_application_crypto::key_types::BEEFY as BEEFY_KEY_TYPE;
use sp_consensus_beefy::{
ecdsa_crypto::Signature, known_payloads, Commitment, Keyring, MmrRootHash, Payload,
SignedCommitment, VoteMessage,
ecdsa_crypto::Signature, known_payloads, test_utils::Keyring, Commitment, MmrRootHash,
Payload, SignedCommitment, VoteMessage,
};
use sp_keystore::{testing::MemoryKeystore, Keystore};

Expand All @@ -507,10 +507,13 @@ pub(crate) mod tests {
}
}

pub fn sign_commitment<BN: Encode>(who: &Keyring, commitment: &Commitment<BN>) -> Signature {
pub fn sign_commitment<BN: Encode>(
who: &Keyring<AuthorityId>,
commitment: &Commitment<BN>,
) -> Signature {
let store = MemoryKeystore::new();
store.ecdsa_generate_new(BEEFY_KEY_TYPE, Some(&who.to_seed())).unwrap();
let beefy_keystore: BeefyKeystore = Some(store.into()).into();
let beefy_keystore: BeefyKeystore<AuthorityId> = Some(store.into()).into();
beefy_keystore.sign(&who.public(), &commitment.encode()).unwrap()
}

Expand Down Expand Up @@ -538,7 +541,10 @@ pub(crate) mod tests {
.validators()
.iter()
.map(|validator: &AuthorityId| {
Some(sign_commitment(&Keyring::from_public(validator).unwrap(), &commitment))
Some(sign_commitment(
&Keyring::<AuthorityId>::from_public(validator).unwrap(),
&commitment,
))
})
.collect();

Expand All @@ -547,7 +553,7 @@ pub(crate) mod tests {

#[test]
fn should_validate_messages() {
let keys = vec![Keyring::Alice.public()];
let keys = vec![Keyring::<AuthorityId>::Alice.public()];
let validator_set = ValidatorSet::<AuthorityId>::new(keys.clone(), 0).unwrap();
let (gv, mut report_stream) =
GossipValidator::<Block>::new(Arc::new(Mutex::new(KnownPeers::new())));
Expand Down
9 changes: 5 additions & 4 deletions substrate/client/consensus/beefy/src/justification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub(crate) fn verify_with_validator_set<Block: BlockT>(
.as_ref()
.map(|sig| {
signatures_checked += 1;
BeefyKeystore::verify(id, sig, &message[..])
BeefyKeystore::verify(*id, sig, &message[..])
})
.unwrap_or(false)
})
Expand All @@ -93,7 +93,8 @@ pub(crate) fn verify_with_validator_set<Block: BlockT>(
#[cfg(test)]
pub(crate) mod tests {
use sp_consensus_beefy::{
known_payloads, Commitment, Keyring, Payload, SignedCommitment, VersionedFinalityProof,
known_payloads, test_utils::Keyring, Commitment, Payload, SignedCommitment,
VersionedFinalityProof,
};
use substrate_test_runtime_client::runtime::Block;

Expand All @@ -103,7 +104,7 @@ pub(crate) mod tests {
pub(crate) fn new_finality_proof(
block_num: NumberFor<Block>,
validator_set: &ValidatorSet<AuthorityId>,
keys: &[Keyring],
keys: &[Keyring<AuthorityId>],
) -> BeefyVersionedFinalityProof<Block> {
let commitment = Commitment {
payload: Payload::from_single_entry(known_payloads::MMR_ROOT_ID, vec![]),
Expand Down Expand Up @@ -174,7 +175,7 @@ pub(crate) mod tests {
};
// change a signature to a different key
*bad_signed_commitment.signatures.first_mut().unwrap() =
Some(Keyring::Dave.sign(&bad_signed_commitment.commitment.encode()));
Some(Keyring::<AuthorityId>::Dave.sign(&bad_signed_commitment.commitment.encode()));
match verify_with_validator_set::<Block>(block_num, &validator_set, &bad_proof.into()) {
Err((ConsensusError::InvalidJustification, 3)) => (),
e => assert!(false, "Got unexpected {:?}", e),
Expand Down
Loading
Loading