Skip to content
This repository was archived by the owner on Feb 6, 2025. It is now read-only.

Commit f9b81ae

Browse files
Merge pull request #2 from pragma-org/amw/validate_block_kes_signature
feat: Validate conway block KES signatures
2 parents 36b4f01 + 5d914a7 commit f9b81ae

File tree

7 files changed

+375
-129
lines changed

7 files changed

+375
-129
lines changed

Diff for: ouroboros-praos/Cargo.toml

+11-5
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,20 @@ edition = "2021"
66
[dependencies]
77
hex = "0.4"
88
ouroboros = { path = "../ouroboros" }
9-
pallas-crypto = { git = "https://github.com/txpipe/pallas", rev = "252714d58a93d58bf2cd7ada1156e3ace10a8298" }
10-
pallas-math = { git = "https://github.com/txpipe/pallas", rev = "252714d58a93d58bf2cd7ada1156e3ace10a8298" }
11-
pallas-primitives = { git = "https://github.com/txpipe/pallas", rev = "252714d58a93d58bf2cd7ada1156e3ace10a8298" }
9+
pallas-crypto = { git = "https://github.com/txpipe/pallas", rev = "4871342a8deffaceafb5e0f771e1623dfe57e25f" }
10+
pallas-math = { git = "https://github.com/txpipe/pallas", rev = "4871342a8deffaceafb5e0f771e1623dfe57e25f" }
11+
pallas-primitives = { git = "https://github.com/txpipe/pallas", rev = "4871342a8deffaceafb5e0f771e1623dfe57e25f" }
1212
tracing = "0.1"
13+
rayon = "1.10.0"
1314

1415
[dev-dependencies]
1516
ctor = "0.2"
1617
insta = { version = "1.40.0", features = ["yaml"] }
1718
mockall = "0.13"
18-
pallas-traverse = { git = "https://github.com/txpipe/pallas", rev = "252714d58a93d58bf2cd7ada1156e3ace10a8298" }
19-
tracing-subscriber = "0.3"
19+
pallas-traverse = { git = "https://github.com/txpipe/pallas", rev = "4871342a8deffaceafb5e0f771e1623dfe57e25f" }
20+
tracing-subscriber = "0.3"
21+
criterion = "0.5.1"
22+
23+
[[bench]]
24+
harness = false
25+
name = "benchmark"

Diff for: ouroboros-praos/benches/benchmark.rs

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
use criterion::{criterion_group, criterion_main, Criterion};
2+
use mockall::predicate::eq;
3+
use ouroboros::ledger::{MockLedgerState, PoolId, PoolSigma};
4+
use ouroboros::validator::Validator;
5+
use ouroboros_praos::consensus::BlockValidator;
6+
use pallas_crypto::hash::Hash;
7+
use pallas_math::math::{FixedDecimal, FixedPrecision};
8+
use pallas_traverse::MultiEraHeader;
9+
10+
fn validate_conway_block() {
11+
let test_block = include_bytes!("../tests/data/mainnet_blockheader_10817298.cbor");
12+
let test_vector = vec![(
13+
"00beef0a9be2f6d897ed24a613cf547bb20cd282a04edfc53d477114",
14+
"c0d1f9b040d2f6fd7fc8775d24753d6db4b697429f11404a6178a0a4a005867b",
15+
"c7937fc47fecbe687891b3decd71e904d1e129598aa3852481d295eea3ea3ada",
16+
25626202470912_u64,
17+
22586623335121436_u64,
18+
true,
19+
)];
20+
21+
for (pool_id_str, vrf_vkey_hash_str, epoch_nonce_str, numerator, denominator, expected) in
22+
test_vector
23+
{
24+
let pool_id: PoolId = pool_id_str.parse().unwrap();
25+
let vrf_vkey_hash: Hash<32> = vrf_vkey_hash_str.parse().unwrap();
26+
let epoch_nonce: Hash<32> = epoch_nonce_str.parse().unwrap();
27+
28+
let active_slots_coeff: FixedDecimal =
29+
FixedDecimal::from(5u64) / FixedDecimal::from(100u64);
30+
let c = (FixedDecimal::from(1u64) - active_slots_coeff).ln();
31+
let conway_block_tag: u8 = 6;
32+
let multi_era_header = MultiEraHeader::decode(conway_block_tag, None, test_block).unwrap();
33+
let babbage_header = multi_era_header.as_babbage().expect("Infallible");
34+
assert_eq!(babbage_header.header_body.slot, 134402628u64);
35+
36+
let mut ledger_state = MockLedgerState::new();
37+
ledger_state
38+
.expect_pool_id_to_sigma()
39+
.with(eq(pool_id))
40+
.returning(move |_| {
41+
Ok(PoolSigma {
42+
numerator,
43+
denominator,
44+
})
45+
});
46+
ledger_state
47+
.expect_vrf_vkey_hash()
48+
.with(eq(pool_id))
49+
.returning(move |_| Ok(vrf_vkey_hash));
50+
ledger_state.expect_slot_to_kes_period().returning(|slot| {
51+
// hardcode some values from shelley-genesis.json for the mock implementation
52+
let slots_per_kes_period: u64 = 129600; // from shelley-genesis.json (1.5 days in seconds)
53+
slot / slots_per_kes_period
54+
});
55+
ledger_state.expect_max_kes_evolutions().returning(|| 62);
56+
ledger_state
57+
.expect_latest_opcert_sequence_number()
58+
.returning(|_| None);
59+
60+
let block_validator = BlockValidator::new(babbage_header, &ledger_state, &epoch_nonce, &c);
61+
assert_eq!(block_validator.validate().is_ok(), expected);
62+
}
63+
}
64+
65+
fn benchmark_validate_conway_block(c: &mut Criterion) {
66+
c.bench_function("validate_conway_block", |b| {
67+
b.iter(|| validate_conway_block())
68+
});
69+
}
70+
71+
criterion_group!(benches, benchmark_validate_conway_block);
72+
criterion_main!(benches);

Diff for: ouroboros-praos/criterion.toml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[profile.release]
2+
measurement_time = 10.0 # Increase the measurement time to 10 seconds
3+
sample_size = 100 # Increase the sample size to 100

0 commit comments

Comments
 (0)