Skip to content

Commit

Permalink
check signatures and certificates
Browse files Browse the repository at this point in the history
  • Loading branch information
lanvidr committed Mar 30, 2022
1 parent a7ab858 commit 726d9e7
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 5 deletions.
2 changes: 1 addition & 1 deletion sui_core/src/authority_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use sui_types::batch::UpdateItem;
use sui_types::{error::SuiError, messages::*, serialize::*};

static MAX_ERRORS: i32 = 10;
static BUFFER_SIZE: usize = 100;
pub(crate) static BUFFER_SIZE: usize = 100;

#[async_trait]
pub trait AuthorityAPI {
Expand Down
54 changes: 50 additions & 4 deletions sui_core/src/safe_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use crate::authority_client::AuthorityAPI;
use crate::authority_client::{AuthorityAPI, BUFFER_SIZE};
use async_trait::async_trait;
use futures::channel::mpsc::Receiver;
use futures::channel::mpsc::{channel, Receiver};
use std::io;
use futures::{SinkExt, StreamExt};
use sui_types::crypto::PublicKeyBytes;
use sui_types::{base_types::*, committee::*, fp_ensure};

use sui_types::batch::UpdateItem;
use sui_types::{
error::{SuiError, SuiResult},
messages::*,
Expand Down Expand Up @@ -264,8 +266,52 @@ where
/// Handle Batch information requests for this authority.
async fn handle_batch_streaming(
&self,
_request: BatchInfoRequest,
request: BatchInfoRequest,
) -> Result<Receiver<Result<BatchInfoResponseItem, SuiError>>, io::Error> {
todo!()
let (mut tx_output, tr_output) = channel(BUFFER_SIZE);

let mut batch_info_items = self
.authority_client
.handle_batch_streaming(request)
.await?;

for next_data in batch_info_items.next().await {
match next_data {
Ok(batch_info_response_item) => {
// do security checks
match batch_info_response_item.clone() {
BatchInfoResponseItem(UpdateItem::Batch(signed_batch)) => {
// check signature of batch
let result = signed_batch.signature.check(&signed_batch.signature, signed_batch.authority);
match result {
Ok(_) => {
let _ = tx_output.send(Ok(batch_info_response_item)).await;
},
Err(e) => {
let _ = tx_output.send(Err(e)).await;
},
}
}
BatchInfoResponseItem(UpdateItem::Transaction((_seq, digest))) => {
// make transaction info request which checks transaction certificate
let transaction_info_request = TransactionInfoRequest{ transaction_digest: digest };
let transaction_info_response = self.handle_transaction_info_request(transaction_info_request).await;
match transaction_info_response {
Ok(_) => {
let _ = tx_output.send(Ok(batch_info_response_item)).await;
},
Err(e) => {
let _ = tx_output.send(Err(e)).await;
},
}
}
}
}
Err(_) => {
continue;
}
}
}
Ok(tr_output)
}
}
2 changes: 2 additions & 0 deletions sui_types/src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,8 @@ impl Signature {

pub struct AuthoritySignature(pub dalek::Signature);

impl BcsSignable for AuthoritySignature {}

impl AsRef<[u8]> for AuthoritySignature {
fn as_ref(&self) -> &[u8] {
self.0.as_ref()
Expand Down

0 comments on commit 726d9e7

Please sign in to comment.