Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
6a6b33f
Introduce trait
Jun 2, 2020
363bb02
Implement VRFSigner in keystore
Jun 2, 2020
45c7582
Use vrf_sign from keystore
Jun 2, 2020
4fcf607
Convert output to VRFInOut
Jun 2, 2020
3c148b7
Simplify conversion
Jun 2, 2020
3ca49f6
vrf_sign secondary slot using keystore
Jun 2, 2020
f292623
Fix RPC call to claim_slot
Jun 2, 2020
df6063d
Use Public instead of Pair
Jun 2, 2020
76bcb2c
Check primary threshold in signer
Jun 4, 2020
81e31c5
Fix interface to return error
Jun 4, 2020
1d64e56
Move vrf_sign to BareCryptoStore
Jun 4, 2020
95a7b93
Merge remote-tracking branch 'upstream/master' into vrf-signing
Jun 4, 2020
f62b1d7
Fix authorship_works test
Jun 4, 2020
04ec073
Fix BABE logic leaks
Jun 7, 2020
6c6f380
Acquire a read lock once
Jun 7, 2020
c572d13
Also fix RPC acquiring the read lock once
Jun 7, 2020
b5415f6
Merge remote-tracking branch 'upstream/master' into vrf-signing
Jun 7, 2020
e4db9bf
Implement a generic way to construct VRF Transcript
Jun 8, 2020
b581c6c
Use make_transcript_data to call sr25519_vrf_sign
Jun 8, 2020
022b706
Make sure VRFTranscriptData is serializable
Jun 8, 2020
0c23a48
Cleanup
Jun 8, 2020
c3f17de
Move VRF to it's own module
Jun 8, 2020
a691f24
Implement & test VRF signing in testing module
Jun 8, 2020
a5821f0
Merge remote-tracking branch 'upstream/master' into vrf-signing
Jun 8, 2020
b5322c3
Remove leftover
Jun 8, 2020
53bed39
Fix feature requirements
Jun 8, 2020
43596d7
Revert removing vec macro
Jun 8, 2020
61e3b8d
Drop keystore pointer to prevent deadlock
Jun 8, 2020
383bf44
Nitpicks
Jun 8, 2020
2508594
Add test to make sure make_transcript works
Jun 8, 2020
1fd6936
Fix mismatch in VRF transcript
Jun 10, 2020
b45a1ca
Add a test to verify transcripts match in babe
Jun 10, 2020
df7dd65
Merge remote-tracking branch 'upstream/master' into vrf-signing
Jun 10, 2020
67b1c03
Return VRFOutput and VRFProof from keystore
Jun 10, 2020
e46467b
Merge remote-tracking branch 'upstream/master' into vrf-signing
Jun 10, 2020
ecd7cf1
Merge remote-tracking branch 'upstream/master' into vrf-signing
Jun 18, 2020
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
Add a test to verify transcripts match in babe
  • Loading branch information
Rakan Alhneiti committed Jun 10, 2020
commit b45a1ca1fbdeba407eb438cd2db1f50a404f811d
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.

1 change: 1 addition & 0 deletions client/consensus/babe/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ sc-service = { version = "0.8.0-rc2", default-features = false, path = "../../se
substrate-test-runtime-client = { version = "2.0.0-rc2", path = "../../../test-utils/runtime/client" }
sc-block-builder = { version = "0.8.0-rc2", path = "../../block-builder" }
env_logger = "0.7.0"
rand_chacha = "0.2.2"
tempfile = "3.1.0"

[features]
Expand Down
48 changes: 46 additions & 2 deletions client/consensus/babe/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,14 @@
#![allow(deprecated)]
use super::*;
use authorship::claim_slot;
use sp_core::crypto::Pair;
use sp_consensus_babe::{AuthorityPair, SlotNumber, AllowedSlots};
use sp_core::{crypto::Pair, vrf::make_transcript as transcript_from_data};
use sp_consensus_babe::{
AuthorityPair,
SlotNumber,
AllowedSlots,
make_transcript,
make_transcript_data,
};
use sc_block_builder::{BlockBuilder, BlockBuilderProvider};
use sp_consensus::{
NoNetwork as DummyOracle, Proposal, RecordProof,
Expand All @@ -35,6 +41,11 @@ use sp_runtime::{generic::DigestItem, traits::{Block as BlockT, DigestFor}};
use sc_client_api::{BlockchainEvents, backend::TransactionFor};
use log::debug;
use std::{time::Duration, cell::RefCell, task::Poll};
use rand::RngCore;
use rand_chacha::{
rand_core::SeedableRng,
ChaChaRng,
};

type Item = DigestItem<Hash>;

Expand Down Expand Up @@ -796,3 +807,36 @@ fn verify_slots_are_strictly_increasing() {
&mut block_import,
);
}

#[test]
fn babe_transcript_generation_match() {
let _ = env_logger::try_init();
let keystore_path = tempfile::tempdir().expect("Creates keystore path");
let keystore = sc_keystore::Store::open(keystore_path.path(), None).expect("Creates keystore");
let pair = keystore.write().insert_ephemeral_from_seed::<AuthorityPair>("//Alice")
.expect("Generates authority pair");

let epoch = Epoch {
start_slot: 0,
authorities: vec![(pair.public(), 1)],
randomness: [0; 32],
epoch_index: 1,
duration: 100,
config: BabeEpochConfiguration {
c: (3, 10),
allowed_slots: AllowedSlots::PrimaryAndSecondaryPlainSlots,
},
};

let orig_transcript = make_transcript(&epoch.randomness.clone(), 1, epoch.epoch_index);
let new_transcript = make_transcript_data(&epoch.randomness, 1, epoch.epoch_index);

let test = |t: merlin::Transcript| -> [u8; 16] {
let mut b = [0u8; 16];
t.build_rng()
.finalize(&mut ChaChaRng::from_seed([0u8;32]))
.fill_bytes(&mut b);
b
};
debug_assert!(test(orig_transcript) == test(transcript_from_data(new_transcript)));
}
6 changes: 4 additions & 2 deletions primitives/core/src/vrf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ mod tests {
use super::*;
use crate::vrf::VRFTranscriptValue;
use rand::RngCore;
use rand_chacha::rand_core::SeedableRng;
use rand_chacha::ChaChaRng;
use rand_chacha::{
rand_core::SeedableRng,
ChaChaRng,
};

#[test]
fn transcript_creation_matches() {
Expand Down