zkvmc_sp1/
lib.rs

1mod addition;
2mod syscall;
3
4pub use addition::Sp1Addition;
5pub use syscall::sp1_syscall;
6use zkvmc_context::{CompileConfig, Context};
7use zkvmc_cranelift::CraneliftCompiler;
8use zkvmc_jit::JitCache;
9use zkvmc_rv32im::{load_program, undefined_handler, RrsFrontend};
10
11type Sp1Context = Context;
12
13pub fn new_jit_context(input: &[u8], cfg: Option<CompileConfig>) -> eyre::Result<Sp1Context> {
14    let (pc, image) = load_program(input)?;
15    let sp1_ctx = Sp1Addition::new(input);
16    let clif_compiler = CraneliftCompiler::<RrsFrontend>::default();
17    let cached_compiler = JitCache::new(clif_compiler);
18    Ok(Context::new(
19        Some(Box::new(cached_compiler)),
20        pc,
21        image,
22        sp1_ctx,
23        cfg,
24        Some(sp1_syscall),
25        None,
26        Some(undefined_handler),
27        None,
28    ))
29}
30
31pub fn new_interpreter_context(input: &[u8]) -> eyre::Result<Sp1Context> {
32    let (pc, image) = load_program(input)?;
33    let sp1_ctx = Sp1Addition::new(input);
34    Ok(Context::new(
35        None,
36        pc,
37        image,
38        sp1_ctx,
39        None,
40        Some(sp1_syscall),
41        None,
42        Some(undefined_handler),
43        None,
44    ))
45}