Skip to content

Commit

Permalink
Ensure only publish if src chain matches
Browse files Browse the repository at this point in the history
  • Loading branch information
ryardley committed Oct 8, 2024
1 parent f7ea669 commit 1153cef
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
7 changes: 6 additions & 1 deletion packages/ciphernode/evm/src/enclave_sol_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,12 @@ impl Handler<EnclaveEvent> for EnclaveSolWriter {
type Result = ();
fn handle(&mut self, msg: EnclaveEvent, ctx: &mut Self::Context) -> Self::Result {
match msg {
EnclaveEvent::PlaintextAggregated { data, .. } => ctx.notify(data),
EnclaveEvent::PlaintextAggregated { data, .. } => {
// Only publish if the src and destination chains match
if self.provider.get_chain_id() == data.src_chain_id {
ctx.notify(data);
}
}
_ => (),
}
}
Expand Down
7 changes: 6 additions & 1 deletion packages/ciphernode/evm/src/registry_filter_sol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ impl Handler<EnclaveEvent> for RegistryFilterSolWriter {
type Result = ();
fn handle(&mut self, msg: EnclaveEvent, ctx: &mut Self::Context) -> Self::Result {
match msg {
EnclaveEvent::PublicKeyAggregated { data, .. } => ctx.notify(data),
EnclaveEvent::PublicKeyAggregated { data, .. } => {
// Only publish if the src and destination chains match
if self.provider.get_chain_id() == data.src_chain_id {
ctx.notify(data);
}
}
_ => (),
}
}
Expand Down
13 changes: 10 additions & 3 deletions packages/ciphernode/tests/tests/test_aggregation_and_decryption.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ async fn test_public_key_aggregation_and_decryption() -> Result<()> {
threshold_m: 3,
seed: seed.clone(),
params: params.to_bytes(),
src_chain_id: 1,
});
// Send the computation requested event
bus.send(event.clone()).await?;
Expand Down Expand Up @@ -153,7 +154,8 @@ async fn test_public_key_aggregation_and_decryption() -> Result<()> {
e3_id: e3_id.clone(),
threshold_m: 3,
seed: seed.clone(),
params: params.to_bytes()
params: params.to_bytes(),
src_chain_id: 1
}),
EnclaveEvent::from(CiphernodeSelected {
e3_id: e3_id.clone(),
Expand All @@ -177,7 +179,8 @@ async fn test_public_key_aggregation_and_decryption() -> Result<()> {
EnclaveEvent::from(PublicKeyAggregated {
pubkey: pubkey.to_bytes(),
e3_id: e3_id.clone(),
nodes: OrderedSet::from(eth_addrs.clone())
nodes: OrderedSet::from(eth_addrs.clone()),
src_chain_id: 1
})
]
);
Expand Down Expand Up @@ -243,7 +246,8 @@ async fn test_public_key_aggregation_and_decryption() -> Result<()> {
}),
EnclaveEvent::from(PlaintextAggregated {
e3_id: e3_id.clone(),
decrypted_output: expected_raw_plaintext.clone()
decrypted_output: expected_raw_plaintext.clone(),
src_chain_id: 1
})
]
);
Expand Down Expand Up @@ -277,11 +281,13 @@ async fn test_p2p_actor_forwards_events_to_network() -> Result<()> {
let evt_1 = EnclaveEvent::from(PlaintextAggregated {
e3_id: E3id::new("1235"),
decrypted_output: vec![1, 2, 3, 4],
src_chain_id: 1,
});

let evt_2 = EnclaveEvent::from(PlaintextAggregated {
e3_id: E3id::new("1236"),
decrypted_output: vec![1, 2, 3, 4],
src_chain_id: 1,
});

let local_evt_3 = EnclaveEvent::from(CiphernodeSelected {
Expand Down Expand Up @@ -330,6 +336,7 @@ async fn test_p2p_actor_forwards_events_to_bus() -> Result<()> {
threshold_m: 3,
seed: seed.clone(),
params: vec![1, 2, 3, 4],
src_chain_id: 1,
});

// lets send an event from the network
Expand Down

0 comments on commit 1153cef

Please sign in to comment.