Skip to content

Commit 2e61a83

Browse files
authored
Merge pull request #1170 from input-output-hk/ensemble/668/protocol-key-for-avk
Protocol key for certificate AVK
2 parents 45768aa + 90619fc commit 2e61a83

File tree

29 files changed

+198
-130
lines changed

29 files changed

+198
-130
lines changed

Cargo.lock

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

mithril-aggregator/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mithril-aggregator"
3-
version = "0.3.72"
3+
version = "0.3.73"
44
description = "A Mithril Aggregator server"
55
authors = { workspace = true }
66
edition = { workspace = true }

mithril-aggregator/src/database/provider/certificate.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl CertificateRecord {
8282
parent_certificate_id: Some(parent_id.to_string()),
8383
message: "message".to_string(),
8484
signature: fake_keys::multi_signature()[0].to_owned(),
85-
aggregate_verification_key: "avk".to_string(),
85+
aggregate_verification_key: fake_keys::aggregate_verification_key()[0].to_owned(),
8686
epoch: beacon.epoch,
8787
beacon,
8888
protocol_version: "protocol_version".to_string(),
@@ -113,7 +113,7 @@ impl From<Certificate> for CertificateRecord {
113113
parent_certificate_id,
114114
message: other.signed_message,
115115
signature,
116-
aggregate_verification_key: other.aggregate_verification_key,
116+
aggregate_verification_key: other.aggregate_verification_key.to_json_hex().unwrap(),
117117
epoch: other.beacon.epoch,
118118
beacon: other.beacon,
119119
protocol_version: other.metadata.protocol_version,
@@ -153,7 +153,7 @@ impl From<CertificateRecord> for Certificate {
153153
metadata: certificate_metadata,
154154
signed_message: other.protocol_message.compute_hash(),
155155
protocol_message: other.protocol_message,
156-
aggregate_verification_key: other.aggregate_verification_key,
156+
aggregate_verification_key: other.aggregate_verification_key.try_into().unwrap(),
157157
signature,
158158
}
159159
}

mithril-aggregator/src/message_adapters/to_certificate_list_message.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ impl ToMessageAdapter<Vec<Certificate>, CertificateListMessage>
2727
},
2828
protocol_message: certificate.protocol_message,
2929
signed_message: certificate.signed_message,
30-
aggregate_verification_key: certificate.aggregate_verification_key,
30+
aggregate_verification_key: certificate
31+
.aggregate_verification_key
32+
.to_json_hex()
33+
.unwrap(),
3134
})
3235
.collect()
3336
}
@@ -58,7 +61,10 @@ mod tests {
5861
},
5962
protocol_message: certificate.protocol_message,
6063
signed_message: certificate.signed_message,
61-
aggregate_verification_key: certificate.aggregate_verification_key,
64+
aggregate_verification_key: certificate
65+
.aggregate_verification_key
66+
.to_json_hex()
67+
.unwrap(),
6268
}];
6369

6470
assert_eq!(certificate_list_message_expected, certificate_list_message);

mithril-aggregator/src/message_adapters/to_certificate_message.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ impl ToMessageAdapter<Certificate, CertificateMessage> for ToCertificateMessageA
3434
metadata,
3535
protocol_message: certificate.protocol_message,
3636
signed_message: certificate.signed_message,
37-
aggregate_verification_key: certificate.aggregate_verification_key,
37+
aggregate_verification_key: certificate
38+
.aggregate_verification_key
39+
.to_json_hex()
40+
.unwrap(),
3841
multi_signature,
3942
genesis_signature,
4043
}

mithril-aggregator/src/multi_signer.rs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ use thiserror::Error;
55

66
use mithril_common::{
77
crypto_helper::{
8-
key_encode_hex, ProtocolAggregateVerificationKey, ProtocolAggregationError,
9-
ProtocolMultiSignature, ProtocolParameters, ProtocolRegistrationError,
10-
ProtocolStakeDistribution,
8+
ProtocolAggregateVerificationKey, ProtocolAggregationError, ProtocolMultiSignature,
9+
ProtocolParameters, ProtocolRegistrationError, ProtocolStakeDistribution,
1110
},
1211
entities::{self, Epoch, SignerWithStake, StakeDistribution},
1312
protocol::{MultiSigner as ProtocolMultiSigner, SignerBuilder},
@@ -38,10 +37,6 @@ pub enum ProtocolError {
3837
#[error("single signature already recorded")]
3938
ExistingSingleSignature(entities::PartyId),
4039

41-
/// Codec error.
42-
#[error("codec error: '{0}'")]
43-
Codec(String),
44-
4540
/// Mithril STM library returned an error.
4641
#[error("core error: '{0}'")]
4742
Core(String),
@@ -122,31 +117,29 @@ pub trait MultiSigner: Sync + Send {
122117
/// Compute stake distribution aggregate verification key
123118
async fn compute_stake_distribution_aggregate_verification_key(
124119
&self,
125-
) -> Result<String, ProtocolError> {
120+
) -> Result<ProtocolAggregateVerificationKey, ProtocolError> {
126121
let signers_with_stake = self.get_signers_with_stake().await?;
127122
let protocol_parameters = self
128123
.get_protocol_parameters()
129124
.await?
130125
.ok_or_else(ProtocolError::UnavailableProtocolParameters)?;
131-
let avk = self
126+
Ok(self
132127
.compute_aggregate_verification_key(&signers_with_stake, &protocol_parameters)
133-
.await?;
134-
Ok(key_encode_hex(avk).map_err(ProtocolError::Codec)?)
128+
.await?)
135129
}
136130

137131
/// Compute next stake distribution aggregate verification key
138132
async fn compute_next_stake_distribution_aggregate_verification_key(
139133
&self,
140-
) -> Result<String, ProtocolError> {
134+
) -> Result<ProtocolAggregateVerificationKey, ProtocolError> {
141135
let next_signers_with_stake = self.get_next_signers_with_stake().await?;
142136
let protocol_parameters = self
143137
.get_next_protocol_parameters()
144138
.await?
145139
.ok_or_else(ProtocolError::UnavailableProtocolParameters)?;
146-
let next_avk = self
140+
Ok(self
147141
.compute_aggregate_verification_key(&next_signers_with_stake, &protocol_parameters)
148-
.await?;
149-
Ok(key_encode_hex(next_avk).map_err(ProtocolError::Codec)?)
142+
.await?)
150143
}
151144

152145
/// Get signers

mithril-aggregator/src/runtime/runner.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use anyhow::Context;
12
use async_trait::async_trait;
23
use slog_scope::{debug, info, warn};
34
use std::{path::Path, path::PathBuf, sync::Arc};
@@ -369,7 +370,9 @@ impl AggregatorRunnerTrait for AggregatorRunner {
369370
ProtocolMessagePartKey::NextAggregateVerificationKey,
370371
multi_signer
371372
.compute_next_stake_distribution_aggregate_verification_key()
372-
.await?,
373+
.await?
374+
.to_json_hex()
375+
.with_context(|| "convert next avk to json hex failure")?,
373376
);
374377

375378
Ok(protocol_message)

mithril-aggregator/src/tools/certificates_hash_migrator.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -342,41 +342,41 @@ mod test {
342342
let expected = vec![
343343
(
344344
dummy_genesis(
345-
"b9263d7c2e94f6a62802b6521b30967e7e7a7fdccf02026dc70a0ffbc46da393",
345+
"98b44c52ac3c82adcbc5aea27a0c99cbba716048dddaf401b27acded80f1abcd",
346346
1,
347347
1,
348348
),
349349
None,
350350
),
351351
(
352352
dummy_certificate(
353-
"5d73905d314abc86451a399d4f1820201d4c20076d8fb0e4b277ffe5f5e4dc07",
354-
"b9263d7c2e94f6a62802b6521b30967e7e7a7fdccf02026dc70a0ffbc46da393",
353+
"0b7c12daffe63ca93a9cded424e300361a5234ab8c52b3e7029ff9dfbd8a16bd",
354+
"98b44c52ac3c82adcbc5aea27a0c99cbba716048dddaf401b27acded80f1abcd",
355355
1,
356356
2,
357357
),
358358
Some(SignedEntityRecord {
359359
signed_entity_id: "signed_entity_id".to_string(),
360360
signed_entity_type: MithrilStakeDistribution(Epoch(1)),
361361
certificate_id:
362-
"5d73905d314abc86451a399d4f1820201d4c20076d8fb0e4b277ffe5f5e4dc07"
362+
"0b7c12daffe63ca93a9cded424e300361a5234ab8c52b3e7029ff9dfbd8a16bd"
363363
.to_string(),
364364
artifact: "".to_string(),
365365
created_at: Default::default(),
366366
}),
367367
),
368368
(
369369
dummy_certificate(
370-
"583803ea5050f781de38c25d8773628ccf5c6fd737b4d984db2d41444bfdbf39",
371-
"5d73905d314abc86451a399d4f1820201d4c20076d8fb0e4b277ffe5f5e4dc07",
370+
"0aa74b928d3eade6548b22349435a12e9591f0c34c9ca2b0abfbeeefbb1acb37",
371+
"0b7c12daffe63ca93a9cded424e300361a5234ab8c52b3e7029ff9dfbd8a16bd",
372372
2,
373373
3,
374374
),
375375
Some(SignedEntityRecord {
376376
signed_entity_id: "signed_entity_id".to_string(),
377377
signed_entity_type: MithrilStakeDistribution(Epoch(2)),
378378
certificate_id:
379-
"583803ea5050f781de38c25d8773628ccf5c6fd737b4d984db2d41444bfdbf39"
379+
"0aa74b928d3eade6548b22349435a12e9591f0c34c9ca2b0abfbeeefbb1acb37"
380380
.to_string(),
381381
artifact: "".to_string(),
382382
created_at: Default::default(),

mithril-aggregator/src/tools/genesis.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use tokio::sync::RwLock;
55
use mithril_common::{
66
certificate_chain::{CertificateGenesisProducer, CertificateVerifier},
77
crypto_helper::{
8-
key_decode_hex, ProtocolAggregateVerificationKey, ProtocolGenesisSignature,
9-
ProtocolGenesisSigner, ProtocolGenesisVerifier,
8+
ProtocolAggregateVerificationKey, ProtocolGenesisSignature, ProtocolGenesisSigner,
9+
ProtocolGenesisVerifier,
1010
},
1111
entities::{Beacon, ProtocolParameters},
1212
BeaconProvider, StdResult,
@@ -82,8 +82,6 @@ impl GenesisTools {
8282
let genesis_avk = multi_signer
8383
.compute_next_stake_distribution_aggregate_verification_key()
8484
.await?;
85-
let genesis_avk: ProtocolAggregateVerificationKey = key_decode_hex(&genesis_avk)
86-
.map_err(|e| anyhow!(e).context("Aggregate verification key decode error"))?;
8785

8886
Ok(Self::new(
8987
protocol_parameters,
@@ -211,7 +209,7 @@ mod tests {
211209
let fixture = MithrilFixtureBuilder::default().with_signers(5).build();
212210
let first_signer = fixture.signers_fixture()[0].clone().protocol_signer;
213211
let clerk = ProtocolClerk::from_signer(&first_signer);
214-
clerk.compute_avk()
212+
clerk.compute_avk().into()
215213
}
216214

217215
fn build_tools(

mithril-aggregator/tests/test_extensions/runtime_tester.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ impl RuntimeTester {
416416
let expected_certificate = match signed_entity_record {
417417
None if certificate.is_genesis() => ExpectedCertificate::new_genesis(
418418
certificate.beacon,
419-
certificate.aggregate_verification_key,
419+
certificate.aggregate_verification_key.try_into().unwrap(),
420420
),
421421
None => {
422422
panic!("A certificate should always have a SignedEntity if it's not a genesis certificate");
@@ -429,7 +429,7 @@ impl RuntimeTester {
429429
ExpectedCertificate::new(
430430
certificate.beacon,
431431
&certificate.metadata.signers,
432-
certificate.aggregate_verification_key,
432+
certificate.aggregate_verification_key.try_into().unwrap(),
433433
record.signed_entity_type,
434434
previous_cert_identifier,
435435
)

0 commit comments

Comments
 (0)