mirror of
https://github.com/logos-blockchain/lssa.git
synced 2026-05-22 09:39:44 +00:00
rm template
This commit is contained in:
parent
bfea8a8797
commit
7635448652
@ -1,17 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "sc_example"
|
|
||||||
version = "0.1.0"
|
|
||||||
edition = "2024"
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
serde_json = "1.0.81"
|
|
||||||
|
|
||||||
[dependencies.sc_core]
|
|
||||||
path = "../../sc_core"
|
|
||||||
|
|
||||||
[dependencies.utxo]
|
|
||||||
path = "../../utxo"
|
|
||||||
|
|
||||||
[dependencies.serde]
|
|
||||||
features = ["derive"]
|
|
||||||
version = "1.0.60"
|
|
||||||
@ -1,70 +0,0 @@
|
|||||||
use sc_core::traits::{
|
|
||||||
IContract, IDeshieldedExecutor, IInputParameters, IPrivateOutput, IPublicOutput,
|
|
||||||
};
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use utxo::utxo_core::UTXO;
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
|
||||||
struct SmartContract {}
|
|
||||||
|
|
||||||
impl<'a> IContract<'a> for SmartContract {}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
|
||||||
struct InputParameters {
|
|
||||||
pub a: u64,
|
|
||||||
pub b: u64,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> IInputParameters<'a> for InputParameters {
|
|
||||||
fn public_input_parameters_ser(&self) -> Vec<Vec<u8>> {
|
|
||||||
let param_vec = vec![self.a];
|
|
||||||
|
|
||||||
param_vec
|
|
||||||
.into_iter()
|
|
||||||
.map(|item| serde_json::to_vec(&item).unwrap())
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
|
||||||
struct PublicOutputs {
|
|
||||||
pub ab: u64,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl IPublicOutput for PublicOutputs {}
|
|
||||||
|
|
||||||
struct PrivateOutputs {
|
|
||||||
pub a_plus_b: u64,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl IPrivateOutput for PrivateOutputs {
|
|
||||||
fn make_utxo_list(&self) -> Vec<UTXO> {
|
|
||||||
let mut utxo_list = vec![];
|
|
||||||
|
|
||||||
let res_utxo = UTXO {
|
|
||||||
hash: [0; 32],
|
|
||||||
owner: [1; 32],
|
|
||||||
asset: vec![1, 2, 3],
|
|
||||||
amount: self.a_plus_b as u128,
|
|
||||||
privacy_flag: true,
|
|
||||||
randomness: [2; 32],
|
|
||||||
};
|
|
||||||
|
|
||||||
utxo_list.push(res_utxo);
|
|
||||||
|
|
||||||
utxo_list
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> IDeshieldedExecutor<'a, InputParameters, PublicOutputs, PrivateOutputs> for SmartContract {
|
|
||||||
fn deshielded_execution(&self, inputs: InputParameters) -> (PublicOutputs, PrivateOutputs) {
|
|
||||||
(
|
|
||||||
PublicOutputs {
|
|
||||||
ab: inputs.a * inputs.b,
|
|
||||||
},
|
|
||||||
PrivateOutputs {
|
|
||||||
a_plus_b: inputs.a + inputs.b,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,20 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "zk_test_template"
|
|
||||||
version = "0.1.0"
|
|
||||||
edition = "2021"
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
anyhow = "1.0"
|
|
||||||
serde_json = "1.0.81"
|
|
||||||
|
|
||||||
risc0-zkvm = { git = "https://github.com/risc0/risc0.git", branch = "release-2.0" }
|
|
||||||
test-methods = { path = "test_methods" }
|
|
||||||
|
|
||||||
[dependencies.serde]
|
|
||||||
features = ["derive"]
|
|
||||||
version = "1.0.60"
|
|
||||||
|
|
||||||
[features]
|
|
||||||
cuda = ["risc0-zkvm/cuda"]
|
|
||||||
default = []
|
|
||||||
prove = ["risc0-zkvm/prove"]
|
|
||||||
@ -1 +0,0 @@
|
|||||||
//ToDo: handle ABI of smart contract
|
|
||||||
@ -1,10 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "test-methods"
|
|
||||||
version = "0.1.0"
|
|
||||||
edition = "2021"
|
|
||||||
|
|
||||||
[build-dependencies]
|
|
||||||
risc0-build = { git = "https://github.com/risc0/risc0.git", branch = "release-2.0" }
|
|
||||||
|
|
||||||
[package.metadata.risc0]
|
|
||||||
methods = ["guest"]
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
fn main() {
|
|
||||||
risc0_build::embed_methods();
|
|
||||||
}
|
|
||||||
@ -1,22 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "test"
|
|
||||||
version = "0.1.0"
|
|
||||||
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"
|
|
||||||
|
|
||||||
[dependencies.{sc_name}]
|
|
||||||
path = "../../../{sc_name}"
|
|
||||||
|
|
||||||
[dependencies.sc_core]
|
|
||||||
path = "../../../../sc_core"
|
|
||||||
@ -1,59 +0,0 @@
|
|||||||
use risc0_zkvm::{
|
|
||||||
guest::env,
|
|
||||||
};
|
|
||||||
|
|
||||||
use {sc_name}::{SmartContract, InputParameters, PublicOutputs, PrivateOutputs};
|
|
||||||
use sc_core::traits::{IContract, IInputParameters, IPublicOutput, IPrivateOutput};
|
|
||||||
use sc_core::{{execution_type_trait}};
|
|
||||||
|
|
||||||
use sc_core::{PublicSCContext, produce_blob_list_from_sc_public_state, compare_blob_lists};
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let mut state: SmartContract = env::read();
|
|
||||||
//Must fail if this step fails
|
|
||||||
let old_state = produce_blob_list_from_sc_public_state(&state).unwrap();
|
|
||||||
|
|
||||||
let public_context: PublicSCContext = env::read();
|
|
||||||
let inputs: InputParameters = env::read();
|
|
||||||
|
|
||||||
//In RISC0 all input parameters are private, so we need to commit to public ones
|
|
||||||
env::commit(&(inputs.public_input_parameters_ser()))
|
|
||||||
|
|
||||||
//Next, push one of possible variants depending on execution type
|
|
||||||
{
|
|
||||||
public => let public_outputs = state.public_execution(inputs);,
|
|
||||||
private => let private_outputs = state.private_execution(inputs);,
|
|
||||||
shielded => let (public_outputs, private_outputs) = state.shielded_execution(inputs);,
|
|
||||||
deshielded => let (public_outputs, private_outputs) = state.shielded_execution(inputs);,
|
|
||||||
}
|
|
||||||
|
|
||||||
//Next, push one of possible variants depending on execution type
|
|
||||||
//ToDo [Debatable]: Rework and update circuits to work with new trait system system
|
|
||||||
{
|
|
||||||
public => ,
|
|
||||||
private => private_circuit(public_context, private_outputs);,
|
|
||||||
shielded => shielded_circuit(public_context, public_outputs, private_outputs);,
|
|
||||||
deshielded => deshielded_circuit(public_context, public_outputs, private_outputs);,
|
|
||||||
}
|
|
||||||
|
|
||||||
//Must fail if this step fails
|
|
||||||
let new_state = produce_blob_list_from_sc_public_state(&state).unwrap();
|
|
||||||
|
|
||||||
//Commiting public state changes
|
|
||||||
let state_changes = compare_blob_lists(old_state, new_state);
|
|
||||||
env::commit(&state_changes);
|
|
||||||
|
|
||||||
//Next, push one of possible variants depending on execution type
|
|
||||||
{
|
|
||||||
public => {
|
|
||||||
env::commit(&public_outputs);
|
|
||||||
},
|
|
||||||
private => {
|
|
||||||
env::commit(&(public_context.encode_utxo_for_owners(private_outputs)));
|
|
||||||
},
|
|
||||||
shielded | deshielded => {
|
|
||||||
env::commit(&public_outputs);
|
|
||||||
env::commit(&(public_context.encode_utxo_for_owners(private_outputs)));
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1 +0,0 @@
|
|||||||
include!(concat!(env!("OUT_DIR"), "/methods.rs"));
|
|
||||||
Loading…
x
Reference in New Issue
Block a user