Skip to content

Commit 32944bf

Browse files
committed
tweak
1 parent 6645ca8 commit 32944bf

File tree

3 files changed

+26
-47
lines changed

3 files changed

+26
-47
lines changed

protocol-units/zkfp/eth-zk/host/src/compiler.rs

+25-15
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,30 @@
1-
use std::path::Path;
2-
31
use anyhow::Result;
2+
use serde::Serialize;
3+
use std::path::PathBuf;
44

5-
pub fn compile_units(s: &str) -> Result<Vec<()>> {
6-
Ok(vec![])
7-
}
5+
use foundry_compilers::{info::ContractInfo, Artifact, Project, ProjectCompileOutput, ProjectPathsConfig};
86

9-
fn expect_contracts(units: impl IntoIterator<Item = ()>) -> impl Iterator<Item = Result<()>> {
10-
units.into_iter().map(|_| Ok(()))
11-
}
7+
/// Makes a foo function that is compatible with the expectations of the guest code.
8+
pub fn compile_foo() -> Vec<u8> {
9+
let root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
10+
let paths = ProjectPathsConfig::builder()
11+
.sources(root.join("contracts"))
12+
.build()
13+
.unwrap();
14+
let project = Project::builder()
15+
.paths(paths)
16+
.no_artifacts()
17+
.build()
18+
.unwrap();
1219

13-
pub fn compile_contracts_in_file(_path: &Path) -> Result<Vec<()>> {
14-
Ok(vec![])
20+
let compiled = project.compile().unwrap();
21+
let info = ContractInfo::new("contracts/Foo.sol:Foo");
22+
let bytes = compiled
23+
.find_contract(info)
24+
.expect("Could not find contract")
25+
.get_bytecode_bytes()
26+
.unwrap()
27+
.to_vec();
28+
println!("Compiled foo: {:?}", bytes);
29+
bytes
1530
}
16-
17-
#[allow(dead_code)]
18-
pub fn as_contract(_unit: ()) -> () {
19-
()
20-
}

protocol-units/zkfp/eth-zk/host/src/compiler_examples.rs

-30
This file was deleted.

protocol-units/zkfp/eth-zk/host/src/main.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// These constants represent the RISC-V ELF and the image ID generated by risc0-build.
22
// The ELF is used for proving and the ID is used for verification.
33
pub mod compiler;
4-
pub mod compiler_examples;
54
use methods::{GUEST_ELF, GUEST_ID};
65
use risc0_zkvm::{default_prover, ExecutorEnv};
76

@@ -24,7 +23,7 @@ fn main() {
2423
// ExecutorEnvBuilder::build().
2524

2625
// For example:
27-
let input: Vec<u8> = compiler_examples::return_u64();
26+
let input: Vec<u8> = compiler::compile_foo();
2827
let env = ExecutorEnv::builder()
2928
.write(&input)
3029
.unwrap()

0 commit comments

Comments
 (0)