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

feat: add sov-modules-wallet-blueprint #1179

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 17 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ members = [
"module-system/sov-cli",
"module-system/sov-modules-stf-blueprint",
"module-system/sov-modules-rollup-blueprint",
"module-system/sov-modules-wallet-blueprint",
"module-system/sov-modules-macros",
"module-system/sov-modules-core",
"module-system/sov-state",
Expand Down
1 change: 1 addition & 0 deletions examples/demo-rollup/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ sov-rollup-interface = { path = "../../rollup-interface", features = ["native"]

sov-modules-rollup-blueprint = { path = "../../module-system/sov-modules-rollup-blueprint" }
sov-modules-stf-blueprint = { path = "../../module-system/sov-modules-stf-blueprint", features = ["native"] }
sov-modules-wallet-blueprint = { path = "../../module-system/sov-modules-wallet-blueprint", features = ["cli"] }
sov-modules-api = { path = "../../module-system/sov-modules-api", features = ["native"] }
sov-nft-module = { path = "../../module-system/module-implementations/sov-nft-module" }
demo-stf = { path = "./stf", features = ["native"] }
Expand Down
5 changes: 3 additions & 2 deletions examples/demo-rollup/src/celestia_rollup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ use sov_celestia_adapter::verifier::{CelestiaSpec, CelestiaVerifier, RollupParam
use sov_celestia_adapter::{CelestiaConfig, CelestiaService};
use sov_modules_api::default_context::{DefaultContext, ZkDefaultContext};
use sov_modules_api::Spec;
use sov_modules_rollup_blueprint::{RollupBlueprint, WalletBlueprint};
use sov_modules_rollup_blueprint::RollupBlueprint;
use sov_modules_stf_blueprint::kernels::basic::BasicKernel;
use sov_modules_stf_blueprint::StfBlueprint;
use sov_modules_wallet_blueprint::cli::CliWalletBlueprint;
use sov_risc0_adapter::host::Risc0Host;
use sov_rollup_interface::zk::ZkvmHost;
use sov_state::storage_manager::ProverStorageManager;
Expand Down Expand Up @@ -114,4 +115,4 @@ impl RollupBlueprint for CelestiaDemoRollup {
}
}

impl WalletBlueprint for CelestiaDemoRollup {}
impl CliWalletBlueprint for CelestiaDemoRollup {}
2 changes: 1 addition & 1 deletion examples/demo-rollup/src/sov-cli/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use demo_stf::runtime::RuntimeSubcommand;
use sov_demo_rollup::CelestiaDemoRollup;
use sov_modules_api::cli::{FileNameArg, JsonStringArg};
use sov_modules_rollup_blueprint::WalletBlueprint;
use sov_modules_wallet_blueprint::cli::CliWalletBlueprint;

#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
Expand Down
2 changes: 0 additions & 2 deletions module-system/sov-modules-rollup-blueprint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#![doc = include_str!("../README.md")]

mod runtime_rpc;
mod wallet;
use std::net::SocketAddr;

use async_trait::async_trait;
Expand All @@ -18,7 +17,6 @@ use sov_state::storage::NativeStorage;
use sov_state::Storage;
use sov_stf_runner::{ProverService, RollupConfig, RollupProverConfig, StateTransitionRunner};
use tokio::sync::oneshot;
pub use wallet::*;

/// This trait defines how to crate all the necessary dependencies required by a rollup.
#[async_trait]
Expand Down
43 changes: 43 additions & 0 deletions module-system/sov-modules-wallet-blueprint/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[package]
name = "sov-modules-wallet-blueprint"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need a new crate? Can we just put the snap-wallet in sov-modules-rollup-blueprint so everything is in one place?

Copy link
Contributor Author

@vlopes11 vlopes11 Nov 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would bring more feature complexity to sov-modules-rollup-blueprint as I need to differentiate when we generate for the CLI (so we use things like clap as dependency), and for the WASM (that is as minimal as possible to keep the binary size small)

If we put it under sov-modules-rollup-blueprint, we will have to shield anything non-wallet behind feature flags

description = "Defines the interface of the Sovereign SDK wallet"
authors = { workspace = true }
edition = { workspace = true }
homepage = { workspace = true }
license = { workspace = true }
repository = { workspace = true }

version = { workspace = true }
readme = "README.md"
resolver = "2"

[dependencies]
anyhow = { workspace = true, optional = true }
async-trait = { workspace = true, optional = true }
borsh = { workspace = true, optional = true }
serde = { workspace = true, optional = true }
serde_json = { workspace = true, optional = true }
sov-cli = { path = "../sov-cli", optional = true }
sov-mock-da = { path = "../../adapters/mock-da", version = "0.3", optional = true }
sov-modules-api = { path = "../sov-modules-api", version = "0.3" }
sov-modules-rollup-blueprint = { path = "../sov-modules-rollup-blueprint", optional = true }
sov-rollup-interface = { path = "../../rollup-interface", version = "0.3" }

[features]
default = ["cli", "default-impl"]
cli = [
"anyhow",
"async-trait",
"borsh",
"native",
"serde",
"serde_json",
"sov-cli",
"sov-modules-rollup-blueprint",
]
default-impl = ["sov-mock-da"]
native = [
"sov-mock-da?/native",
"sov-modules-api/native",
"sov-rollup-interface/native",
]
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
use core::convert::Infallible;
use std::{fs, io};

use async_trait::async_trait;
use borsh::BorshSerialize;
use serde::de::DeserializeOwned;
use serde::Serialize;
use sov_cli::clap::{self, Parser, Subcommand};
use sov_cli::wallet_dir;
use sov_cli::wallet_state::WalletState;
use sov_cli::workflows::keys::KeyWorkflow;
use sov_cli::workflows::rpc::RpcWorkflows;
use sov_cli::workflows::transactions::TransactionWorkflow;
use sov_cli::{clap, wallet_dir};
use sov_modules_api::clap::Parser;
use sov_modules_api::cli::{CliFrontEnd, JsonStringArg};
use sov_modules_api::{CliWallet, Context, DispatchCall};
use sov_modules_rollup_blueprint::RollupBlueprint;

use crate::RollupBlueprint;

#[derive(clap::Subcommand)]
#[derive(Subcommand)]
#[command(author, version, about, long_about = None)]
enum Workflows<File: clap::Subcommand, Json: clap::Subcommand, C: Context> {
enum Workflows<File: Subcommand, Json: Subcommand, C: Context> {
#[clap(subcommand)]
Transactions(TransactionWorkflow<File, Json>),
#[clap(subcommand)]
Expand All @@ -22,53 +26,51 @@ enum Workflows<File: clap::Subcommand, Json: clap::Subcommand, C: Context> {
Rpc(RpcWorkflows<C>),
}

#[derive(clap::Parser)]
#[derive(Parser)]
#[command(author, version, about = None, long_about = None)]
struct CliApp<File: clap::Subcommand, Json: clap::Subcommand, C: Context> {
struct CliApp<File: Subcommand, Json: Subcommand, C: Context> {
#[clap(subcommand)]
workflow: Workflows<File, Json, C>,
}

/// Generic wallet for any type that implements RollupBlueprint.
#[async_trait]
pub trait WalletBlueprint: RollupBlueprint
pub trait CliWalletBlueprint: RollupBlueprint
where
// The types here a quite complicated but they are never exposed to the user
// as the WalletTemplate is implemented for any types that implements RollupBlueprint.
<Self as RollupBlueprint>::NativeContext:
serde::Serialize + serde::de::DeserializeOwned + Send + Sync,
<Self as RollupBlueprint>::NativeContext: Serialize + DeserializeOwned + Send + Sync,

<Self as RollupBlueprint>::NativeRuntime: CliWallet,

<Self as RollupBlueprint>::DaSpec: serde::Serialize + serde::de::DeserializeOwned,
<Self as RollupBlueprint>::DaSpec: Serialize + DeserializeOwned,

<<Self as RollupBlueprint>::NativeRuntime as DispatchCall>::Decodable:
serde::Serialize + serde::de::DeserializeOwned + BorshSerialize + Send + Sync,
Serialize + DeserializeOwned + BorshSerialize + Send + Sync,

<<Self as RollupBlueprint>::NativeRuntime as CliWallet>::CliStringRepr<JsonStringArg>: TryInto<
<<Self as RollupBlueprint>::NativeRuntime as DispatchCall>::Decodable,
Error = serde_json::Error,
>,
{
/// Generates wallet cli for the runtime.
async fn run_wallet<File: clap::Subcommand, Json: clap::Subcommand>(
) -> Result<(), anyhow::Error>
async fn run_wallet<File: Subcommand, Json: Subcommand>() -> Result<(), anyhow::Error>
where
File: CliFrontEnd<<Self as RollupBlueprint>::NativeRuntime> + Send + Sync,
Json: CliFrontEnd<<Self as RollupBlueprint>::NativeRuntime> + Send + Sync,

File: TryInto<
<<Self as RollupBlueprint>::NativeRuntime as CliWallet>::CliStringRepr<JsonStringArg>,
Error = std::io::Error,
Error = io::Error,
>,
Json: TryInto<
<<Self as RollupBlueprint>::NativeRuntime as CliWallet>::CliStringRepr<JsonStringArg>,
Error = std::convert::Infallible,
Error = Infallible,
>,
{
let app_dir = wallet_dir()?;

std::fs::create_dir_all(app_dir.as_ref())?;
fs::create_dir_all(app_dir.as_ref())?;
let wallet_state_path = app_dir.as_ref().join("wallet_state.json");

let mut wallet_state: WalletState<
Expand Down
29 changes: 29 additions & 0 deletions module-system/sov-modules-wallet-blueprint/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use sov_modules_api::Context;
use sov_rollup_interface::da::DaSpec;

#[cfg(feature = "cli")]
pub mod cli;

/// Blueprint definition for a module wallet.
///
/// The associated types of this trait are expected to be implemented concretely as binary
/// endpoints depends on resolved generics in order to compile properly.
///
/// The `DefaultWalletBlueprint` contains concrete types for the default implementations on
/// `sov-modules-api`. It lives behind a feature flag 'default-impl'.
pub trait WalletBlueprint {
/// Context used to define the asymetric cryptography for keys generation and signing.
type Context: Context;
/// DA specification used to declare runtime call message of the module, that is signed by the
/// wallet.
type DaSpec: DaSpec;
}

#[cfg(feature = "default-impl")]
pub struct DefaultWalletBlueprint;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't need this. If we move the code to sov-modules-rollup-blueprint like suggested in another comment we will just implemnt the WalletBlueprint for CelestiaDemoRollup & MockDemoRollup the same way as it was done for CliWallet.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The goal of this struct is to make a (Context, DaSpec) available for crates outside our demos. Meaning: if we create a new runtime that is not the one of celestia or mock, we can use DefaultWalletBlueprint to generate the WASM module with ed25519 keys.

If we implement WalletBlueprint for celestia/mock, we will be able to generate WASM only for these runtimes


#[cfg(feature = "default-impl")]
impl WalletBlueprint for DefaultWalletBlueprint {
type Context = sov_modules_api::default_context::ZkDefaultContext;
type DaSpec = sov_mock_da::MockDaSpec;
}
1 change: 1 addition & 0 deletions packages_to_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- sov-modules-stf-blueprint
- sov-stf-runner
- sov-modules-rollup-blueprint
- sov-modules-wallet-blueprint
- sov-ledger-rpc

# Modules
Expand Down
Loading