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 13 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
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,20 @@
"typechain": "yarn evm:typechain",
"test": "yarn evm:test && yarn ciphernode:test",
"coverage": "yarn evm:coverage",
"ciphernode:launch": "cd packages/ciphernode && ./scripts/launch.sh",
ryardley marked this conversation as resolved.
Show resolved Hide resolved
"ciphernode:add": "cd packages/evm && yarn ciphernode:add",
"ciphernode:remove": "cd packages/evm && yarn ciphernode:remove",
ryardley marked this conversation as resolved.
Show resolved Hide resolved
"ciphernode:aggregator": "cd packages/ciphernode && ./scripts/aggregator.sh",
"ciphernode:test": "cd packages/ciphernode && cargo test",
"ciphernode:build": "cd packages/ciphernode && cargo build --release",
"evm:install": "cd packages/evm && yarn install",
"evm:node": "cd packages/evm && yarn hardhat node",
"evm:compile": "cd packages/evm && yarn compile",
"evm:lint": "cd packages/evm && yarn lint",
"evm:typechain": "cd packages/evm && yarn typechain",
"evm:test": "cd packages/evm && yarn test",
"evm:coverage": "cd packages/evm && yarn coverage",
"evm:committee:new": "cd packages/evm && yarn committee:new",
"preinstall": "yarn evm:install",
"evm:release": "cd packages/evm && yarn release"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/ciphernode/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
22 changes: 10 additions & 12 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,12 +81,10 @@ async fn on_ciphernode_selected(
data: Addr<Data>,
bus: Addr<EventBus>,
event: CiphernodeSelected,
address: Address,
address: String,
) -> Result<()> {
let CiphernodeSelected { e3_id, .. } = event;

println!("\n\nGENERATING KEY!\n\n");

// generate keyshare
let (sk, pubkey) = fhe.send(GenerateKeyshare {}).await??;

Expand Down Expand Up @@ -117,7 +114,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 +148,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 +161,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())
})
}
}
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.

Loading
Loading