risc0 / risc0-ethereum

Integration of the RISC Zero verifiable compute platform with Ethereum and EVM chains.
https://risczero.com
Apache License 2.0
84 stars 17 forks source link

Derive Clone for EvmEnv #204

Closed intoverflow closed 2 months ago

intoverflow commented 2 months ago

Why?

Imagine a situation where the host wants to generate multiple Steel proofs, all using the same RPC provider and block number. In this case, one might start by setting up an EthEvmEnv:

let env = EthEvmEnv::from_rpc(args.rpc_url, block_number).await?.with_chain_spec(chain_spec);

Later, each time we want to use Steel, we work from a fresh clone of env.

In this way, we can avoid passing the RPC and block number around (less verbose and maybe less error prone)

intoverflow commented 2 months ago

You make some very good points. I will think some more and get back to you.

intoverflow commented 2 months ago

this feature would only be useful in a case where multiple independent Steel proofs (but still referencing the same block) are to be generated within the same host file

This is exactly the situation I'm in. Basically, I need to do a bunch of separate Steel proofs, which I then roll-up into one proof. Right now I'm doing something like this:

let env = EthEvmEnv::from_rpc(args.rpc_url, BlockNumberOrTag::Number(args.block_number)).await?.with_chain_spec(chain_spec);

...

let foo_receipt = foo(env.clone(), foo_args)?;
let bar_receipt = bar(env.clone(), bar_args)?;

...

This saves me from needing to pass the RPC url, block number, chain_spec.

A builder would be just as good for this purpose, and also (as you point out) would be less error prone. I'll close this PR and maybe we can make the builder happen this week