Skip to content

Commit aa5a4eb

Browse files
committed
feat: make empty block_kes_validator and add KesValidationError Type
1 parent 9fedc00 commit aa5a4eb

File tree

10 files changed

+362
-2
lines changed

10 files changed

+362
-2
lines changed

Cargo.lock

Lines changed: 34 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ members = [
2727
"modules/chain_store", # Tracks historical information about blocks and TXs
2828
"modules/tx_submitter", # Submits TXs to peers
2929
"modules/block_vrf_validator", # Validate the VRF calculation in the block header
30+
"modules/block_kes_validator", # Validate KES in the block header
3031

3132
# Process builds
3233
"processes/omnibus", # All-inclusive omnibus process

common/src/validation.rs

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub enum ValidationError {
1616
BadVRF(#[from] VrfValidationError),
1717

1818
#[error("KES failure")]
19-
BadKES,
19+
BadKES(#[from] KesValidationError),
2020

2121
#[error("Doubly spent UTXO: {0}")]
2222
DoubleSpendUTXO(String),
@@ -220,3 +220,70 @@ impl PartialEq for BadVrfProofError {
220220
}
221221
}
222222
}
223+
224+
/// Reference
225+
/// https://github.com/IntersectMBO/ouroboros-consensus/blob/e3c52b7c583bdb6708fac4fdaa8bf0b9588f5a88/ouroboros-consensus-protocol/src/ouroboros-consensus-protocol/Ouroboros/Consensus/Protocol/Praos.hs#L342
226+
#[derive(Error, Clone, Debug, serde::Serialize, serde::Deserialize, PartialEq)]
227+
pub enum KesValidationError {
228+
/// Current KES period is before the OCert start period
229+
#[error(
230+
"KES Before Start OCert: OCert Start Period={}, Current Period={}",
231+
ocert_start_period,
232+
current_period
233+
)]
234+
KesBeforeStartOcert {
235+
ocert_start_period: u64,
236+
current_period: u64,
237+
},
238+
/// Current KES period is after the valid range
239+
#[error(
240+
"KES After End OCert: Current Period={}, OCert Start Period={}, Max KES Evolutions={}",
241+
current_period,
242+
ocert_start_period,
243+
max_kes_evolutions
244+
)]
245+
KesAfterEndOcert {
246+
current_period: u64,
247+
ocert_start_period: u64,
248+
max_kes_evolutions: u64,
249+
},
250+
/// The OCert counter is too small
251+
#[error(
252+
"Counter Too Small OCert: Last Counter={}, Current Counter={}",
253+
last_counter,
254+
current_counter
255+
)]
256+
CounterTooSmallOcert {
257+
last_counter: u64,
258+
current_counter: u64,
259+
},
260+
/// The OCert counter incremented by more than 1 (Praos only)
261+
#[error(
262+
"Counter Over Incremented OCert: Last Counter={}, Current Counter={}",
263+
last_counter,
264+
current_counter
265+
)]
266+
CounterOverIncrementedOcert {
267+
last_counter: u64,
268+
current_counter: u64,
269+
},
270+
/// The cold key signature on the OCert is invalid
271+
#[error(
272+
"Invalid Signature OCert: Counter={}, KES Period={}",
273+
counter,
274+
kes_period
275+
)]
276+
InvalidSignatureOcert { counter: u64, kes_period: u64 },
277+
/// The KES signature verification failed
278+
#[error("Invalid KES Signature OCert: Current KES Period={}, KES Start Period={}, Expected Evolutions={}, Max KES Evolutions={}, Error Message={}", current_kes_period, kes_start_period, expected_evolutions, max_kes_evolutions, error_message)]
279+
InvalidKesSignatureOcert {
280+
current_kes_period: u64,
281+
kes_start_period: u64,
282+
expected_evolutions: u64,
283+
max_kes_evolutions: u64,
284+
error_message: String,
285+
},
286+
/// No counter found for this key hash (not a stake pool or genesis delegate)
287+
#[error("No Counter For Key Hash OCert: Pool ID={}", hex::encode(pool_id))]
288+
NoCounterForKeyHashOcert { pool_id: PoolId },
289+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Acropolis Block KES Validator
2+
3+
[package]
4+
name = "acropolis_module_block_kes_validator"
5+
version = "0.1.0"
6+
edition = "2021"
7+
authors = ["Golddy <[email protected]>"]
8+
description = "Validate the KES in the block header"
9+
license = "Apache-2.0"
10+
11+
[dependencies]
12+
acropolis_common = { path = "../../common" }
13+
14+
caryatid_sdk = { workspace = true }
15+
16+
anyhow = { workspace = true }
17+
config = { workspace = true }
18+
hex = { workspace = true }
19+
imbl = { workspace = true }
20+
tokio = { workspace = true }
21+
tracing = { workspace = true }
22+
serde_json = { workspace = true }
23+
serde = { workspace = true }
24+
blake2 = "0.10.6"
25+
num-traits = "0.2"
26+
thiserror = "2.0.17"
27+
28+
kes-summed-ed25519 = { git = "https://github.com/txpipe/kes", rev = "f69fb357d46f6a18925543d785850059569d7e78" }
29+
30+
[lib]
31+
path = "src/block_kes_validator.rs"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
mod ouroboros;
2+
mod state;

0 commit comments

Comments
 (0)