diff --git a/.github/workflows/foundry-test.yml b/.github/workflows/foundry-test.yml deleted file mode 100644 index f00e456..0000000 --- a/.github/workflows/foundry-test.yml +++ /dev/null @@ -1,40 +0,0 @@ -name: Foundry Test - -on: - workflow_dispatch: - push: - branches: [ main ] - pull_request: - -env: - FOUNDRY_PROFILE: ci - -jobs: - check: - strategy: - fail-fast: true - - name: Foundry project - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - submodules: recursive - - - name: Install Foundry - uses: foundry-rs/foundry-toolchain@v1 - with: - version: nightly - - - name: Run Forge build - run: | - cd contracts - forge --version - forge build --sizes - id: build - - - name: Run Forge tests - run: | - cd contracts - forge test -vvv - id: test diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 9219300..0000000 --- a/.gitmodules +++ /dev/null @@ -1,10 +0,0 @@ -[submodule "contracts/lib/forge-std"] - path = contracts/lib/forge-std - url = https://github.com/foundry-rs/forge-std - tag = v1.8.2 - shallow = true -[submodule "contracts/lib/sp1-contracts"] - path = contracts/lib/sp1-contracts - url = https://github.com/succinctlabs/sp1-contracts - tag = v2.0.0 - shallow = true diff --git a/Cargo.lock b/Cargo.lock index 45ffb36..2e6ff2b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1729,14 +1729,13 @@ checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d" name = "fibonacci-lib" version = "0.1.0" dependencies = [ - "alloy-sol-types", + "serde", ] [[package]] name = "fibonacci-program" version = "0.1.0" dependencies = [ - "alloy-sol-types", "fibonacci-lib", "sp1-zkvm", ] @@ -1745,7 +1744,6 @@ dependencies = [ name = "fibonacci-script" version = "0.1.0" dependencies = [ - "alloy-sol-types", "clap", "fibonacci-lib", "hex", diff --git a/Cargo.toml b/Cargo.toml index 2f463f7..b55e454 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,6 @@ resolver = "2" sp1-sdk = "2.0.0" sp1-zkvm = "2.0.0" sp1-helper = "2.0.0" -alloy-sol-types = "0.7.7" serde_json = { version = "1.0", default-features = false, features = ["alloc"] } serde = { version = "1.0", default-features = false, features = ["derive"] } clap = { version = "4.0", features = ["derive", "env"] } diff --git a/README.md b/README.md index 9fbeaec..8da7129 100644 --- a/README.md +++ b/README.md @@ -37,35 +37,6 @@ cd script cargo run --release -- --prove ``` -### Generate an EVM-Compatible Proof - -> [!WARNING] -> You will need at least 128GB RAM to generate a Groth16 or PLONK proof. - -To generate a proof that is small enough to be verified on-chain and verifiable by the EVM: - -```sh -cd script -cargo run --release --bin evm -- --system groth16 -``` - -this will generate a Groth16 proof. If you want to generate a PLONK proof, run the following command: - -```sh -cargo run --release --bin evm -- --system plonk -``` - -These commands will also generate fixtures that can be used to test the verification of SP1 zkVM proofs -inside Solidity. - -### Retrieve the Verification Key - -To retrieve your `programVKey` for your on-chain contract, run the following command: - -```sh -cargo prove vkey --elf elf/riscv32im-succinct-zkvm-elf -``` - ## Using the Prover Network We highly recommend using the Succinct prover network for any non-trivial programs or benchmarking purposes. For more information, see the [setup guide](https://docs.succinct.xyz/generating-proofs/prover-network.html). @@ -79,9 +50,8 @@ cp .env.example .env Then, set the `SP1_PROVER` environment variable to `network` and set the `SP1_PRIVATE_KEY` environment variable to your whitelisted private key. -For example, to generate an EVM-compatible proof using the prover network, run the following -command: +To generate a proof, run the following command: ```sh -SP1_PROVER=network SP1_PRIVATE_KEY=... cargo run --release --bin evm +SP1_PROVER=network SP1_PRIVATE_KEY=... cargo run --release ``` diff --git a/contracts/.gitignore b/contracts/.gitignore deleted file mode 100644 index 59ae5b1..0000000 --- a/contracts/.gitignore +++ /dev/null @@ -1,15 +0,0 @@ -# Compiler files -cache/ -out/ - -# Ignores development broadcast logs -/broadcast -/broadcast/*/11155111/ -/broadcast/*/31337/ -/broadcast/**/dry-run/ - -# Docs -docs/ - -# Dotenv file -.env diff --git a/contracts/README.md b/contracts/README.md deleted file mode 100644 index 02f860a..0000000 --- a/contracts/README.md +++ /dev/null @@ -1,61 +0,0 @@ -# SP1 Project Template Contracts - -This is a template for writing a contract that uses verification of [SP1](https://github.com/succinctlabs/sp1) PlonK proofs onchain using the [SP1VerifierGateway](https://github.com/succinctlabs/sp1-contracts/blob/main/contracts/src/SP1VerifierGateway.sol). - -## Requirements - -- [Foundry](https://book.getfoundry.sh/getting-started/installation) - -## Test - -```sh -forge test -v -``` - -## Deployment - -#### Step 1: Set the `VERIFIER` environment variable - -Find the address of the `verifer` to use from the [deployments](https://github.com/succinctlabs/sp1-contracts/tree/main/contracts/deployments) list for the chain you are deploying to. Set it to the `VERIFIER` environment variable, for example: - -```sh -VERIFIER=0x3B6041173B80E77f038f3F2C0f9744f04837185e -``` - -Note: you can use either the [SP1VerifierGateway](https://github.com/succinctlabs/sp1-contracts/blob/main/contracts/src/SP1VerifierGateway.sol) or a specific version, but it is highly recommended to use the gateway as this will allow you to use different versions of SP1. - -#### Step 2: Set the `PROGRAM_VKEY` environment variable - -Find your program verification key by going into the `../script` directory and running `RUST_LOG=info cargo run --package fibonacci-script --bin vkey --release`, which will print an output like: - -> Program Verification Key: 0x00620892344c310c32a74bf0807a5c043964264e4f37c96a10ad12b5c9214e0e - -Then set the `PROGRAM_VKEY` environment variable to the output of that command, for example: - -```sh -PROGRAM_VKEY=0x00620892344c310c32a74bf0807a5c043964264e4f37c96a10ad12b5c9214e0e -``` - -#### Step 3: Deploy the contract - -Fill out the rest of the details needed for deployment: - -```sh -RPC_URL=... -``` - -```sh -PRIVATE_KEY=... -``` - -Then deploy the contract to the chain: - -```sh -forge create src/Fibonacci.sol:Fibonacci --rpc-url $RPC_URL --private-key $PRIVATE_KEY --constructor-args $VERIFIER $PROGRAM_VKEY -``` - -It can also be a good idea to verify the contract when you deploy, in which case you would also need to set `ETHERSCAN_API_KEY`: - -```sh -forge create src/Fibonacci.sol:Fibonacci --rpc-url $RPC_URL --private-key $PRIVATE_KEY --constructor-args $VERIFIER $PROGRAM_VKEY --verify --verifier etherscan --etherscan-api-key $ETHERSCAN_API_KEY -``` diff --git a/contracts/foundry.toml b/contracts/foundry.toml deleted file mode 100644 index 9430db1..0000000 --- a/contracts/foundry.toml +++ /dev/null @@ -1,7 +0,0 @@ -[profile.default] -src = "src" -out = "out" -libs = ["lib"] -fs_permissions = [{ access = "read-write", path = "./" }] - -# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options diff --git a/contracts/lib/forge-std b/contracts/lib/forge-std deleted file mode 160000 index c28115d..0000000 --- a/contracts/lib/forge-std +++ /dev/null @@ -1 +0,0 @@ -Subproject commit c28115db8d90ebffb41953cf83aac63130f4bd40 diff --git a/contracts/lib/sp1-contracts b/contracts/lib/sp1-contracts deleted file mode 160000 index af1ae09..0000000 --- a/contracts/lib/sp1-contracts +++ /dev/null @@ -1 +0,0 @@ -Subproject commit af1ae093ef8a8f68b022aa8f0f7ad9ffd94aa6fb diff --git a/contracts/remappings.txt b/contracts/remappings.txt deleted file mode 100644 index 4483f06..0000000 --- a/contracts/remappings.txt +++ /dev/null @@ -1 +0,0 @@ -@sp1-contracts/=./lib/sp1-contracts/contracts/src/ \ No newline at end of file diff --git a/contracts/src/Fibonacci.sol b/contracts/src/Fibonacci.sol deleted file mode 100644 index f66a01f..0000000 --- a/contracts/src/Fibonacci.sol +++ /dev/null @@ -1,44 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.20; - -import {ISP1Verifier} from "@sp1-contracts/ISP1Verifier.sol"; - -struct PublicValuesStruct { - uint32 n; - uint32 a; - uint32 b; -} - -/// @title Fibonacci. -/// @author Succinct Labs -/// @notice This contract implements a simple example of verifying the proof of a computing a -/// fibonacci number. -contract Fibonacci { - /// @notice The address of the SP1 verifier contract. - /// @dev This can either be a specific SP1Verifier for a specific version, or the - /// SP1VerifierGateway which can be used to verify proofs for any version of SP1. - /// For the list of supported verifiers on each chain, see: - /// https://github.com/succinctlabs/sp1-contracts/tree/main/contracts/deployments - address public verifier; - - /// @notice The verification key for the fibonacci program. - bytes32 public fibonacciProgramVKey; - - constructor(address _verifier, bytes32 _fibonacciProgramVKey) { - verifier = _verifier; - fibonacciProgramVKey = _fibonacciProgramVKey; - } - - /// @notice The entrypoint for verifying the proof of a fibonacci number. - /// @param _proofBytes The encoded proof. - /// @param _publicValues The encoded public values. - function verifyFibonacciProof(bytes calldata _publicValues, bytes calldata _proofBytes) - public - view - returns (uint32, uint32, uint32) - { - ISP1Verifier(verifier).verifyProof(fibonacciProgramVKey, _publicValues, _proofBytes); - PublicValuesStruct memory publicValues = abi.decode(_publicValues, (PublicValuesStruct)); - return (publicValues.n, publicValues.a, publicValues.b); - } -} diff --git a/contracts/src/fixtures/groth16-fixture.json b/contracts/src/fixtures/groth16-fixture.json deleted file mode 100644 index fd07864..0000000 --- a/contracts/src/fixtures/groth16-fixture.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "a": 6765, - "b": 10946, - "n": 20, - "vkey": "0x00a22fd3af2b4ec77de39ec50023cf6c2b64984d0156a3df1984262984ef71bf", - "publicValues": "0x00000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000001a6d0000000000000000000000000000000000000000000000000000000000002ac2", - "proof": "0x6a2906ac23e4480564d34dfcf7005e26d0cc0d530a1b5029dfc2152f14b97841cbcb738a03a407d4104ced929ce6474501da24e7e1e5267ea0e1b2ace137c28a053febcf1fa039f5f964c2ed7f82ca582574f761af8c2541a6991d85190450c02131539f03747b06260cd8bff401728a923fc6f980c7fa8bed4a9de3c9821f62328c243e003d00cd3b8eb153f1df4e5e9f7fbfa9b81ac4f03d3bbbfdb8204ec9e25b520016d69ba1c93b90d86da73111123388195d65ed14c8241cf8a4390c416bdabffd165b92debad53ca3db689e06e533131364e1d9652aba537d689321fac966d32e1d2e7714067217b2cd5a3d1df81ece476eec70bf682164102de5e8d652221d3d" -} \ No newline at end of file diff --git a/contracts/src/fixtures/plonk-fixture.json b/contracts/src/fixtures/plonk-fixture.json deleted file mode 100644 index 0d381e7..0000000 --- a/contracts/src/fixtures/plonk-fixture.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "a": 6765, - "b": 10946, - "n": 20, - "vkey": "0x00a22fd3af2b4ec77de39ec50023cf6c2b64984d0156a3df1984262984ef71bf", - "publicValues": "0x00000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000001a6d0000000000000000000000000000000000000000000000000000000000002ac2", - "proof": "0x4aca240a10e48d547d454301bd5384e07852d60e6ba0f115f65a60f4443c4cee1348b695086b30d01c43bbd73a4026a1e2085b206e16f2e996ea101e35e116501fbe8c70003cef43831a390fc7d551058c6b186bb29597eb5d4981d72453a1c48c9ef3b90f1571cc98e55ebac36e5fecb14f7840419de70cd9a4c5c9692ab35b7222203c0f146200c674ffde1bb21feded6250d54d1bbbae633d1c4d070ce21384187ee60e87d43ed7a580181615ca48a5dfa0704ed429f690e0cb8f4382a16fc911d24623dc90465ed642716ffcb0cd53ff149273f5c511129f029f4072371572cf3bcc1e53ace42dbd6890319597f31401c96287eac3300c5930cfc150e9d81bf1ee740e5b7e8ed8e8e592d9f779f35e2be0208e209ff9b728ff3825b1a9b7aef826a525f9d755f96ec2e68a88b4da246b425ebd4af4c3041ea12c5e4c44ed9e83a4ad069f674517a08ec7bcda9c7672978a2fd056956c5f48e9b8f348028335aee6db1c105a306b0d03f309f406ceb824c72133f186a615849b950ab9baec61bff812034bb448565d0b789adeaaead1e5c07b9224d081a9c42dbe3bf0d66889dda3d11fc11c3465d952f797cf9a26341edbfb868de65bb51cc3e4445ca084e120c4b406f30b78f720ff785e6592ad218f71b4382cd6cfbb4d653a64efea019e5c705e1e15f9034b85b02b5c65d5c4a79143982b596bb1dc49d2799c581906686042780ca366da2fed051649bfa7fd0a350bd5953db403e2b638d992288cf2df85adba29442fd8f5fe7db31bd22002ba1e9bf59d5fe848dc66242191c070ddc1ba6e9d16affcb406d1b765024293ee018e48a79b81dc26c3219a7c76a91071fc1abb67096561ba7cb68c5c7f0eb82c3aed59c413abb7cad01a2ad2c6a3cbc87700f01716ecb7c7b42f6d5cb2dd20c5ec528236fa0220500e07daf5138a8ede04ee206f02912f9571ef693a699811a9bcbe544a5ab6e97e61dcff677e631f50126868460715fda230220afce3ca030a8b561a0863d2a1e926f8b07c4846e858690f593a1713eb06cf21f1a3962ab2a9086c4d8761dcf0d8c2c7dcbc35ade5b7be2848ff1861e824799ace0e4ea39031ff336e2005373d35a9549e5d9cc4191f337f407f0fc4ce65a7484686747f6de7914eef3bdca97cf4ca0013c3af4097e7d768146a1bfa12db65d818ecae20612f5e14d71f608bd19da830794b7ca09ff5e00b0722" -} \ No newline at end of file diff --git a/contracts/test/Fibonacci.t.sol b/contracts/test/Fibonacci.t.sol deleted file mode 100644 index 9e065f1..0000000 --- a/contracts/test/Fibonacci.t.sol +++ /dev/null @@ -1,58 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.20; - -import {Test, console} from "forge-std/Test.sol"; -import {stdJson} from "forge-std/StdJson.sol"; -import {Fibonacci} from "../src/Fibonacci.sol"; -import {SP1VerifierGateway} from "@sp1-contracts/SP1VerifierGateway.sol"; - -struct SP1ProofFixtureJson { - uint32 a; - uint32 b; - uint32 n; - bytes proof; - bytes publicValues; - bytes32 vkey; -} - -contract FibonacciTest is Test { - using stdJson for string; - - address verifier; - Fibonacci public fibonacci; - - function loadFixture() public view returns (SP1ProofFixtureJson memory) { - string memory root = vm.projectRoot(); - string memory path = string.concat(root, "/src/fixtures/plonk-fixture.json"); - string memory json = vm.readFile(path); - bytes memory jsonBytes = json.parseRaw("."); - return abi.decode(jsonBytes, (SP1ProofFixtureJson)); - } - - function setUp() public { - SP1ProofFixtureJson memory fixture = loadFixture(); - - verifier = address(new SP1VerifierGateway(address(1))); - fibonacci = new Fibonacci(verifier, fixture.vkey); - } - - function test_ValidFibonacciProof() public { - SP1ProofFixtureJson memory fixture = loadFixture(); - - vm.mockCall(verifier, abi.encodeWithSelector(SP1VerifierGateway.verifyProof.selector), abi.encode(true)); - - (uint32 n, uint32 a, uint32 b) = fibonacci.verifyFibonacciProof(fixture.publicValues, fixture.proof); - assert(n == fixture.n); - assert(a == fixture.a); - assert(b == fixture.b); - } - - function testFail_InvalidFibonacciProof() public view { - SP1ProofFixtureJson memory fixture = loadFixture(); - - // Create a fake proof. - bytes memory fakeProof = new bytes(fixture.proof.length); - - fibonacci.verifyFibonacciProof(fixture.publicValues, fakeProof); - } -} diff --git a/elf/riscv32im-succinct-zkvm-elf b/elf/riscv32im-succinct-zkvm-elf index 92b2fb3..9818e60 100755 Binary files a/elf/riscv32im-succinct-zkvm-elf and b/elf/riscv32im-succinct-zkvm-elf differ diff --git a/lib/Cargo.toml b/lib/Cargo.toml index 11f9527..f744b48 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2021" [dependencies] -alloy-sol-types = { workspace = true } +serde = { workspace = true } \ No newline at end of file diff --git a/lib/src/lib.rs b/lib/src/lib.rs index f4b1779..76de78b 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -1,12 +1,11 @@ -use alloy_sol_types::sol; +use serde::{Deserialize, Serialize}; -sol! { - /// The public values encoded as a struct that can be easily deserialized inside Solidity. - struct PublicValuesStruct { - uint32 n; - uint32 a; - uint32 b; - } +/// The public values encoded as a struct. +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct PublicValuesStruct { + pub n: u32, + pub a: u32, + pub b: u32, } /// Compute the n'th fibonacci number (wrapping around on overflows), using normal Rust code. diff --git a/program/Cargo.toml b/program/Cargo.toml index cb6fcb9..426b0e1 100644 --- a/program/Cargo.toml +++ b/program/Cargo.toml @@ -4,6 +4,5 @@ name = "fibonacci-program" edition = "2021" [dependencies] -alloy-sol-types = { workspace = true } sp1-zkvm = { workspace = true } fibonacci-lib = { workspace = true } diff --git a/program/src/main.rs b/program/src/main.rs index fc35d4a..35608e3 100644 --- a/program/src/main.rs +++ b/program/src/main.rs @@ -8,7 +8,6 @@ #![no_main] sp1_zkvm::entrypoint!(main); -use alloy_sol_types::SolType; use fibonacci_lib::{fibonacci, PublicValuesStruct}; pub fn main() { @@ -22,9 +21,9 @@ pub fn main() { let (a, b) = fibonacci(n); // Encode the public values of the program. - let bytes = PublicValuesStruct::abi_encode(&PublicValuesStruct { n, a, b }); + let bytes = PublicValuesStruct { n, a, b }; // Commit to the public values of the program. The final proof will have a commitment to all the // bytes that were committed to. - sp1_zkvm::io::commit_slice(&bytes); + sp1_zkvm::io::commit(&bytes); } diff --git a/script/Cargo.toml b/script/Cargo.toml index c8b3512..06cc267 100644 --- a/script/Cargo.toml +++ b/script/Cargo.toml @@ -8,10 +8,6 @@ default-run = "fibonacci" name = "fibonacci" path = "src/bin/main.rs" -[[bin]] -name = "evm" -path = "src/bin/evm.rs" - [dependencies] sp1-sdk = { workspace = true } serde_json = { workspace = true } @@ -19,7 +15,6 @@ serde = { workspace = true } clap = { workspace = true } tracing = { workspace = true } hex = { workspace = true } -alloy-sol-types = { workspace = true } fibonacci-lib = { workspace = true } [build-dependencies] diff --git a/script/src/bin/evm.rs b/script/src/bin/evm.rs deleted file mode 100644 index f694f61..0000000 --- a/script/src/bin/evm.rs +++ /dev/null @@ -1,126 +0,0 @@ -//! An end-to-end example of using the SP1 SDK to generate a proof of a program that can have an -//! EVM-Compatible proof generated which can be verified on-chain. -//! -//! You can run this script using the following command: -//! ```shell -//! RUST_LOG=info cargo run --release --bin evm -- --system groth16 -//! ``` -//! or -//! ```shell -//! RUST_LOG=info cargo run --release --bin evm -- --system plonk -//! ``` - -use alloy_sol_types::SolType; -use clap::{Parser, ValueEnum}; -use fibonacci_lib::PublicValuesStruct; -use serde::{Deserialize, Serialize}; -use sp1_sdk::{HashableKey, ProverClient, SP1ProofWithPublicValues, SP1Stdin, SP1VerifyingKey}; -use std::path::PathBuf; - -/// The ELF (executable and linkable format) file for the Succinct RISC-V zkVM. -pub const FIBONACCI_ELF: &[u8] = include_bytes!("../../../elf/riscv32im-succinct-zkvm-elf"); - -/// The arguments for the EVM command. -#[derive(Parser, Debug)] -#[clap(author, version, about, long_about = None)] -struct EVMArgs { - #[clap(long, default_value = "20")] - n: u32, - #[clap(long, value_enum, default_value = "groth16")] - system: ProofSystem, -} - -/// Enum representing the available proof systems -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum, Debug)] -enum ProofSystem { - Plonk, - Groth16, -} - -/// A fixture that can be used to test the verification of SP1 zkVM proofs inside Solidity. -#[derive(Debug, Clone, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -struct SP1FibonacciProofFixture { - a: u32, - b: u32, - n: u32, - vkey: String, - public_values: String, - proof: String, -} - -fn main() { - // Setup the logger. - sp1_sdk::utils::setup_logger(); - - // Parse the command line arguments. - let args = EVMArgs::parse(); - - // Setup the prover client. - let client = ProverClient::new(); - - // Setup the program. - let (pk, vk) = client.setup(FIBONACCI_ELF); - - // Setup the inputs. - let mut stdin = SP1Stdin::new(); - stdin.write(&args.n); - - println!("n: {}", args.n); - println!("Proof System: {:?}", args.system); - - // Generate the proof based on the selected proof system. - let proof = match args.system { - ProofSystem::Plonk => client.prove(&pk, stdin).plonk().run(), - ProofSystem::Groth16 => client.prove(&pk, stdin).groth16().run(), - } - .expect("failed to generate proof"); - - create_proof_fixture(&proof, &vk, args.system); -} - -/// Create a fixture for the given proof. -fn create_proof_fixture( - proof: &SP1ProofWithPublicValues, - vk: &SP1VerifyingKey, - system: ProofSystem, -) { - // Deserialize the public values. - let bytes = proof.public_values.as_slice(); - let PublicValuesStruct { n, a, b } = PublicValuesStruct::abi_decode(bytes, false).unwrap(); - - // Create the testing fixture so we can test things end-to-end. - let fixture = SP1FibonacciProofFixture { - a, - b, - n, - vkey: vk.bytes32().to_string(), - public_values: format!("0x{}", hex::encode(bytes)), - proof: format!("0x{}", hex::encode(proof.bytes())), - }; - - // The verification key is used to verify that the proof corresponds to the execution of the - // program on the given input. - // - // Note that the verification key stays the same regardless of the input. - println!("Verification Key: {}", fixture.vkey); - - // The public values are the values which are publicly committed to by the zkVM. - // - // If you need to expose the inputs or outputs of your program, you should commit them in - // the public values. - println!("Public Values: {}", fixture.public_values); - - // The proof proves to the verifier that the program was executed with some inputs that led to - // the give public values. - println!("Proof Bytes: {}", fixture.proof); - - // Save the fixture to a file. - let fixture_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../contracts/src/fixtures"); - std::fs::create_dir_all(&fixture_path).expect("failed to create fixture path"); - std::fs::write( - fixture_path.join(format!("{:?}-fixture.json", system).to_lowercase()), - serde_json::to_string_pretty(&fixture).unwrap(), - ) - .expect("failed to write fixture"); -} diff --git a/script/src/bin/main.rs b/script/src/bin/main.rs index 33089b1..2b9e0fd 100644 --- a/script/src/bin/main.rs +++ b/script/src/bin/main.rs @@ -10,7 +10,6 @@ //! RUST_LOG=info cargo run --release -- --prove //! ``` -use alloy_sol_types::SolType; use clap::Parser; use fibonacci_lib::PublicValuesStruct; use sp1_sdk::{ProverClient, SP1Stdin}; @@ -55,11 +54,11 @@ fn main() { if args.execute { // Execute the program - let (output, report) = client.execute(FIBONACCI_ELF, stdin).run().unwrap(); + let (mut output, report) = client.execute(FIBONACCI_ELF, stdin).run().unwrap(); println!("Program executed successfully."); // Read the output. - let decoded = PublicValuesStruct::abi_decode(output.as_slice(), true).unwrap(); + let decoded = output.read::(); let PublicValuesStruct { n, a, b } = decoded; println!("n: {}", n); println!("a: {}", a);