Skip to content

Commit

Permalink
Feat/weight copy tests (#212)
Browse files Browse the repository at this point in the history
* feat: adding `YumaParams` struct

* chore: renamed

* mock wip

* test wip

* feat: fixed macro logic

* fix: tests

* wip

* wip

* adding liquid alpha

* test: wip

* feat: updating copying irrationality calculation

* removing fucking python from flake

* chore: renaming storages

* updating cargos.tomls

* wip

* chore: removing unused files

* wip: research tests

* chore: commenting out testing tests

* chore: removing snapshot

* feat: impl offworker encryption

---------

Co-authored-by: devwckd <dev.wckd@gmail.com>
  • Loading branch information
functor-flow and devwckd committed Oct 10, 2024
1 parent 63898fc commit 72af72c
Show file tree
Hide file tree
Showing 31 changed files with 1,517 additions and 229 deletions.
13 changes: 7 additions & 6 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@
"**/.hg/store/**": true,
"**/.repos": true
},
"rust-analyzer.cargo.extraEnv": {
"SKIP_WASM_BUILD": 1
},
"rust-analyzer.server.extraEnv": {
"SKIP_WASM_BUILD": 1
}
}
"SKIP_WASM_BUILD": "1",
"RUST_BACKTRACE": "0"
},
"rust-analyzer.procMacro.enable": true,
"rust-analyzer.cargo.buildScripts.enable": true,
"rust-analyzer.cargo.features": [],
}
92 changes: 91 additions & 1 deletion Cargo.lock

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

9 changes: 7 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ members = [
"pallets/subspace",
"pallets/subspace/genesis-config",
"runtime",
"xtask",
"tests",
"testthing",
"xtask",
]
resolver = "2"

Expand All @@ -32,6 +32,7 @@ match_bool = "deny"
infinite_loop = "deny"

[workspace.dependencies]
rsa = "0.9.4"
# External dependencies
bty = { version = "0.2.0", default-features = false }
env_logger = "0.11.3"
Expand All @@ -40,7 +41,11 @@ clap = "4.4.6"
hex = "0.4.3"
jsonrpsee = "0.22.2"
log = { version = "0.4.21", default-features = false }
tokio = "1.17.0"
parity-util-mem = "0.11.0"
rand = "0.8"
scale-info = { version = "2.10.0", default-features = false, features = [
"derive",
] }
serde = { version = "1.0.145", default-features = false, features = ["derive"] }
serde_json = { version = "1.0.108", default-features = false, features = [
"alloc",
Expand Down
4 changes: 3 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
};
rust = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;

generalBuildInputs = with pkgs; [ pkg-config rocksdb zstd.dev bashInteractive ];
generalBuildInputs = with pkgs; [ pkg-config rocksdb zstd.dev bashInteractive openssl.dev ];
buildInputs = with pkgs;
if pkgs.stdenv.isLinux
then generalBuildInputs ++ [ jemalloc ]
Expand All @@ -38,6 +38,8 @@
LIBCLANG_PATH = "${pkgs.libclang.lib}/lib";
ROCKSDB_LIB_DIR = "${pkgs.rocksdb}/lib";
ZSTD_SYS_USE_PKG_CONFIG = "true";
OPENSSL_DIR = "${pkgs.openssl.dev}";
OPENSSL_LIB_DIR = "${pkgs.openssl.out}/lib";
} // nixpkgs.lib.optionalAttrs pkgs.stdenv.isLinux { JEMALLOC_OVERRIDE = "${pkgs.jemalloc}/lib/libjemalloc.so"; };
};

Expand Down
1 change: 1 addition & 0 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ name = "node-subspace"
clap = { workspace = true, features = ["derive"] }
futures = { workspace = true, features = ["thread-pool"] }
hex.workspace = true
rsa.workspace = true
serde.workspace = true

serde_json.workspace = true
Expand Down
27 changes: 19 additions & 8 deletions node/src/manual_seal_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
use futures::FutureExt;
use node_subspace_runtime::{self, opaque::Block, RuntimeApi};
use rsa::{rand_core::OsRng, traits::PublicKeyParts, Pkcs1v15Encrypt};
use sc_client_api::Backend;
use sc_consensus_manual_seal::consensus::{
aura::AuraConsensusDataProvider, timestamp::SlotTimestampProvider,
Expand Down Expand Up @@ -234,20 +235,30 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
Ok(task_manager)
}

#[derive(Default)]
struct Decrypter {
// TODO: swap this with the node's decryption key type and store it once it starts
decryption_key: (),
key: rsa::RsaPrivateKey,
}

impl Default for Decrypter {
fn default() -> Self {
Self {
key: rsa::RsaPrivateKey::new(&mut OsRng, 128).unwrap(),
}
}
}

impl testthing::OffworkerExtension for Decrypter {
fn decrypt_weight(&self, _encrypted: Vec<u8>) -> Vec<u8> {
// TODO: weight decryption goes here
todo!()
fn decrypt_weight(&self, encrypted: Vec<u8>) -> Option<Vec<u8>> {
self.key.decrypt(Pkcs1v15Encrypt, &encrypted).ok()
}
fn encrypt_weight(&self, decrypted: Vec<u8>) -> Option<Vec<u8>> {
let encryption_key = rsa::RsaPublicKey::from(&self.key);
encryption_key.encrypt(&mut OsRng, Pkcs1v15Encrypt, &decrypted[..]).ok()
}

fn get_encryption_key(&self) -> Vec<u8> {
// TODO: return a encryption key derived from our decryption key, or always return the same
todo!()
fn get_encryption_key(&self) -> (Vec<u8>, Vec<u8>) {
let public = rsa::RsaPublicKey::from(&self.key);
(public.n().to_bytes_be(), public.e().to_bytes_le())
}
}
23 changes: 13 additions & 10 deletions pallets/faucet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,28 @@ std = [
try-runtime = ["frame-support/try-runtime"]

[dependencies]
log.workspace = true
bty = { workspace = true }

pallet-subspace = { path = "../subspace", default-features = false }

frame-support.workspace = true
frame-system.workspace = true
frame-support = { workspace = true }
frame-system = { workspace = true }
log = { workspace = true }

sp-runtime.workspace = true
sp-std.workspace = true
sp-core.workspace = true
pallet-subspace = { path = "../subspace", default-features = false }

parity-scale-codec = { workspace = true, default-features = false, features = [
"derive",
] }
scale-info = { workspace = true, default-features = false, features = [
"derive",
] }
sp-core = { workspace = true }

sp-runtime = { workspace = true }
sp-std = { workspace = true }

substrate-fixed = { workspace = true }

[dev-dependencies]
pallet-balances = { workspace = true, features = ["std"] }
sp-io.workspace = true
sp-tracing.workspace = true
sp-io = { workspace = true }
sp-tracing = { workspace = true }
Loading

0 comments on commit 72af72c

Please sign in to comment.