Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1fe4f3621e | |||
| b5739c7308 | |||
| 60518f2f2b | |||
| aaec36addc | |||
| 592d6de8e6 | |||
| cf4746dbf1 | |||
| 75837d73c2 |
Generated
+392
-393
File diff suppressed because it is too large
Load Diff
@@ -30,7 +30,9 @@ nym-topology = { path = "../topology" }
|
|||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
nym-mixnet-contract-common = { path = "../cosmwasm-smart-contracts/mixnet-contract" }
|
nym-mixnet-contract-common = { path = "../cosmwasm-smart-contracts/mixnet-contract" }
|
||||||
nym-crypto = { path = "../crypto", version = "0.4.0", features = ["asymmetric"] }
|
nym-crypto = { path = "../crypto", version = "0.4.0", features = [
|
||||||
|
"asymmetric",
|
||||||
|
] }
|
||||||
|
|
||||||
# do not include this when compiling into wasm as it somehow when combined together with reqwest, it will require
|
# do not include this when compiling into wasm as it somehow when combined together with reqwest, it will require
|
||||||
# net2 via tokio-util -> tokio -> mio -> net2
|
# net2 via tokio-util -> tokio -> mio -> net2
|
||||||
@@ -43,5 +45,13 @@ features = ["sync"]
|
|||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["sphinx"]
|
default = ["sphinx"]
|
||||||
sphinx = ["nym-crypto/sphinx", "nym-sphinx-params/sphinx", "nym-sphinx-types/sphinx"]
|
sphinx = [
|
||||||
outfox = ["nym-crypto/outfox", "nym-sphinx-params/outfox", "nym-sphinx-types/outfox"]
|
"nym-crypto/sphinx",
|
||||||
|
"nym-sphinx-params/sphinx",
|
||||||
|
"nym-sphinx-types/sphinx",
|
||||||
|
]
|
||||||
|
outfox = [
|
||||||
|
"nym-crypto/outfox",
|
||||||
|
"nym-sphinx-params/outfox",
|
||||||
|
"nym-sphinx-types/outfox",
|
||||||
|
]
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ pub mod packet_version;
|
|||||||
|
|
||||||
// If somebody can provide an argument why it might be reasonable to have more than 255 mix hops,
|
// If somebody can provide an argument why it might be reasonable to have more than 255 mix hops,
|
||||||
// I will change this to [`usize`]
|
// I will change this to [`usize`]
|
||||||
pub const DEFAULT_NUM_MIX_HOPS: u8 = 3;
|
pub const DEFAULT_NUM_MIX_HOPS: u8 = 0;
|
||||||
|
|
||||||
// TODO: not entirely sure how to feel about those being defined here, ideally it'd be where [`Fragment`]
|
// TODO: not entirely sure how to feel about those being defined here, ideally it'd be where [`Fragment`]
|
||||||
// is defined, but that'd introduce circular dependencies as the acknowledgements crate also needs
|
// is defined, but that'd introduce circular dependencies as the acknowledgements crate also needs
|
||||||
|
|||||||
@@ -8,9 +8,11 @@ license = { workspace = true }
|
|||||||
repository = { workspace = true }
|
repository = { workspace = true }
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
sphinx-packet = { version = "0.1.0", optional = true }
|
# sphinx-packet = { version = "0.1.0", optional = true }
|
||||||
|
sphinx-packet = { git = "https://github.com/nymtech/sphinx.git", branch="feature/clone-surb", optional = true }
|
||||||
nym-outfox = { path = "../../../nym-outfox", optional = true }
|
nym-outfox = { path = "../../../nym-outfox", optional = true }
|
||||||
thiserror = { workspace = true }
|
thiserror = { workspace = true }
|
||||||
|
once_cell = "1.18"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["sphinx"]
|
default = ["sphinx"]
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ pub use nym_outfox::{
|
|||||||
// re-exporting types and constants available in sphinx
|
// re-exporting types and constants available in sphinx
|
||||||
#[cfg(feature = "outfox")]
|
#[cfg(feature = "outfox")]
|
||||||
use nym_outfox::packet::{OutfoxPacket, OutfoxProcessedPacket};
|
use nym_outfox::packet::{OutfoxPacket, OutfoxProcessedPacket};
|
||||||
|
|
||||||
|
use once_cell::sync::OnceCell;
|
||||||
#[cfg(feature = "sphinx")]
|
#[cfg(feature = "sphinx")]
|
||||||
pub use sphinx_packet::{
|
pub use sphinx_packet::{
|
||||||
constants::{
|
constants::{
|
||||||
@@ -28,6 +30,9 @@ use sphinx_packet::{SphinxPacket, SphinxPacketBuilder};
|
|||||||
use std::{array::TryFromSliceError, fmt};
|
use std::{array::TryFromSliceError, fmt};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
|
static REUSABLE_SURB: OnceCell<SURB> = OnceCell::new();
|
||||||
|
static REUSABLE_HEADER: OnceCell<ProcessedHeader> = OnceCell::new();
|
||||||
|
|
||||||
#[derive(Error, Debug)]
|
#[derive(Error, Debug)]
|
||||||
pub enum NymPacketError {
|
pub enum NymPacketError {
|
||||||
#[error("Sphinx error: {0}")]
|
#[error("Sphinx error: {0}")]
|
||||||
@@ -77,6 +82,30 @@ impl fmt::Debug for NymPacket {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl NymPacket {
|
impl NymPacket {
|
||||||
|
#[cfg(feature = "sphinx")]
|
||||||
|
pub fn from_surb<M: AsRef<[u8]>>(
|
||||||
|
size: usize,
|
||||||
|
message: M,
|
||||||
|
route: &[Node],
|
||||||
|
destination: &Destination,
|
||||||
|
delays: &[Delay],
|
||||||
|
) -> Result<NymPacket, NymPacketError> {
|
||||||
|
let (packet, _address) = if let Some(surb) = REUSABLE_SURB.get() {
|
||||||
|
let new_surb = surb.clone();
|
||||||
|
new_surb.use_surb(message.as_ref(), size)?
|
||||||
|
} else {
|
||||||
|
let surb_material =
|
||||||
|
SURBMaterial::new(route.to_vec(), vec![Delay::new_from_millis(0)], destination.to_owned());
|
||||||
|
let surb = SURB::new(EphemeralSecret::new(), surb_material)?;
|
||||||
|
REUSABLE_SURB
|
||||||
|
.set(surb.clone())
|
||||||
|
.expect("ReusableSURB was already set!");
|
||||||
|
surb.use_surb(message.as_ref(), size)?
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(NymPacket::Sphinx(packet))
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "sphinx")]
|
#[cfg(feature = "sphinx")]
|
||||||
pub fn sphinx_build<M: AsRef<[u8]>>(
|
pub fn sphinx_build<M: AsRef<[u8]>>(
|
||||||
size: usize,
|
size: usize,
|
||||||
@@ -85,11 +114,12 @@ impl NymPacket {
|
|||||||
destination: &Destination,
|
destination: &Destination,
|
||||||
delays: &[Delay],
|
delays: &[Delay],
|
||||||
) -> Result<NymPacket, NymPacketError> {
|
) -> Result<NymPacket, NymPacketError> {
|
||||||
Ok(NymPacket::Sphinx(
|
NymPacket::from_surb(size, message, route, destination, delays)
|
||||||
SphinxPacketBuilder::new()
|
// Ok(NymPacket::Sphinx(
|
||||||
.with_payload_size(size)
|
// SphinxPacketBuilder::new()
|
||||||
.build_packet(message, route, destination, delays)?,
|
// .with_payload_size(size)
|
||||||
))
|
// .build_packet(message, route, destination, delays)?,
|
||||||
|
// ))
|
||||||
}
|
}
|
||||||
#[cfg(feature = "sphinx")]
|
#[cfg(feature = "sphinx")]
|
||||||
pub fn sphinx_from_bytes(bytes: &[u8]) -> Result<NymPacket, NymPacketError> {
|
pub fn sphinx_from_bytes(bytes: &[u8]) -> Result<NymPacket, NymPacketError> {
|
||||||
@@ -149,7 +179,43 @@ impl NymPacket {
|
|||||||
) -> Result<NymProcessedPacket, NymPacketError> {
|
) -> Result<NymProcessedPacket, NymPacketError> {
|
||||||
match self {
|
match self {
|
||||||
NymPacket::Sphinx(packet) => {
|
NymPacket::Sphinx(packet) => {
|
||||||
Ok(NymProcessedPacket::Sphinx(packet.process(node_secret_key)?))
|
let unwrapped_header: ProcessedHeader = if let Some(header) = REUSABLE_HEADER.get() {
|
||||||
|
header.clone()
|
||||||
|
} else {
|
||||||
|
let header = packet.header.process(node_secret_key)?;
|
||||||
|
let _ = REUSABLE_HEADER.set(header.clone());
|
||||||
|
header
|
||||||
|
};
|
||||||
|
|
||||||
|
let processed_packet = match unwrapped_header {
|
||||||
|
ProcessedHeader::ForwardHop(
|
||||||
|
new_header,
|
||||||
|
next_hop_address,
|
||||||
|
delay,
|
||||||
|
payload_key,
|
||||||
|
) => {
|
||||||
|
let new_payload = packet.payload.unwrap(&payload_key)?;
|
||||||
|
let new_packet = SphinxPacket {
|
||||||
|
header: *new_header,
|
||||||
|
payload: new_payload,
|
||||||
|
};
|
||||||
|
ProcessedPacket::ForwardHop(
|
||||||
|
Box::new(new_packet),
|
||||||
|
next_hop_address,
|
||||||
|
delay,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
ProcessedHeader::FinalHop(destination, identifier, payload_key) => {
|
||||||
|
let new_payload = packet.payload.unwrap(&payload_key)?;
|
||||||
|
ProcessedPacket::FinalHop(
|
||||||
|
destination,
|
||||||
|
identifier,
|
||||||
|
new_payload,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(NymProcessedPacket::Sphinx(processed_packet))
|
||||||
}
|
}
|
||||||
#[cfg(feature = "outfox")]
|
#[cfg(feature = "outfox")]
|
||||||
NymPacket::Outfox(mut packet) => {
|
NymPacket::Outfox(mut packet) => {
|
||||||
|
|||||||
@@ -34,6 +34,9 @@ impl PacketProcessor {
|
|||||||
&self,
|
&self,
|
||||||
received: FramedNymPacket,
|
received: FramedNymPacket,
|
||||||
) -> Result<ProcessedFinalHop, GatewayProcessingError> {
|
) -> Result<ProcessedFinalHop, GatewayProcessingError> {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
match self.inner_processor.process_received(received)? {
|
match self.inner_processor.process_received(received)? {
|
||||||
MixProcessingResult::ForwardHop(..) => {
|
MixProcessingResult::ForwardHop(..) => {
|
||||||
Err(GatewayProcessingError::ForwardHopReceivedError)
|
Err(GatewayProcessingError::ForwardHopReceivedError)
|
||||||
|
|||||||
@@ -18,7 +18,8 @@ curve25519-dalek = "3.2"
|
|||||||
chacha20poly1305 = "0.10.1"
|
chacha20poly1305 = "0.10.1"
|
||||||
getrandom = { workspace = true, features = ["js"] }
|
getrandom = { workspace = true, features = ["js"] }
|
||||||
thiserror = { workspace = true }
|
thiserror = { workspace = true }
|
||||||
sphinx-packet = "0.1.0"
|
# sphinx-packet = "0.1.0"
|
||||||
|
sphinx-packet = { git = "https://github.com/nymtech/sphinx.git", branch="feature/clone-surb" }
|
||||||
rand = "0.7.3"
|
rand = "0.7.3"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user