Skip to content
Open
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
4,216 changes: 3,934 additions & 282 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ resolver = "2"
members = ["host", "contract", "methods"]

[workspace.dependencies]
sdk = { git = "https://github.com/hyle-org/hyle", package = "hyle-contract-sdk", tag = "v0.13.0-rc.4" } # don't forget to update methods/guest/Cargo.toml
client-sdk = { git = "https://github.com/hyle-org/hyle", package = "hyle-client-sdk", tag = "v0.13.0-rc.4" }
sdk = { git = "https://github.com/hyli-org/hyli", package = "hyle-contract-sdk", tag = "v0.13.2" } # don't forget to update methods/guest/Cargo.toml
client-sdk = { git = "https://github.com/hyli-org/hyli", package = "hyle-client-sdk", tag = "v0.13.2" }

# Always optimize; building and running the guest takes much longer without optimization.
[profile.dev]
Expand Down
5 changes: 4 additions & 1 deletion contract/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use borsh::{io::Error, BorshDeserialize, BorshSerialize};
use sdk::FullStateRevert;
use serde::{Deserialize, Serialize};

impl sdk::ZkContract for Counter {
Expand All @@ -14,7 +15,7 @@ impl sdk::ZkContract for Counter {

// program_output might be used to give feedback to the user
let program_output = format!("new value: {}", self.value);
Ok((program_output, ctx, vec![]))
Ok((program_output.into(), ctx, vec![]))
}

/// Commit the state of the contract
Expand All @@ -35,6 +36,8 @@ pub struct Counter {
pub value: u32,
}

impl FullStateRevert for Counter {}

/// Utils function for the host
impl Counter {
pub fn as_bytes(&self) -> Result<Vec<u8>, Error> {
Expand Down
2 changes: 1 addition & 1 deletion host/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ tracing-subscriber = { version = "0.3", features = ["env-filter"] }
clap = { version = "4.5.23", features = ["derive"] }
borsh = "1.5.7"
tokio = { version = "1.42.0", features = ["full", "tracing"] }
anyhow = "1.0.96"
anyhow = "1.0.98"
16 changes: 9 additions & 7 deletions host/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use anyhow::Result;
use clap::{Parser, Subcommand};
use client_sdk::helpers::risc0::Risc0Prover;
use client_sdk::rest_client::NodeApiClient;
use contract::Counter;
use contract::CounterAction;
use sdk::api::APIRegisterContract;
Expand Down Expand Up @@ -53,22 +54,23 @@ async fn main() -> Result<()> {

// Send the transaction to register the contract
let res = client
.register_contract(&APIRegisterContract {
.register_contract(APIRegisterContract {
verifier: "risc0-1".into(),
program_id: sdk::ProgramId(sdk::to_u8_array(&GUEST_ID).to_vec()),
state_commitment: initial_state.commit(),
contract_name: contract_name.clone().into(),
..Default::default()
})
.await?;
println!("✅ Register contract tx sent. Tx hash: {}", res);
}
Commands::Increment {} => {
// Fetch the initial state from the node
let mut initial_state: Counter = client
.get_contract(&contract_name.clone().into())
let initial_state: Counter = client
.get_contract(contract_name.clone().into())
.await
.unwrap()
.state
.state_commitment
.into();

// ----
Expand All @@ -79,7 +81,7 @@ async fn main() -> Result<()> {
let blob_tx = BlobTransaction::new(identity.clone(), blobs.clone());

// Send the blob transaction
let blob_tx_hash = client.send_tx_blob(&blob_tx).await.unwrap();
let blob_tx_hash = client.send_tx_blob(blob_tx).await.unwrap();
println!("✅ Blob tx sent. Tx hash: {}", blob_tx_hash);

// ----
Expand All @@ -97,7 +99,7 @@ async fn main() -> Result<()> {
tx_blob_count: blobs.len(),
};
let (program_outputs, _, _) = initial_state.clone().execute(&inputs).unwrap();
println!("🚀 Executed: {}", program_outputs);
println!("🚀 Executed: {}", String::from_utf8(program_outputs).unwrap());

// Generate the zk proof
let proof = prover
Expand All @@ -112,7 +114,7 @@ async fn main() -> Result<()> {
};

// Send the proof transaction
let proof_tx_hash = client.send_tx_proof(&proof_tx).await.unwrap();
let proof_tx_hash = client.send_tx_proof(proof_tx).await.unwrap();
println!("✅ Proof tx sent. Tx hash: {}", proof_tx_hash);
}
}
Expand Down
83 changes: 60 additions & 23 deletions methods/guest/Cargo.lock

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

6 changes: 3 additions & 3 deletions methods/guest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ edition = "2021"
[workspace]

[dependencies]
sdk = { git = "https://github.com/hyle-org/hyle", package = "hyle-contract-sdk", features = [
sdk = { git = "https://github.com/hyli-org/hyli", package = "hyle-contract-sdk", features = [
"risc0",
], tag = "v0.13.0-rc.4" }
], tag = "v0.13.2" }
contract = { path = "../../contract", package = "contract" }

risc0-zkvm = { version = "2.0.1", default-features = false, features = ['std'] }
risc0-zkvm = { version = "2.1.0", default-features = false, features = ['std'] }
4 changes: 2 additions & 2 deletions methods/guest/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ fn main() {
let env = Risc0Env {};
let (commitment_metadata, calldata): (Vec<u8>, Calldata) = env.read();

let output = execute::<Counter>(&commitment_metadata, &calldata);
env.commit(&output);
let output = execute::<Counter>(&commitment_metadata, &[calldata]);
env.commit(output);
}