Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Evm Integration and integration script #107

Merged
merged 38 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
84c4346
Array -> [u8;20]
ryardley Sep 23, 2024
d9f6774
Merge branch 'ry/evm_event_massage-remove_address' into connect_evm
ryardley Sep 23, 2024
7e95860
[u8;20] -> String
ryardley Sep 23, 2024
8a8ecad
Setup evm events
ryardley Sep 23, 2024
e9d0d7a
Remove Committee Requested event
ryardley Sep 23, 2024
54d60ff
Setup evm events E3Requested and CiphernodeAdded
ryardley Sep 23, 2024
2475c63
Supply events to listen with
ryardley Sep 23, 2024
6e0874f
Use shortcut
ryardley Sep 23, 2024
abe4c7d
Update for e2e test
ryardley Sep 24, 2024
1af271a
e2e test sharing keys and saving
ryardley Sep 24, 2024
54de815
Update formatting
ryardley Sep 24, 2024
4699adc
Public Key Writer Working
ryardley Sep 24, 2024
9509146
Write pubkey to screen and file
ryardley Sep 24, 2024
082c3a4
attempt to load pubkey
ryardley Sep 24, 2024
64d44c6
Merge branch 'main' into connect_evm
ryardley Sep 24, 2024
dbfa41b
Update script
ryardley Sep 24, 2024
1551323
tworks
ryardley Sep 24, 2024
b4524de
Remove console
ryardley Sep 24, 2024
21efe3f
script tweaks, deploy tweak for testing
samepant Sep 24, 2024
d76a882
Tidy up test script
ryardley Sep 25, 2024
f9662b1
Add to CI
ryardley Sep 25, 2024
b07b1b9
Use rust 1.81
ryardley Sep 25, 2024
ae0da9c
Ensure bash
ryardley Sep 25, 2024
30d1b37
Remove frozen
ryardley Sep 25, 2024
896f187
Use --data-file over --data
ryardley Sep 26, 2024
e1237ff
Merge branch 'main' into connect_evm
ryardley Sep 26, 2024
8845ded
formatting
ryardley Sep 26, 2024
077049a
Rename file
ryardley Sep 26, 2024
f94252b
Apply code rabbit suggestions
ryardley Sep 26, 2024
a08755d
exit if not run from root
ryardley Sep 26, 2024
d80957d
Add waiton and decrease the use of sleep
ryardley Sep 26, 2024
d1b13a4
Tidy up cleanup trap in bash file
ryardley Sep 26, 2024
b205e6d
Remove cd inline in script
ryardley Sep 26, 2024
8bceba9
Add timeout to wait on
ryardley Sep 26, 2024
7a67578
Make timeout 10 min
ryardley Sep 26, 2024
f5ccc4f
Use version 2 rust toolchain
ryardley Sep 26, 2024
d0b7580
Revert bad suggestion from coderabbit
ryardley Sep 26, 2024
a8217cd
Architecture fixes (#114)
ryardley Sep 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions packages/ciphernode/core/src/ciphernode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,26 @@ use crate::{
DecryptionshareCreated, Get,
};
use actix::prelude::*;
use alloy_primitives::Address;
use anyhow::Result;

pub struct Ciphernode {
fhe: Addr<Fhe>,
data: Addr<Data>,
bus: Addr<EventBus>,
address: Address,
address: String,
}

impl Actor for Ciphernode {
type Context = Context<Self>;
}

impl Ciphernode {
pub fn new(bus: Addr<EventBus>, fhe: Addr<Fhe>, data: Addr<Data>, address: Address) -> Self {
pub fn new(bus: Addr<EventBus>, fhe: Addr<Fhe>, data: Addr<Data>, address: &str) -> Self {
Self {
bus,
fhe,
data,
address,
address:address.to_string(),
}
}
}
Expand All @@ -51,7 +50,7 @@ impl Handler<CiphernodeSelected> for Ciphernode {
let fhe = self.fhe.clone();
let data = self.data.clone();
let bus = self.bus.clone();
let address = self.address;
let address = self.address.clone();
Box::pin(async move {
on_ciphernode_selected(fhe, data, bus, event, address)
.await
Expand All @@ -68,7 +67,7 @@ impl Handler<CiphertextOutputPublished> for Ciphernode {
let fhe = self.fhe.clone();
let data = self.data.clone();
let bus = self.bus.clone();
let address = self.address;
let address = self.address.clone();
Box::pin(async move {
on_decryption_requested(fhe, data, bus, event, address)
.await
Expand All @@ -82,7 +81,7 @@ async fn on_ciphernode_selected(
data: Addr<Data>,
bus: Addr<EventBus>,
event: CiphernodeSelected,
address: Address,
address: String,
) -> Result<()> {
let CiphernodeSelected { e3_id, .. } = event;

Expand Down Expand Up @@ -117,7 +116,7 @@ async fn on_decryption_requested(
data: Addr<Data>,
bus: Addr<EventBus>,
event: CiphertextOutputPublished,
address: Address,
address: String,
) -> Result<()> {
let CiphertextOutputPublished {
e3_id,
Expand Down Expand Up @@ -151,7 +150,8 @@ async fn on_decryption_requested(

pub struct CiphernodeFactory;
impl CiphernodeFactory {
pub fn create(bus: Addr<EventBus>, data: Addr<Data>, address: Address) -> ActorFactory {
pub fn create(bus: Addr<EventBus>, data: Addr<Data>, address: &str) -> ActorFactory {
let address = address.to_string();
Box::new(move |ctx, evt| {
// Save Ciphernode on CiphernodeSelected
let EnclaveEvent::CiphernodeSelected { .. } = evt else {
Expand All @@ -163,7 +163,7 @@ impl CiphernodeFactory {
};

ctx.ciphernode =
Some(Ciphernode::new(bus.clone(), fhe.clone(), data.clone(), address).start())
Some(Ciphernode::new(bus.clone(), fhe.clone(), data.clone(), &address).start())
})
}
}
21 changes: 10 additions & 11 deletions packages/ciphernode/core/src/ciphernode_selector.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use actix::prelude::*;
use alloy_primitives::Address;

use crate::{
CiphernodeSelected, EnclaveEvent, EventBus, GetHasNode, Sortition, Subscribe,
Expand All @@ -8,27 +7,27 @@ use crate::{
pub struct CiphernodeSelector {
bus: Addr<EventBus>,
sortition: Addr<Sortition>,
address: Address,
address: String,
}

impl Actor for CiphernodeSelector {
type Context = Context<Self>;
}

impl CiphernodeSelector {
pub fn new(bus: Addr<EventBus>, sortition: Addr<Sortition>, address: Address) -> Self {
pub fn new(bus: Addr<EventBus>, sortition: Addr<Sortition>, address: &str) -> Self {
Self {
bus,
sortition,
address,
address:address.to_owned(),
}
}

pub fn attach(bus: Addr<EventBus>, sortition: Addr<Sortition>, address: Address) -> Addr<Self> {
pub fn attach(bus: Addr<EventBus>, sortition: Addr<Sortition>, address: &str) -> Addr<Self> {
let addr = CiphernodeSelector::new(bus.clone(), sortition, address).start();

bus.do_send(Subscribe::new(
"CommitteeRequested",
"E3Requested",
addr.clone().recipient(),
));

Expand All @@ -40,17 +39,17 @@ impl Handler<EnclaveEvent> for CiphernodeSelector {
type Result = ResponseFuture<()>;

fn handle(&mut self, event: EnclaveEvent, _ctx: &mut Self::Context) -> Self::Result {
let address = self.address;
let address = self.address.clone();
let sortition = self.sortition.clone();
let bus = self.bus.clone();

Box::pin(async move {
let EnclaveEvent::CommitteeRequested { data, .. } = event else {
let EnclaveEvent::E3Requested { data, .. } = event else {
return;
};

let seed = data.sortition_seed;
let size = data.nodecount;
let seed = data.seed;
let size = data.threshold_m as usize;

if let Ok(is_selected) = sortition
.send(GetHasNode {
Expand All @@ -66,7 +65,7 @@ impl Handler<EnclaveEvent> for CiphernodeSelector {

bus.do_send(EnclaveEvent::from(CiphernodeSelected {
e3_id: data.e3_id,
nodecount: data.nodecount,
threshold_m: data.threshold_m,
}));
}
})
Expand Down
14 changes: 7 additions & 7 deletions packages/ciphernode/core/src/committee_meta.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::{ActorFactory, CommitteeRequested, EnclaveEvent};
use crate::{ActorFactory, E3Requested, EnclaveEvent};

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct CommitteeMeta {
pub nodecount: usize,
pub threshold_m: u32,
pub seed: u64,
}

Expand All @@ -11,16 +11,16 @@ pub struct CommitteeMetaFactory;
impl CommitteeMetaFactory {
pub fn create() -> ActorFactory {
Box::new(move |ctx, evt| {
let EnclaveEvent::CommitteeRequested { data, .. }: crate::EnclaveEvent = evt else {
let EnclaveEvent::E3Requested { data, .. }: crate::EnclaveEvent = evt else {
return;
};
let CommitteeRequested {
nodecount,
sortition_seed: seed,
let E3Requested {
threshold_m,
seed,
..
} = data;

ctx.meta = Some(CommitteeMeta { nodecount, seed });
ctx.meta = Some(CommitteeMeta { threshold_m, seed });
})
}
}
10 changes: 1 addition & 9 deletions packages/ciphernode/core/src/e3_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,11 @@ pub struct E3RequestContext {
pub publickey: Option<Addr<PublicKeyAggregator>>,
pub meta: Option<CommitteeMeta>,
}

#[derive(Default)]
struct EventBuffer {
buffer: HashMap<String, Vec<EnclaveEvent>>,
}

impl Default for EventBuffer {
fn default() -> Self {
Self {
buffer: HashMap::new(),
}
}
}

impl EventBuffer {
pub fn add(&mut self, key: &str, event: EnclaveEvent) {
self.buffer.entry(key.to_string()).or_default().push(event)
Expand Down
13 changes: 0 additions & 13 deletions packages/ciphernode/core/src/enclave_contract.rs

This file was deleted.

48 changes: 22 additions & 26 deletions packages/ciphernode/core/src/events.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
use actix::Message;
use alloy_primitives::Address;
use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha256};
use std::{
fmt,
hash::{DefaultHasher, Hash, Hasher},
};

#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct EthAddr(pub Vec<u8>);

impl From<Address> for EthAddr {
fn from(value: Address) -> Self {
Self(value.to_vec())
}
}

#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct E3id(pub String);
impl fmt::Display for E3id {
Expand All @@ -36,6 +26,12 @@ impl From<u32> for E3id {
}
}

impl From<String> for E3id {
fn from(value: String) -> Self {
E3id::new(value)
}
}
ryardley marked this conversation as resolved.
Show resolved Hide resolved

#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct EventId(pub [u8; 32]);

Expand Down Expand Up @@ -64,9 +60,9 @@ pub enum EnclaveEvent {
id: EventId,
data: KeyshareCreated,
},
CommitteeRequested {
E3Requested {
id: EventId,
data: CommitteeRequested,
data: E3Requested,
},
PublicKeyAggregated {
id: EventId,
Expand Down Expand Up @@ -128,7 +124,7 @@ impl From<EnclaveEvent> for EventId {
fn from(value: EnclaveEvent) -> Self {
match value {
EnclaveEvent::KeyshareCreated { id, .. } => id,
EnclaveEvent::CommitteeRequested { id, .. } => id,
EnclaveEvent::E3Requested { id, .. } => id,
EnclaveEvent::PublicKeyAggregated { id, .. } => id,
EnclaveEvent::CiphertextOutputPublished { id, .. } => id,
EnclaveEvent::DecryptionshareCreated { id, .. } => id,
Expand All @@ -144,7 +140,7 @@ impl EnclaveEvent {
pub fn get_e3_id(&self) -> Option<E3id> {
match self.clone() {
EnclaveEvent::KeyshareCreated { data, .. } => Some(data.e3_id),
EnclaveEvent::CommitteeRequested { data, .. } => Some(data.e3_id),
EnclaveEvent::E3Requested { data, .. } => Some(data.e3_id),
EnclaveEvent::PublicKeyAggregated { data, .. } => Some(data.e3_id),
EnclaveEvent::CiphertextOutputPublished { data, .. } => Some(data.e3_id),
EnclaveEvent::DecryptionshareCreated { data, .. } => Some(data.e3_id),
Expand All @@ -164,9 +160,9 @@ impl From<KeyshareCreated> for EnclaveEvent {
}
}

impl From<CommitteeRequested> for EnclaveEvent {
fn from(data: CommitteeRequested) -> Self {
EnclaveEvent::CommitteeRequested {
impl From<E3Requested> for EnclaveEvent {
fn from(data: E3Requested) -> Self {
EnclaveEvent::E3Requested {
id: EventId::from(data.clone()),
data: data.clone(),
}
Expand Down Expand Up @@ -246,15 +242,15 @@ impl fmt::Display for EnclaveEvent {
pub struct KeyshareCreated {
pub pubkey: Vec<u8>,
pub e3_id: E3id,
pub node: Address,
pub node: String,
}

#[derive(Message, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[rtype(result = "anyhow::Result<()>")]
pub struct DecryptionshareCreated {
pub decryption_share: Vec<u8>,
pub e3_id: E3id,
pub node: Address,
pub node: String,
}

#[derive(Message, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
Expand All @@ -266,10 +262,10 @@ pub struct PublicKeyAggregated {

#[derive(Message, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[rtype(result = "()")]
pub struct CommitteeRequested {
pub struct E3Requested {
pub e3_id: E3id,
pub nodecount: usize,
pub sortition_seed: u64, // Should actually be much larger eg [u8;32]
pub threshold_m: u32,
pub seed: u64, // Should actually be much larger eg [u8;32]

// fhe params
pub moduli: Vec<u64>,
Expand All @@ -287,7 +283,7 @@ pub struct CommitteeRequested {
#[rtype(result = "()")]
pub struct CiphernodeSelected {
pub e3_id: E3id,
pub nodecount: usize,
pub threshold_m: u32,
}

#[derive(Message, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
Expand All @@ -307,15 +303,15 @@ pub struct PlaintextAggregated {
#[derive(Message, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[rtype(result = "()")]
pub struct CiphernodeAdded {
pub address: Address,
pub address: String,
pub index: usize,
pub num_nodes: usize,
}

#[derive(Message, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[rtype(result = "()")]
pub struct CiphernodeRemoved {
pub address: Address,
pub address: String,
pub index: usize,
pub num_nodes: usize,
}
Expand Down Expand Up @@ -383,7 +379,7 @@ mod tests {
let kse = EnclaveEvent::from(KeyshareCreated {
e3_id: E3id::from(1001),
pubkey,
node: address!("d8dA6BF26964aF9D7eEd9e03E53415D37aA96045"),
node: address!("d8dA6BF26964aF9D7eEd9e03E53415D37aA96045").to_string(),
});
let kse_bytes = kse.to_bytes()?;
let _ = EnclaveEvent::from_bytes(&kse_bytes.clone());
Expand Down
Loading
Loading