mirror of
https://github.com/logos-blockchain/lssa.git
synced 2026-01-05 06:43:08 +00:00
fix: methods added
This commit is contained in:
parent
fc01f00272
commit
7845af0fc8
125
Cargo.lock
generated
125
Cargo.lock
generated
@ -2709,6 +2709,7 @@ dependencies = [
|
||||
"serde",
|
||||
"serde_json",
|
||||
"storage",
|
||||
"tokio",
|
||||
"utxo",
|
||||
"vm",
|
||||
"zkvm",
|
||||
@ -3541,21 +3542,6 @@ dependencies = [
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "risc0-binfmt"
|
||||
version = "1.1.3"
|
||||
source = "git+https://github.com/risc0/risc0.git?branch=release-1.1#20df1afbcdd2ca442ece8c3fecd25a20cc0aafb5"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"borsh",
|
||||
"elf",
|
||||
"risc0-zkp 1.1.3",
|
||||
"risc0-zkvm-platform 1.1.3",
|
||||
"serde",
|
||||
"syn 2.0.87",
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "risc0-binfmt"
|
||||
version = "1.2.0"
|
||||
@ -3564,30 +3550,12 @@ dependencies = [
|
||||
"anyhow",
|
||||
"borsh",
|
||||
"elf",
|
||||
"risc0-zkp 1.2.0",
|
||||
"risc0-zkvm-platform 1.2.0",
|
||||
"risc0-zkp",
|
||||
"risc0-zkvm-platform",
|
||||
"serde",
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "risc0-build"
|
||||
version = "1.1.3"
|
||||
source = "git+https://github.com/risc0/risc0.git?branch=release-1.1#20df1afbcdd2ca442ece8c3fecd25a20cc0aafb5"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"cargo_metadata",
|
||||
"dirs",
|
||||
"docker-generate",
|
||||
"hex",
|
||||
"risc0-binfmt 1.1.3",
|
||||
"risc0-zkp 1.1.3",
|
||||
"risc0-zkvm-platform 1.1.3",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tempfile",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "risc0-build"
|
||||
version = "1.2.0"
|
||||
@ -3598,9 +3566,9 @@ dependencies = [
|
||||
"dirs",
|
||||
"docker-generate",
|
||||
"hex",
|
||||
"risc0-binfmt 1.2.0",
|
||||
"risc0-zkp 1.2.0",
|
||||
"risc0-zkvm-platform 1.2.0",
|
||||
"risc0-binfmt",
|
||||
"risc0-zkp",
|
||||
"risc0-zkvm-platform",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tempfile",
|
||||
@ -3637,9 +3605,9 @@ dependencies = [
|
||||
"rand 0.8.5",
|
||||
"rayon",
|
||||
"risc0-circuit-recursion-sys",
|
||||
"risc0-core 1.2.0",
|
||||
"risc0-core",
|
||||
"risc0-sys",
|
||||
"risc0-zkp 1.2.0",
|
||||
"risc0-zkp",
|
||||
"serde",
|
||||
"sha2 0.10.8",
|
||||
"tracing",
|
||||
@ -3653,7 +3621,7 @@ source = "git+https://github.com/risc0/risc0.git?branch=release-1.2#baf81cdbab10
|
||||
dependencies = [
|
||||
"glob",
|
||||
"risc0-build-kernel",
|
||||
"risc0-core 1.2.0",
|
||||
"risc0-core",
|
||||
"risc0-sys",
|
||||
"sppark",
|
||||
]
|
||||
@ -3679,12 +3647,12 @@ dependencies = [
|
||||
"num-traits",
|
||||
"rand 0.8.5",
|
||||
"rayon",
|
||||
"risc0-binfmt 1.2.0",
|
||||
"risc0-binfmt",
|
||||
"risc0-circuit-rv32im-sys",
|
||||
"risc0-core 1.2.0",
|
||||
"risc0-core",
|
||||
"risc0-sys",
|
||||
"risc0-zkp 1.2.0",
|
||||
"risc0-zkvm-platform 1.2.0",
|
||||
"risc0-zkp",
|
||||
"risc0-zkvm-platform",
|
||||
"serde",
|
||||
"sha2 0.10.8",
|
||||
"tracing",
|
||||
@ -3697,20 +3665,11 @@ source = "git+https://github.com/risc0/risc0.git?branch=release-1.2#baf81cdbab10
|
||||
dependencies = [
|
||||
"glob",
|
||||
"risc0-build-kernel",
|
||||
"risc0-core 1.2.0",
|
||||
"risc0-core",
|
||||
"risc0-sys",
|
||||
"sppark",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "risc0-core"
|
||||
version = "1.1.3"
|
||||
source = "git+https://github.com/risc0/risc0.git?branch=release-1.1#20df1afbcdd2ca442ece8c3fecd25a20cc0aafb5"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"rand_core 0.6.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "risc0-core"
|
||||
version = "1.2.0"
|
||||
@ -3736,9 +3695,9 @@ dependencies = [
|
||||
"hex",
|
||||
"num-bigint 0.4.6",
|
||||
"num-traits",
|
||||
"risc0-binfmt 1.2.0",
|
||||
"risc0-core 1.2.0",
|
||||
"risc0-zkp 1.2.0",
|
||||
"risc0-binfmt",
|
||||
"risc0-core",
|
||||
"risc0-zkp",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"stability",
|
||||
@ -3758,29 +3717,6 @@ dependencies = [
|
||||
"sppark",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "risc0-zkp"
|
||||
version = "1.1.3"
|
||||
source = "git+https://github.com/risc0/risc0.git?branch=release-1.1#20df1afbcdd2ca442ece8c3fecd25a20cc0aafb5"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"blake2",
|
||||
"borsh",
|
||||
"bytemuck",
|
||||
"cfg-if 1.0.0",
|
||||
"digest 0.10.7",
|
||||
"hex",
|
||||
"hex-literal",
|
||||
"metal",
|
||||
"paste 1.0.15",
|
||||
"rand_core 0.6.4",
|
||||
"risc0-core 1.1.3",
|
||||
"risc0-zkvm-platform 1.1.3",
|
||||
"serde",
|
||||
"sha2 0.10.8",
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "risc0-zkp"
|
||||
version = "1.2.0"
|
||||
@ -3803,9 +3739,9 @@ dependencies = [
|
||||
"rand 0.8.5",
|
||||
"rand_core 0.6.4",
|
||||
"rayon",
|
||||
"risc0-core 1.2.0",
|
||||
"risc0-core",
|
||||
"risc0-sys",
|
||||
"risc0-zkvm-platform 1.2.0",
|
||||
"risc0-zkvm-platform",
|
||||
"serde",
|
||||
"sha2 0.10.8",
|
||||
"tracing",
|
||||
@ -3832,14 +3768,14 @@ dependencies = [
|
||||
"prost",
|
||||
"rand 0.8.5",
|
||||
"rayon",
|
||||
"risc0-binfmt 1.2.0",
|
||||
"risc0-build 1.2.0",
|
||||
"risc0-binfmt",
|
||||
"risc0-build",
|
||||
"risc0-circuit-recursion",
|
||||
"risc0-circuit-rv32im",
|
||||
"risc0-core 1.2.0",
|
||||
"risc0-core",
|
||||
"risc0-groth16",
|
||||
"risc0-zkp 1.2.0",
|
||||
"risc0-zkvm-platform 1.2.0",
|
||||
"risc0-zkp",
|
||||
"risc0-zkvm-platform",
|
||||
"rrs-lib",
|
||||
"rustc-demangle",
|
||||
"semver",
|
||||
@ -3852,14 +3788,6 @@ dependencies = [
|
||||
"typetag",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "risc0-zkvm-platform"
|
||||
version = "1.1.3"
|
||||
source = "git+https://github.com/risc0/risc0.git?branch=release-1.1#20df1afbcdd2ca442ece8c3fecd25a20cc0aafb5"
|
||||
dependencies = [
|
||||
"stability",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "risc0-zkvm-platform"
|
||||
version = "1.2.0"
|
||||
@ -4542,7 +4470,7 @@ dependencies = [
|
||||
name = "test-methods"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"risc0-build 1.1.3",
|
||||
"risc0-build",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -5466,13 +5394,16 @@ dependencies = [
|
||||
name = "zkvm"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"accounts",
|
||||
"anyhow",
|
||||
"env_logger",
|
||||
"log",
|
||||
"risc0-zkvm",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"storage",
|
||||
"test-methods",
|
||||
"utxo",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
@ -21,11 +21,12 @@ pub struct NodeCore {
|
||||
pub main_acc: Account,
|
||||
pub node_config: NodeConfig,
|
||||
pub db_updater_handle: JoinHandle<Result<()>>,
|
||||
pub sequencer_client: Arc<SequencerClient>,
|
||||
}
|
||||
|
||||
impl NodeCore {
|
||||
pub async fn start_from_config_update_chain(config: NodeConfig) -> Result<Self> {
|
||||
let client = SequencerClient::new(config.clone())?;
|
||||
let client = Arc::new(SequencerClient::new(config.clone())?);
|
||||
|
||||
let genesis_id = client.get_genesis_id().await?;
|
||||
let genesis_block = client.get_block(genesis_id.genesis_id).await?.block;
|
||||
@ -83,6 +84,7 @@ impl NodeCore {
|
||||
main_acc: account,
|
||||
node_config: config.clone(),
|
||||
db_updater_handle: updater_handle,
|
||||
sequencer_client: client.clone(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,9 +6,13 @@ use anyhow::Result;
|
||||
use block_store::NodeBlockStore;
|
||||
use storage::{
|
||||
block::Block,
|
||||
merkle_tree_public::merkle_tree::{PublicTransactionMerkleTree, UTXOCommitmentsMerkleTree},
|
||||
merkle_tree_public::{
|
||||
merkle_tree::{PublicTransactionMerkleTree, UTXOCommitmentsMerkleTree},
|
||||
TreeHashType,
|
||||
},
|
||||
nullifier::UTXONullifier,
|
||||
nullifier_sparse_merkle_tree::NullifierSparseMerkleTree,
|
||||
transaction::Transaction,
|
||||
utxo_commitment::UTXOCommitment,
|
||||
};
|
||||
|
||||
@ -78,4 +82,13 @@ impl NodeChainStore {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn calculate_transaction_execution(
|
||||
&mut self,
|
||||
_acc_addr: AccountAddress,
|
||||
_contract_addr: TreeHashType,
|
||||
_call_data: Vec<u8>,
|
||||
) -> Transaction {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,6 +12,7 @@ serde.workspace = true
|
||||
actix.workspace = true
|
||||
actix-cors.workspace = true
|
||||
futures.workspace = true
|
||||
tokio.workspace = true
|
||||
|
||||
actix-web.workspace = true
|
||||
|
||||
|
||||
@ -2,6 +2,9 @@ pub mod net_utils;
|
||||
pub mod process;
|
||||
pub mod types;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use node_core::{config::NodeConfig, NodeCore};
|
||||
use rpc_primitives::{
|
||||
errors::{RpcError, RpcErrorKind},
|
||||
RpcPollingConfig,
|
||||
@ -10,12 +13,15 @@ use serde::Serialize;
|
||||
use serde_json::Value;
|
||||
|
||||
pub use net_utils::*;
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
use self::types::err_rpc::RpcErr;
|
||||
|
||||
//ToDo: Add necessary fields
|
||||
pub struct JsonHandler {
|
||||
pub polling_config: RpcPollingConfig,
|
||||
pub node_core_config: NodeConfig,
|
||||
pub node_chain_store: Arc<Mutex<NodeCore>>,
|
||||
}
|
||||
|
||||
fn respond<T: Serialize>(val: T) -> Result<Value, RpcErr> {
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
use std::io;
|
||||
use std::sync::Arc;
|
||||
|
||||
use actix_cors::Cors;
|
||||
use actix_web::{http, middleware, web, App, Error as HttpError, HttpResponse, HttpServer};
|
||||
@ -6,8 +7,11 @@ use futures::Future;
|
||||
use futures::FutureExt;
|
||||
use log::info;
|
||||
|
||||
use node_core::config::NodeConfig;
|
||||
use node_core::NodeCore;
|
||||
use rpc_primitives::message::Message;
|
||||
use rpc_primitives::RpcConfig;
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
use super::JsonHandler;
|
||||
|
||||
@ -38,7 +42,11 @@ fn get_cors(cors_allowed_origins: &[String]) -> Cors {
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn new_http_server(config: RpcConfig) -> io::Result<actix_web::dev::Server> {
|
||||
pub fn new_http_server(
|
||||
config: RpcConfig,
|
||||
node_config: NodeConfig,
|
||||
node_chain_store: Arc<Mutex<NodeCore>>,
|
||||
) -> io::Result<actix_web::dev::Server> {
|
||||
let RpcConfig {
|
||||
addr,
|
||||
cors_allowed_origins,
|
||||
@ -46,7 +54,11 @@ pub fn new_http_server(config: RpcConfig) -> io::Result<actix_web::dev::Server>
|
||||
limits_config,
|
||||
} = config;
|
||||
info!(target:"network", "Starting http server at {}", addr);
|
||||
let handler = web::Data::new(JsonHandler { polling_config });
|
||||
let handler = web::Data::new(JsonHandler {
|
||||
polling_config,
|
||||
node_core_config: node_config,
|
||||
node_chain_store,
|
||||
});
|
||||
|
||||
// HTTP server
|
||||
Ok(HttpServer::new(move || {
|
||||
|
||||
@ -9,7 +9,7 @@ use rpc_primitives::{
|
||||
|
||||
use crate::{
|
||||
rpc_error_responce_inverter,
|
||||
types::rpc_structs::{HelloRequest, HelloResponse},
|
||||
types::{err_rpc::cast_seq_client_error_into_rpc_error, rpc_structs::{RegisterAccountRequest, RegisterAccountResponse, SendTxRequest}},
|
||||
};
|
||||
|
||||
use super::{respond, types::err_rpc::RpcErr, JsonHandler};
|
||||
@ -31,13 +31,33 @@ impl JsonHandler {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::unused_async)]
|
||||
///Example of request processing
|
||||
async fn process_temp_hello(&self, request: Request) -> Result<Value, RpcErr> {
|
||||
let _hello_request = HelloRequest::parse(Some(request.params))?;
|
||||
async fn process_register_account(&self, request: Request) -> Result<Value, RpcErr> {
|
||||
let req = RegisterAccountRequest::parse(Some(request.params))?;
|
||||
|
||||
let helperstruct = HelloResponse {
|
||||
greeting: "HELLO_FROM_NODE".to_string(),
|
||||
{
|
||||
let guard = self.node_chain_store.lock().await;
|
||||
|
||||
guard.sequencer_client.register_account(&guard.main_acc).await.map_err(cast_seq_client_error_into_rpc_error)?;
|
||||
}
|
||||
|
||||
let helperstruct = RegisterAccountResponse {
|
||||
status: "success".to_string()
|
||||
};
|
||||
|
||||
respond(helperstruct)
|
||||
}
|
||||
|
||||
async fn process_send_tx(&self, request: Request) -> Result<Value, RpcErr> {
|
||||
let req = SendTxRequest::parse(Some(request.params))?;
|
||||
|
||||
{
|
||||
let guard = self.node_chain_store.lock().await;
|
||||
|
||||
guard.sequencer_client.send_tx(req.transaction).await.map_err(cast_seq_client_error_into_rpc_error)?;
|
||||
}
|
||||
|
||||
let helperstruct = RegisterAccountResponse {
|
||||
status: "success".to_string()
|
||||
};
|
||||
|
||||
respond(helperstruct)
|
||||
@ -46,7 +66,8 @@ impl JsonHandler {
|
||||
pub async fn process_request_internal(&self, request: Request) -> Result<Value, RpcErr> {
|
||||
match request.method.as_ref() {
|
||||
//Todo : Add handling of more JSON RPC methods
|
||||
"hello" => self.process_temp_hello(request).await,
|
||||
"register_account" => self.process_register_account(request).await,
|
||||
"send_tx" => self.process_send_tx(request).await,
|
||||
_ => Err(RpcErr(RpcError::method_not_found(request.method))),
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
use log::debug;
|
||||
|
||||
use node_core::sequencer_client::SequencerClientError;
|
||||
use rpc_primitives::errors::{RpcError, RpcParseError};
|
||||
|
||||
pub struct RpcErr(pub RpcError);
|
||||
@ -45,3 +46,12 @@ pub fn from_rpc_err_into_anyhow_err(rpc_err: RpcError) -> anyhow::Error {
|
||||
debug!("Rpc error cast to anyhow error : err {rpc_err:?}");
|
||||
anyhow::anyhow!(format!("{rpc_err:#?}"))
|
||||
}
|
||||
|
||||
pub fn cast_seq_client_error_into_rpc_error(seq_cli_err: SequencerClientError) -> RpcError {
|
||||
let error_string = seq_cli_err.to_string();
|
||||
|
||||
match seq_cli_err {
|
||||
SequencerClientError::SerdeError(_) => RpcError::serialization_error(&error_string),
|
||||
SequencerClientError::HTTPError(_) => RpcError::new_internal_error(None, &error_string),
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,13 +4,51 @@ use rpc_primitives::parser::parse_params;
|
||||
use rpc_primitives::parser::RpcRequest;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
use storage::block::Block;
|
||||
use storage::transaction::Transaction;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct HelloRequest {}
|
||||
pub struct RegisterAccountRequest {}
|
||||
|
||||
parse_request!(HelloRequest);
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct SendTxRequest {
|
||||
pub transaction: Transaction,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct GetBlockDataRequest {
|
||||
pub block_id: u64,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct GetGenesisIdRequest {}
|
||||
|
||||
parse_request!(RegisterAccountRequest);
|
||||
parse_request!(SendTxRequest);
|
||||
parse_request!(GetBlockDataRequest);
|
||||
parse_request!(GetGenesisIdRequest);
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct HelloResponse {
|
||||
pub greeting: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct RegisterAccountResponse {
|
||||
pub status: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct SendTxResponse {
|
||||
pub status: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct GetBlockDataResponse {
|
||||
pub block: Block,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct GetGenesisIdResponse {
|
||||
pub genesis_id: u64,
|
||||
}
|
||||
|
||||
@ -1,9 +1,10 @@
|
||||
use std::sync::Arc;
|
||||
use std::{path::PathBuf, sync::Arc};
|
||||
|
||||
use anyhow::Result;
|
||||
use consensus::ConsensusManager;
|
||||
use log::info;
|
||||
use networking::peer_manager::PeerManager;
|
||||
use node_core::{config::NodeConfig, NodeCore};
|
||||
use node_rpc::new_http_server;
|
||||
use rpc_primitives::RpcConfig;
|
||||
use tokio::sync::Mutex;
|
||||
@ -11,7 +12,18 @@ use tokio::sync::Mutex;
|
||||
pub async fn main_runner() -> Result<()> {
|
||||
env_logger::init();
|
||||
|
||||
let http_server = new_http_server(RpcConfig::default())?;
|
||||
//ToDo: Change it
|
||||
let node_config = NodeConfig {
|
||||
home: PathBuf::new(),
|
||||
override_rust_log: None,
|
||||
sequencer_addr: "addr".to_string(),
|
||||
seq_poll_timeout_secs: 1
|
||||
};
|
||||
|
||||
let node_core = NodeCore::start_from_config_update_chain(node_config.clone()).await?;
|
||||
let wrapped_node_core = Arc::new(Mutex::new(node_core));
|
||||
|
||||
let http_server = new_http_server(RpcConfig::default(), node_config.clone(), wrapped_node_core.clone())?;
|
||||
info!("HTTP server started");
|
||||
let _http_server_handle = http_server.handle();
|
||||
tokio::spawn(http_server);
|
||||
|
||||
@ -18,7 +18,7 @@ pub struct UTXO {
|
||||
pub privacy_flag: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct UTXOPayload {
|
||||
pub owner: AccountId,
|
||||
pub asset: Asset,
|
||||
|
||||
@ -13,6 +13,15 @@ serde.workspace = true
|
||||
risc0-zkvm = { git = "https://github.com/risc0/risc0.git", branch = "release-1.2" }
|
||||
test-methods = { path = "test_methods" }
|
||||
|
||||
[dependencies.accounts]
|
||||
path = "../accounts"
|
||||
|
||||
[dependencies.storage]
|
||||
path = "../storage"
|
||||
|
||||
[dependencies.utxo]
|
||||
path = "../utxo"
|
||||
|
||||
[features]
|
||||
cuda = ["risc0-zkvm/cuda"]
|
||||
default = []
|
||||
|
||||
@ -1,4 +1,78 @@
|
||||
use accounts::account_core::{Account, AccountAddress};
|
||||
use risc0_zkvm::{default_executor, default_prover, sha::Digest, ExecutorEnv, Receipt};
|
||||
use utxo::utxo_core::{UTXOPayload, UTXO};
|
||||
|
||||
pub fn prove_mint_utxo(amount_to_mint: u128, owner: AccountAddress) -> UTXO {
|
||||
let mut builder = ExecutorEnv::builder();
|
||||
|
||||
builder.write(&amount_to_mint).unwrap();
|
||||
builder.write(&owner).unwrap();
|
||||
|
||||
let env = builder.build().unwrap();
|
||||
|
||||
let prover = default_prover();
|
||||
|
||||
let receipt = prover.prove(env, test_methods::MINT_UTXO_ELF).unwrap().receipt;
|
||||
|
||||
let digest: UTXOPayload = receipt.journal.decode().unwrap();
|
||||
|
||||
UTXO::create_utxo_from_payload(digest)
|
||||
}
|
||||
|
||||
pub fn prove_send_utxo(spent_utxo: UTXO, owners_parts: Vec<(u128, AccountAddress)>) -> (UTXO, Vec<(UTXO, AccountAddress)>) {
|
||||
let mut builder = ExecutorEnv::builder();
|
||||
|
||||
builder.write(&spent_utxo).unwrap();
|
||||
builder.write(&owners_parts).unwrap();
|
||||
|
||||
let env = builder.build().unwrap();
|
||||
|
||||
let prover = default_prover();
|
||||
|
||||
let receipt = prover.prove(env, test_methods::SEND_UTXO_ELF).unwrap().receipt;
|
||||
|
||||
let digest: (UTXOPayload, Vec<(UTXOPayload, AccountAddress)>) = receipt.journal.decode().unwrap();
|
||||
|
||||
(UTXO::create_utxo_from_payload(digest.0), digest.1.into_iter().map(|(payload, addr)| (
|
||||
UTXO::create_utxo_from_payload(payload), addr
|
||||
)).collect())
|
||||
}
|
||||
|
||||
pub fn execute_mint_utxo(amount_to_mint: u128, owner: AccountAddress) -> UTXO {
|
||||
let mut builder = ExecutorEnv::builder();
|
||||
|
||||
builder.write(&amount_to_mint).unwrap();
|
||||
builder.write(&owner).unwrap();
|
||||
|
||||
let env = builder.build().unwrap();
|
||||
|
||||
let executor = default_executor();
|
||||
|
||||
let receipt = executor.execute(env, test_methods::MINT_UTXO_ELF).unwrap();
|
||||
|
||||
let digest: UTXOPayload = receipt.journal.decode().unwrap();
|
||||
|
||||
UTXO::create_utxo_from_payload(digest)
|
||||
}
|
||||
|
||||
pub fn execute_send_utxo(spent_utxo: UTXO, owners_parts: Vec<(u128, AccountAddress)>) -> (UTXO, Vec<(UTXO, AccountAddress)>) {
|
||||
let mut builder = ExecutorEnv::builder();
|
||||
|
||||
builder.write(&spent_utxo).unwrap();
|
||||
builder.write(&owners_parts).unwrap();
|
||||
|
||||
let env = builder.build().unwrap();
|
||||
|
||||
let executor = default_executor();
|
||||
|
||||
let receipt = executor.execute(env, test_methods::SEND_UTXO_ELF).unwrap();
|
||||
|
||||
let digest: (UTXOPayload, Vec<(UTXOPayload, AccountAddress)>) = receipt.journal.decode().unwrap();
|
||||
|
||||
(UTXO::create_utxo_from_payload(digest.0), digest.1.into_iter().map(|(payload, addr)| (
|
||||
UTXO::create_utxo_from_payload(payload), addr
|
||||
)).collect())
|
||||
}
|
||||
|
||||
pub fn prove<T: serde::ser::Serialize>(input_vec: Vec<T>, elf: &[u8]) -> (u64, Receipt) {
|
||||
let mut builder = ExecutorEnv::builder();
|
||||
|
||||
@ -4,7 +4,7 @@ version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[build-dependencies]
|
||||
risc0-build = { git = "https://github.com/risc0/risc0.git", branch = "release-1.1" }
|
||||
risc0-build = { git = "https://github.com/risc0/risc0.git", branch = "release-1.2" }
|
||||
|
||||
[package.metadata.risc0]
|
||||
methods = ["guest"]
|
||||
|
||||
28
zkvm/test_methods/guest/Cargo.lock
generated
28
zkvm/test_methods/guest/Cargo.lock
generated
@ -1,6 +1,6 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "ahash"
|
||||
@ -490,6 +490,12 @@ dependencies = [
|
||||
"either",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.162"
|
||||
@ -805,6 +811,12 @@ dependencies = [
|
||||
"semver",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "1.0.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f"
|
||||
|
||||
[[package]]
|
||||
name = "semver"
|
||||
version = "1.0.23"
|
||||
@ -831,6 +843,18 @@ dependencies = [
|
||||
"syn 2.0.87",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.133"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c7fceb2473b9166b2294ef05efcb65a3db80803f0b03ef86a5fc88a2b85ee377"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"memchr",
|
||||
"ryu",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sha2"
|
||||
version = "0.10.8"
|
||||
@ -885,6 +909,8 @@ name = "test"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"risc0-zkvm",
|
||||
"serde",
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
@ -6,6 +6,11 @@ edition = "2021"
|
||||
[workspace]
|
||||
|
||||
[dependencies]
|
||||
serde_json = "1.0.81"
|
||||
risc0-zkvm = { git = "https://github.com/risc0/risc0.git", default-features = false, features = [
|
||||
"std",
|
||||
] }
|
||||
|
||||
[dependencies.serde]
|
||||
features = ["derive"]
|
||||
version = "1.0.60"
|
||||
|
||||
29
zkvm/test_methods/guest/src/bin/mint_utxo.rs
Normal file
29
zkvm/test_methods/guest/src/bin/mint_utxo.rs
Normal file
@ -0,0 +1,29 @@
|
||||
use risc0_zkvm::{
|
||||
guest::env,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
type AccountAddr = [u8; 32];
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct UTXOPayload {
|
||||
pub owner: AccountAddr,
|
||||
pub asset: Vec<u8>,
|
||||
// TODO: change to u256
|
||||
pub amount: u128,
|
||||
pub privacy_flag: bool,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let amount_to_mint: u128 = env::read();
|
||||
let owner: AccountAddr = env::read();
|
||||
|
||||
let payload = UTXOPayload {
|
||||
owner,
|
||||
asset: vec![],
|
||||
amount: amount_to_mint,
|
||||
privacy_flag: true,
|
||||
};
|
||||
|
||||
env::commit(&(payload));
|
||||
}
|
||||
32
zkvm/test_methods/guest/src/bin/send_utxo.rs
Normal file
32
zkvm/test_methods/guest/src/bin/send_utxo.rs
Normal file
@ -0,0 +1,32 @@
|
||||
use risc0_zkvm::{
|
||||
guest::env,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
type AccountAddr = [u8; 32];
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct UTXOPayload {
|
||||
pub owner: AccountAddr,
|
||||
pub asset: Vec<u8>,
|
||||
// TODO: change to u256
|
||||
pub amount: u128,
|
||||
pub privacy_flag: bool,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let utxo_spent: UTXOPayload = env::read();
|
||||
let owners_parts: Vec<(u128, AccountAddr)> = env::read();
|
||||
|
||||
let res: Vec<(UTXOPayload, AccountAddr)> = owners_parts.into_iter().map(|(amount, addr)| (
|
||||
UTXOPayload {
|
||||
owner: addr.clone(),
|
||||
asset: vec![],
|
||||
amount,
|
||||
privacy_flag: true,
|
||||
},
|
||||
addr
|
||||
)).collect();
|
||||
|
||||
env::commit(&(res));
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user