Skip to content

Commit 92c2e4f

Browse files
committed
additional fixes
1 parent cce5a7f commit 92c2e4f

File tree

11 files changed

+42
-30
lines changed

11 files changed

+42
-30
lines changed

crates/attestation/src/report_data.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
use alloc::vec;
12
use borsh::{BorshDeserialize, BorshSerialize};
23
use derive_more::Constructor;
34
use near_sdk::PublicKey;
45
use serde::{Deserialize, Serialize};
56
use sha3::{Digest, Sha3_384};
6-
use alloc::vec;
77

88
/// Number of bytes for the report data.
99
const REPORT_DATA_SIZE: usize = 64;
@@ -108,10 +108,11 @@ pub enum ReportData {
108108
}
109109

110110
impl ReportData {
111-
pub fn new(tls_public_key: PublicKey, account_public_key: Option<PublicKey>) -> Self {
111+
pub fn new(tls_public_key: PublicKey, account_public_key: Option<PublicKey>) -> Self {
112112
let account_pk = account_public_key.unwrap_or_else(|| {
113-
//TODO (#823) Construct a "zero" public key. will not be used in practice, only for backward compatibility. remove this code once that network enforces real attestation
114-
PublicKey::from_parts(near_sdk::CurveType::ED25519, vec![0u8; 32]).expect("valid zero PublicKey")
113+
//TODO (#823) Construct a "zero" public key. will not be used in practice, only for backward compatibility. remove this code once that network enforces real attestation
114+
PublicKey::from_parts(near_sdk::CurveType::ED25519, vec![0u8; 32])
115+
.expect("valid zero PublicKey")
115116
});
116117

117118
ReportData::V1(ReportDataV1::new(tls_public_key, account_pk))

crates/attestation/tests/test_attestation_verification.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use mpc_primitives::hash::{LauncherDockerComposeHash, MpcDockerImageHash};
66
use near_sdk::PublicKey;
77
use rstest::rstest;
88
use test_utils::attestation::{
9-
image_digest, launcher_compose_digest, mock_dstack_attestation, p2p_tls_key, account_key,
9+
account_key, image_digest, launcher_compose_digest, mock_dstack_attestation, p2p_tls_key,
1010
};
1111

1212
#[rstest]
@@ -23,7 +23,7 @@ fn test_mock_attestation_verify(
2323
let account_key = "ed25519:5v8Y8ZLoxZzCVtYpjh1cYdFrRh1p9EXAMPLEaQJ5sP4o"
2424
.parse()
2525
.unwrap();
26-
let report_data = ReportData::V1(ReportDataV1::new(tls_key,account_key));
26+
let report_data = ReportData::V1(ReportDataV1::new(tls_key, account_key));
2727
let attestation = Attestation::Mock(local_attestation);
2828

2929
assert_eq!(
@@ -38,7 +38,7 @@ fn test_verify_method_signature() {
3838
let tls_key: PublicKey = p2p_tls_key();
3939
let account_key: PublicKey = account_key();
4040

41-
let report_data = ReportData::V1(ReportDataV1::new(tls_key,account_key));
41+
let report_data = ReportData::V1(ReportDataV1::new(tls_key, account_key));
4242
let timestamp_s = 1755186041_u64;
4343

4444
let allowed_mpc_image_digest: MpcDockerImageHash = image_digest();

crates/contract/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ impl MpcContract {
518518
pub fn respond_ckd(&mut self, request: CKDRequest, response: CKDResponse) -> Result<(), Error> {
519519
let signer = env::signer_account_id();
520520
log!("respond_ckd: signer={}, request={:?}", &signer, &request);
521-
521+
522522
self.tee_state.assert_caller_is_attested_node();
523523

524524
if !self.protocol_state.is_running_or_resharing() {
@@ -720,7 +720,7 @@ impl MpcContract {
720720
#[handle_result]
721721
pub fn start_keygen_instance(&mut self, key_event_id: KeyEventId) -> Result<(), Error> {
722722
log!("start_keygen_instance: signer={}", env::signer_account_id(),);
723-
723+
724724
self.tee_state.assert_caller_is_attested_node();
725725

726726
self.protocol_state
@@ -754,7 +754,7 @@ impl MpcContract {
754754
key_event_id,
755755
public_key,
756756
);
757-
757+
758758
self.tee_state.assert_caller_is_attested_node();
759759

760760
let extended_key =
@@ -779,7 +779,7 @@ impl MpcContract {
779779
"start_reshare_instance: signer={}",
780780
env::signer_account_id()
781781
);
782-
782+
783783
self.tee_state.assert_caller_is_attested_node();
784784
self.protocol_state
785785
.start_reshare_instance(key_event_id, self.config.key_event_timeout_blocks)
@@ -805,7 +805,7 @@ impl MpcContract {
805805
env::signer_account_id(),
806806
key_event_id,
807807
);
808-
808+
809809
self.tee_state.assert_caller_is_attested_node();
810810
let resharing_concluded =
811811
if let Some(new_state) = self.protocol_state.vote_reshared(key_event_id)? {
@@ -883,7 +883,7 @@ impl MpcContract {
883883
"vote_abort_key_event_instance: signer={}",
884884
env::signer_account_id()
885885
);
886-
886+
887887
self.tee_state.assert_caller_is_attested_node();
888888
self.protocol_state
889889
.vote_abort_key_event_instance(key_event_id)

crates/contract/src/primitives/participants.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,9 @@ impl Participants {
203203
self.participants.remove(pos);
204204
}
205205
}
206-
206+
/// Returns the set of NodeIds corresponding to the participants.
207+
/// Note that the account_public_key field in NodeId is None.
208+
/// This is because NodeId is used in contexts where account_public_key is not needed.
207209
pub fn get_node_ids(&self) -> BTreeSet<NodeId> {
208210
self.participants()
209211
.iter()

crates/contract/src/state/key_event.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ impl KeyEvent {
105105
.as_mut()
106106
.unwrap()
107107
.vote_success(candidate, public_key)?
108-
{
108+
{
109109
VoteSuccessResult::Voted(count) => {
110110
if count == self.parameters.participants().len() {
111111
Ok(true)

crates/contract/src/tee/tee_state.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl TeeState {
9696
let node_id = NodeId {
9797
account_id: account_id.clone(),
9898
tls_public_key: participant_info.sign_pk.clone(),
99-
account_public_key: None,
99+
account_public_key: None,
100100
};
101101

102102
participants_attestations
@@ -285,7 +285,7 @@ impl TeeState {
285285
.map(|(account_id, _, p_info)| NodeId {
286286
account_id: account_id.clone(),
287287
tls_public_key: p_info.sign_pk.clone(),
288-
account_public_key: None,
288+
account_public_key: None, //mapping to NodeId without account_public_key.
289289
})
290290
.collect();
291291

crates/contract/tests/inprocess/expired_attestation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ fn test_participant_kickout_after_expiration() {
183183
let third_node = NodeId {
184184
account_id: setup.participants_list[2].0.clone(),
185185
tls_public_key: setup.participants_list[2].2.sign_pk.clone(),
186-
account_public_key: Some(bogus_ed25519_near_public_key()),
186+
account_public_key: Some(bogus_ed25519_near_public_key()),
187187
};
188188

189189
setup.submit_attestation_for_node(&third_node, expiring_attestation);

crates/node/src/cli.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,15 @@ impl StartCmd {
238238
let secrets =
239239
SecretsConfig::from_parts(&self.secret_store_key_hex, persistent_secrets.clone())?;
240240

241-
242241
// Generate attestation
243242
let tee_authority = TeeAuthority::try_from(self.tee_authority.clone())?;
244243
let tls_public_key = &secrets.persistent_secrets.p2p_private_key.verifying_key();
245-
let account_public_key = &secrets.persistent_secrets.near_signer_key.verifying_key();
246-
247-
let report_data = ReportData::new(tls_public_key.clone().to_near_sdk_public_key()?,
248-
Some(account_public_key.clone().to_near_sdk_public_key()?));
244+
let account_public_key = &secrets.persistent_secrets.near_signer_key.verifying_key();
245+
246+
let report_data = ReportData::new(
247+
tls_public_key.clone().to_near_sdk_public_key()?,
248+
Some(account_public_key.clone().to_near_sdk_public_key()?),
249+
);
249250
let attestation = tee_authority.generate_attestation(report_data).await?;
250251

251252
// Create communication channels and runtime
@@ -394,9 +395,13 @@ impl StartCmd {
394395
// Spawn periodic attestation submission task
395396
let tx_sender_clone = indexer_api.txn_sender.clone();
396397
tokio::spawn(async move {
397-
if let Err(e) =
398-
periodic_attestation_submission(tee_authority, tx_sender_clone, tls_public_key,account_public_key)
399-
.await
398+
if let Err(e) = periodic_attestation_submission(
399+
tee_authority,
400+
tx_sender_clone,
401+
tls_public_key,
402+
account_public_key,
403+
)
404+
.await
400405
{
401406
tracing::error!(
402407
error = ?e,

crates/node/src/indexer/fake.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,6 @@ pub fn participant_info_from_config(info: &config::ParticipantInfo) -> Participa
256256
ParticipantInfo {
257257
sign_pk: info.p2p_public_key.to_near_sdk_public_key().unwrap(),
258258
url: format!("http://{}:{}", info.address, info.port),
259-
260259
}
261260
}
262261

crates/node/src/tee/remote_attestation.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,10 @@ async fn periodic_attestation_submission_with_interval<T: TransactionSender + Cl
117117
let tls_sdk_public_key = tls_public_key.to_near_sdk_public_key()?;
118118
let account_sdk_public_key = account_public_key.to_near_sdk_public_key()?;
119119

120-
let report_data = ReportData::new(tls_sdk_public_key.clone(),Some(account_sdk_public_key.clone()));
120+
let report_data = ReportData::new(
121+
tls_sdk_public_key.clone(),
122+
Some(account_sdk_public_key.clone()),
123+
);
121124
let fresh_attestation = match tee_authority.generate_attestation(report_data).await {
122125
Ok(attestation) => attestation,
123126
Err(error) => {
@@ -223,10 +226,13 @@ mod tests {
223226
let mut rng = rand::rngs::StdRng::seed_from_u64(42);
224227
let key = SigningKey::generate(&mut rng).verifying_key();
225228

229+
let account_key = SigningKey::generate(&mut rng).verifying_key();
230+
226231
let handle = tokio::spawn(periodic_attestation_submission_with_interval(
227232
tee_authority,
228233
sender.clone(),
229234
key,
235+
account_key,
230236
MockTicker::new(TEST_SUBMISSION_COUNT),
231237
));
232238

0 commit comments

Comments
 (0)