mirror of
https://github.com/logos-blockchain/lssa.git
synced 2026-01-06 23:33:10 +00:00
Merge branch 'Pravdyvy/complex-scenarios' into Pravdyvy/show-rpc-methods
This commit is contained in:
commit
b9ec326112
@ -3,7 +3,7 @@ use std::collections::HashMap;
|
||||
use anyhow::Result;
|
||||
use k256::AffinePoint;
|
||||
use log::info;
|
||||
use serde::Serialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use storage::{merkle_tree_public::TreeHashType, nullifier::UTXONullifier};
|
||||
use utxo::{
|
||||
utxo_core::{UTXOPayload, UTXO},
|
||||
@ -118,7 +118,7 @@ impl Account {
|
||||
}
|
||||
|
||||
pub fn log(&self) {
|
||||
self.key_holder.log();
|
||||
info!("Keys generated");
|
||||
info!("Account address is {:?}", hex::encode(self.address));
|
||||
info!("Account balance is {:?}", self.balance);
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@ use aes_gcm::{aead::Aead, AeadCore, Aes256Gcm, Key, KeyInit};
|
||||
use elliptic_curve::group::GroupEncoding;
|
||||
use elliptic_curve::PrimeField;
|
||||
use k256::{AffinePoint, FieldBytes, Scalar};
|
||||
use log::info;
|
||||
use rand::{rngs::OsRng, RngCore};
|
||||
|
||||
use super::constants_types::{CipherText, Nonce};
|
||||
@ -51,4 +52,11 @@ impl EphemeralKeyHolder {
|
||||
|
||||
(cipher.encrypt(&nonce, data).unwrap(), nonce)
|
||||
}
|
||||
|
||||
pub fn log(&self) {
|
||||
info!(
|
||||
"Ephemeral private key is {:?}",
|
||||
hex::encode(self.ephemeral_secret_key.to_bytes())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -78,21 +78,24 @@ impl AddressKeyHolder {
|
||||
|
||||
pub fn log(&self) {
|
||||
info!(
|
||||
"AddressKeyHolder top_secret_key_holder is {:?}",
|
||||
self.top_secret_key_holder
|
||||
"Secret spending key is {:?}",
|
||||
hex::encode(self.top_secret_key_holder.secret_spending_key.to_bytes()),
|
||||
);
|
||||
info!(
|
||||
"AddressKeyHolder utxo_secret_key_holder is {:?}",
|
||||
self.utxo_secret_key_holder
|
||||
);
|
||||
info!("AddressKeyHolder address is {:?}", self.address);
|
||||
info!(
|
||||
"AddressKeyHolder nullifer_public_key is {:?}",
|
||||
self.nullifer_public_key
|
||||
"Nulifier secret key is {:?}",
|
||||
hex::encode(self.utxo_secret_key_holder.nullifier_secret_key.to_bytes()),
|
||||
);
|
||||
info!(
|
||||
"AddressKeyHolder viewing_public_key is {:?}",
|
||||
self.viewing_public_key
|
||||
"Viewing secret key is {:?}",
|
||||
hex::encode(self.utxo_secret_key_holder.viewing_secret_key.to_bytes()),
|
||||
);
|
||||
info!(
|
||||
"Nullifier public key is {:?}",
|
||||
hex::encode(self.nullifer_public_key.to_bytes()),
|
||||
);
|
||||
info!(
|
||||
"Viewing public key is {:?}",
|
||||
hex::encode(self.viewing_public_key.to_bytes()),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -17,7 +17,7 @@ pub struct SeedHolder {
|
||||
#[derive(Debug, Clone)]
|
||||
///Secret spending key holder. Produces `UTXOSecretKeyHolder` objects.
|
||||
pub struct TopSecretKeyHolder {
|
||||
secret_spending_key: Scalar,
|
||||
pub secret_spending_key: Scalar,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,20 +1,15 @@
|
||||
use std::{collections::HashMap, path::Path};
|
||||
|
||||
use accounts::account_core::{Account, AccountAddress};
|
||||
use accounts_store::NodeAccountsStore;
|
||||
use anyhow::Result;
|
||||
use block_store::NodeBlockStore;
|
||||
use elliptic_curve::group::GroupEncoding;
|
||||
use k256::AffinePoint;
|
||||
use storage::{
|
||||
block::Block,
|
||||
merkle_tree_public::{
|
||||
merkle_tree::{PublicTransactionMerkleTree, UTXOCommitmentsMerkleTree},
|
||||
TreeHashType,
|
||||
},
|
||||
merkle_tree_public::merkle_tree::{PublicTransactionMerkleTree, UTXOCommitmentsMerkleTree},
|
||||
nullifier::UTXONullifier,
|
||||
nullifier_sparse_merkle_tree::NullifierSparseMerkleTree,
|
||||
transaction::Transaction,
|
||||
utxo_commitment::UTXOCommitment,
|
||||
};
|
||||
use utxo::utxo_core::UTXO;
|
||||
@ -85,6 +80,7 @@ impl NodeChainStore {
|
||||
acc_mut.balance.saturating_sub(action.amount as u64);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -14,9 +14,11 @@ use crate::{
|
||||
types::{
|
||||
err_rpc::cast_seq_client_error_into_rpc_error,
|
||||
rpc_structs::{
|
||||
ExecuteSubscenarioRequest, ExecuteSubscenarioResponse, GetBlockDataRequest,
|
||||
GetBlockDataResponse, GetLastBlockRequest, GetLastBlockResponse,
|
||||
RegisterAccountRequest, RegisterAccountResponse, SendTxRequest,
|
||||
ExecuteScenarioMultipleSendRequest, ExecuteScenarioMultipleSendResponse,
|
||||
ExecuteScenarioSplitRequest, ExecuteScenarioSplitResponse, ExecuteSubscenarioRequest,
|
||||
ExecuteSubscenarioResponse, GetBlockDataRequest, GetBlockDataResponse,
|
||||
GetLastBlockRequest, GetLastBlockResponse, RegisterAccountRequest,
|
||||
RegisterAccountResponse, SendTxRequest,
|
||||
},
|
||||
},
|
||||
};
|
||||
@ -63,6 +65,48 @@ impl JsonHandler {
|
||||
respond(helperstruct)
|
||||
}
|
||||
|
||||
async fn process_request_execute_scenario_split(
|
||||
&self,
|
||||
request: Request,
|
||||
) -> Result<Value, RpcErr> {
|
||||
let req = ExecuteScenarioSplitRequest::parse(Some(request.params))?;
|
||||
|
||||
{
|
||||
let mut store = self.node_chain_store.lock().await;
|
||||
|
||||
store
|
||||
.scenario_1(req.visibility_list, req.publication_index)
|
||||
.await;
|
||||
}
|
||||
|
||||
let helperstruct = ExecuteScenarioSplitResponse {
|
||||
scenario_result: "success".to_string(),
|
||||
};
|
||||
|
||||
respond(helperstruct)
|
||||
}
|
||||
|
||||
async fn process_request_execute_scenario_multiple_send(
|
||||
&self,
|
||||
request: Request,
|
||||
) -> Result<Value, RpcErr> {
|
||||
let req = ExecuteScenarioMultipleSendRequest::parse(Some(request.params))?;
|
||||
|
||||
{
|
||||
let mut store = self.node_chain_store.lock().await;
|
||||
|
||||
store
|
||||
.scenario_2(req.number_of_assets, req.number_to_send)
|
||||
.await;
|
||||
}
|
||||
|
||||
let helperstruct = ExecuteScenarioMultipleSendResponse {
|
||||
scenario_result: "success".to_string(),
|
||||
};
|
||||
|
||||
respond(helperstruct)
|
||||
}
|
||||
|
||||
async fn process_register_account(&self, request: Request) -> Result<Value, RpcErr> {
|
||||
let _req = RegisterAccountRequest::parse(Some(request.params))?;
|
||||
|
||||
@ -139,6 +183,11 @@ impl JsonHandler {
|
||||
"send_tx" => self.process_send_tx(request).await,
|
||||
"get_block" => self.process_get_block_data(request).await,
|
||||
"get_last_block" => self.process_get_last_block(request).await,
|
||||
"execute_scenario_split" => self.process_request_execute_scenario_split(request).await,
|
||||
"execute_scenario_multiple_send" => {
|
||||
self.process_request_execute_scenario_multiple_send(request)
|
||||
.await
|
||||
}
|
||||
_ => Err(RpcErr(RpcError::method_not_found(request.method))),
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,6 +25,18 @@ pub struct ExecuteSubscenarioRequest {
|
||||
pub scenario_id: u64,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct ExecuteScenarioSplitRequest {
|
||||
pub visibility_list: [bool; 3],
|
||||
pub publication_index: usize,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct ExecuteScenarioMultipleSendRequest {
|
||||
pub number_of_assets: usize,
|
||||
pub number_to_send: usize,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct GetGenesisIdRequest {}
|
||||
|
||||
@ -36,6 +48,8 @@ parse_request!(SendTxRequest);
|
||||
parse_request!(GetBlockDataRequest);
|
||||
parse_request!(GetGenesisIdRequest);
|
||||
parse_request!(ExecuteSubscenarioRequest);
|
||||
parse_request!(ExecuteScenarioSplitRequest);
|
||||
parse_request!(ExecuteScenarioMultipleSendRequest);
|
||||
parse_request!(GetLastBlockRequest);
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
@ -63,6 +77,16 @@ pub struct ExecuteSubscenarioResponse {
|
||||
pub scenario_result: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct ExecuteScenarioSplitResponse {
|
||||
pub scenario_result: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct ExecuteScenarioMultipleSendResponse {
|
||||
pub scenario_result: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct GetGenesisIdResponse {
|
||||
pub genesis_id: u64,
|
||||
|
||||
@ -91,45 +91,144 @@ impl From<TransactionPayload> for Transaction {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct MintMoneyPublicTx {
|
||||
pub acc: [u8; 32],
|
||||
pub amount: u128,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct SendMoneyShieldedTx {
|
||||
pub acc_sender: [u8; 32],
|
||||
pub amount: u128,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct SendMoneyDeshieldedTx {
|
||||
pub receiver_data: Vec<(u128, [u8; 32])>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct OwnedUTXO {
|
||||
pub hash: [u8; 32],
|
||||
pub owner: [u8; 32],
|
||||
pub amount: u128,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct OwnedUTXOForPublication {
|
||||
pub hash: String,
|
||||
pub owner: String,
|
||||
pub amount: u128,
|
||||
}
|
||||
|
||||
impl From<OwnedUTXO> for OwnedUTXOForPublication {
|
||||
fn from(value: OwnedUTXO) -> Self {
|
||||
Self {
|
||||
hash: hex::encode(value.hash),
|
||||
owner: hex::encode(value.owner),
|
||||
amount: value.amount,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct UTXOPublication {
|
||||
pub utxos: Vec<OwnedUTXO>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub enum ActionData {
|
||||
MintMoneyPublicTx(MintMoneyPublicTx),
|
||||
SendMoneyShieldedTx(SendMoneyShieldedTx),
|
||||
SendMoneyDeshieldedTx(SendMoneyDeshieldedTx),
|
||||
UTXOPublication(UTXOPublication),
|
||||
}
|
||||
|
||||
impl ActionData {
|
||||
pub fn into_hexed_print(self) -> String {
|
||||
match self {
|
||||
ActionData::MintMoneyPublicTx(action) => {
|
||||
format!(
|
||||
"Account {:?} minted {:?} balance",
|
||||
hex::encode(action.acc),
|
||||
action.amount
|
||||
)
|
||||
}
|
||||
ActionData::SendMoneyDeshieldedTx(action) => {
|
||||
format!(
|
||||
"Receivers receipt {:?}",
|
||||
action
|
||||
.receiver_data
|
||||
.into_iter()
|
||||
.map(|(amount, rec)| (amount, hex::encode(rec)))
|
||||
.collect::<Vec<_>>()
|
||||
)
|
||||
}
|
||||
ActionData::SendMoneyShieldedTx(action) => {
|
||||
format!(
|
||||
"Shielded send from {:?} for {:?} balance",
|
||||
hex::encode(action.acc_sender),
|
||||
action.amount
|
||||
)
|
||||
}
|
||||
ActionData::UTXOPublication(action) => {
|
||||
let pub_own_utxo: Vec<OwnedUTXOForPublication> = action
|
||||
.utxos
|
||||
.into_iter()
|
||||
.map(|owned_utxo| owned_utxo.into())
|
||||
.collect();
|
||||
format!("Published utxos {:?}", pub_own_utxo)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Transaction {
|
||||
pub fn log(&self) {
|
||||
info!("Transaction hash is {:?}", hex::encode(self.hash));
|
||||
info!("Transaction tx_kind is {:?}", self.tx_kind);
|
||||
info!(
|
||||
"Transaction execution_input is {:?}",
|
||||
hex::encode(self.execution_input.clone())
|
||||
);
|
||||
info!(
|
||||
"Transaction execution_output is {:?}",
|
||||
hex::encode(self.execution_output.clone())
|
||||
);
|
||||
info!("Transaction execution_input is {:?}", {
|
||||
if let Ok(action) = serde_json::from_slice::<ActionData>(&self.execution_input) {
|
||||
action.into_hexed_print()
|
||||
} else {
|
||||
"".to_string()
|
||||
}
|
||||
});
|
||||
info!("Transaction execution_output is {:?}", {
|
||||
if let Ok(action) = serde_json::from_slice::<ActionData>(&self.execution_output) {
|
||||
action.into_hexed_print()
|
||||
} else {
|
||||
"".to_string()
|
||||
}
|
||||
});
|
||||
info!(
|
||||
"Transaction utxo_commitments_spent_hashes is {:?}",
|
||||
self.utxo_commitments_spent_hashes
|
||||
.iter()
|
||||
.map(|val| hex::encode(val.clone()))
|
||||
.collect::<Vec<_>>()
|
||||
);
|
||||
info!(
|
||||
"Transaction utxo_commitments_created_hashes is {:?}",
|
||||
self.utxo_commitments_created_hashes
|
||||
.iter()
|
||||
.map(|val| hex::encode(val.clone()))
|
||||
.collect::<Vec<_>>()
|
||||
);
|
||||
info!(
|
||||
"Transaction nullifier_created_hashes is {:?}",
|
||||
self.nullifier_created_hashes
|
||||
.iter()
|
||||
.map(|val| hex::encode(val.clone()))
|
||||
);
|
||||
info!(
|
||||
"Transaction execution_proof_private is {:?}",
|
||||
self.execution_proof_private
|
||||
.collect::<Vec<_>>()
|
||||
);
|
||||
info!(
|
||||
"Transaction encoded_data is {:?}",
|
||||
self.encoded_data
|
||||
.iter()
|
||||
.map(|val| (hex::encode(val.0.clone()), hex::encode(val.1.clone())))
|
||||
.collect::<Vec<_>>()
|
||||
);
|
||||
info!(
|
||||
"Transaction ephemeral_pub_key is {:?}",
|
||||
|
||||
@ -73,7 +73,7 @@ impl UTXO {
|
||||
|
||||
pub fn log(&self) {
|
||||
info!("UTXO hash is {:?}", hex::encode(self.hash));
|
||||
info!("UTXO owner is {:?}", self.owner);
|
||||
info!("UTXO owner is {:?}", hex::encode(self.owner));
|
||||
info!(
|
||||
"UTXO nullifier is {:?}",
|
||||
self.nullifier.clone().map(|val| hex::encode(val.utxo_hash))
|
||||
|
||||
@ -52,6 +52,47 @@ pub fn prove_send_utxo(
|
||||
)
|
||||
}
|
||||
|
||||
pub fn prove_send_utxo_multiple_assets_one_receiver(
|
||||
spent_utxos: Vec<UTXO>,
|
||||
number_to_send: usize,
|
||||
receiver: AccountAddress,
|
||||
) -> (Vec<UTXO>, Vec<UTXO>, Receipt) {
|
||||
let mut builder = ExecutorEnv::builder();
|
||||
let utxo_payload: Vec<UTXOPayload> = spent_utxos
|
||||
.into_iter()
|
||||
.map(|spent_utxo| spent_utxo.into_payload())
|
||||
.collect();
|
||||
|
||||
builder.write(&utxo_payload).unwrap();
|
||||
builder.write(&number_to_send).unwrap();
|
||||
builder.write(&receiver).unwrap();
|
||||
|
||||
let env = builder.build().unwrap();
|
||||
|
||||
let prover = default_prover();
|
||||
|
||||
let receipt = prover
|
||||
.prove(env, test_methods::SEND_UTXO_MULTIPLE_ASSETS_ELF)
|
||||
.unwrap()
|
||||
.receipt;
|
||||
|
||||
let digest: (Vec<UTXOPayload>, Vec<UTXOPayload>) = receipt.journal.decode().unwrap();
|
||||
|
||||
(
|
||||
digest
|
||||
.0
|
||||
.into_iter()
|
||||
.map(|payload| UTXO::create_utxo_from_payload(payload))
|
||||
.collect(),
|
||||
digest
|
||||
.1
|
||||
.into_iter()
|
||||
.map(|payload| UTXO::create_utxo_from_payload(payload))
|
||||
.collect(),
|
||||
receipt,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn prove_send_utxo_shielded(
|
||||
owner: AccountAddress,
|
||||
amount: u128,
|
||||
@ -120,6 +161,37 @@ pub fn prove_send_utxo_deshielded(
|
||||
)
|
||||
}
|
||||
|
||||
pub fn prove_mint_utxo_multiple_assets(
|
||||
amount_to_mint: u128,
|
||||
number_of_assets: usize,
|
||||
owner: AccountAddress,
|
||||
) -> (Vec<UTXO>, Receipt) {
|
||||
let mut builder = ExecutorEnv::builder();
|
||||
|
||||
builder.write(&amount_to_mint).unwrap();
|
||||
builder.write(&number_of_assets).unwrap();
|
||||
builder.write(&owner).unwrap();
|
||||
|
||||
let env = builder.build().unwrap();
|
||||
|
||||
let prover = default_prover();
|
||||
|
||||
let receipt = prover
|
||||
.prove(env, test_methods::MINT_UTXO_MULTIPLE_ASSETS_ELF)
|
||||
.unwrap()
|
||||
.receipt;
|
||||
|
||||
let digest: Vec<UTXOPayload> = receipt.journal.decode().unwrap();
|
||||
|
||||
(
|
||||
digest
|
||||
.into_iter()
|
||||
.map(UTXO::create_utxo_from_payload)
|
||||
.collect(),
|
||||
receipt,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn execute_mint_utxo(amount_to_mint: u128, owner: AccountAddress) -> UTXO {
|
||||
let mut builder = ExecutorEnv::builder();
|
||||
|
||||
|
||||
36
zkvm/test_methods/guest/src/bin/mint_utxo_multiple_assets.rs
Normal file
36
zkvm/test_methods/guest/src/bin/mint_utxo_multiple_assets.rs
Normal file
@ -0,0 +1,36 @@
|
||||
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 number_of_assets: usize = env::read();
|
||||
let owner: AccountAddr = env::read();
|
||||
|
||||
let mut asseted_utxos = vec![];
|
||||
|
||||
for i in 0..number_of_assets {
|
||||
let payload = UTXOPayload {
|
||||
owner,
|
||||
asset: vec![i as u8],
|
||||
amount: amount_to_mint,
|
||||
privacy_flag: true,
|
||||
};
|
||||
|
||||
asseted_utxos.push(payload);
|
||||
}
|
||||
|
||||
env::commit(&(asseted_utxos));
|
||||
}
|
||||
40
zkvm/test_methods/guest/src/bin/send_utxo_multiple_assets.rs
Normal file
40
zkvm/test_methods/guest/src/bin/send_utxo_multiple_assets.rs
Normal file
@ -0,0 +1,40 @@
|
||||
use risc0_zkvm::{
|
||||
guest::env,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
type AccountAddr = [u8; 32];
|
||||
|
||||
#[derive(Clone, 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: Vec<UTXOPayload> = env::read();
|
||||
let number_to_send = env::read();
|
||||
let receiver: AccountAddr = env::read();
|
||||
|
||||
let mut utxo_received = vec![];
|
||||
let mut utxo_not_spent = vec![];
|
||||
|
||||
for i in 0..utxo_spent.len() {
|
||||
let mut utxo_payload = utxo_spent[i].clone();
|
||||
|
||||
if i < number_to_send {
|
||||
utxo_payload.owner = receiver;
|
||||
|
||||
utxo_received.push(utxo_payload);
|
||||
} else {
|
||||
utxo_payload.asset.push(0);
|
||||
|
||||
utxo_not_spent.push(utxo_payload);
|
||||
}
|
||||
}
|
||||
|
||||
env::commit(&(utxo_received, utxo_not_spent));
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user