diff --git a/cli/src/interface.rs b/cli/src/interface.rs index 22a96ceb..6494c61b 100644 --- a/cli/src/interface.rs +++ b/cli/src/interface.rs @@ -36,14 +36,14 @@ pub fn set(x: U256, post_state_digest: FixedBytes<32>, seal: Vec) -> Vec calldata.abi_encode() } -/// Input parser from string to an encoded `Vec` compatible with the zkVM and Bonsai. -pub fn parse_input(input: String) -> Result> { +/// Input serializer returning an encoded `Vec` compatible with the zkVM and Bonsai. +pub fn serialize_input(input: String) -> Result> { serialize(U256::from_str(&input)?) } -/// Parses a proof to extract the required output from the journal. -pub fn parse_output(proof: Proof) -> Result> { - let output = U256::abi_decode(&proof.journal, true)?; - let calldata = set(output, proof.post_state_digest, proof.seal); +/// Parses a proof to extract the required calldata. +pub fn calldata(proof: Proof) -> Result> { + let x = U256::abi_decode(&proof.journal, true)?; + let calldata = set(x, proof.post_state_digest, proof.seal); Ok(calldata) } diff --git a/cli/src/main.rs b/cli/src/main.rs index 5326160d..2ba01344 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -13,7 +13,7 @@ // limitations under the License. use anyhow::Result; -use interface::{parse_input, parse_output}; +use interface::{calldata, serialize_input}; use methods::IS_EVEN_ELF; use risc0_ethereum_sdk::cli; @@ -21,5 +21,5 @@ mod interface; fn main() -> Result<()> { env_logger::init(); - cli::run(IS_EVEN_ELF, parse_input, parse_output) + cli::run(IS_EVEN_ELF, serialize_input, calldata) } diff --git a/sdk/src/cli.rs b/sdk/src/cli.rs index 589920fc..74fb4783 100644 --- a/sdk/src/cli.rs +++ b/sdk/src/cli.rs @@ -64,14 +64,14 @@ enum Command { pub fn query( guest_binary: String, input: Option, - parser: fn(input: T) -> Result>, + serialize_input: fn(input: T) -> Result>, ) -> Result<()> { let elf = resolve_guest_entry(GUEST_LIST, &guest_binary)?; let image_id = compute_image_id(&elf)?; let output = match input { // Input provided. Return the Ethereum ABI encoded proof. Some(input) => { - let proof = prover::generate_proof(&elf, parser(input)?)?; + let proof = prover::generate_proof(&elf, serialize_input(input)?)?; hex::encode(proof.abi_encode()) } // No input. Return the Ethereum ABI encoded bytes32 image ID. @@ -91,8 +91,8 @@ pub fn publish( rpc_url: String, contract: String, input: T, - parse_input: fn(input: T) -> Result>, - parse_output: fn(proof: Proof) -> Result>, + serialize_input: fn(input: T) -> Result>, + calldata: fn(proof: Proof) -> Result>, ) -> Result<()> { let tx_sender = match std::env::var("ETH_WALLET_PRIVATE_KEY") { Ok(private_key) => Some(eth::TxSender::new( @@ -107,8 +107,8 @@ pub fn publish( if tx_sender.is_some() { println!("Private key is set; transaction will be sent"); } - let proof = prover::generate_proof(elf, parse_input(input)?)?; - let calldata = parse_output(proof)?; + let proof = prover::generate_proof(elf, serialize_input(input)?)?; + let calldata = calldata(proof)?; let runtime = tokio::runtime::Runtime::new()?; runtime.block_on(send_transaction(tx_sender, calldata))?; @@ -126,14 +126,14 @@ async fn send_transaction(tx_sender: Option, calldata: Vec) -> Res /// Run the CLI. pub fn run( elf: &[u8], - parse_input: fn(input: String) -> Result>, - parse_output: fn(proof: Proof) -> Result>, + serialize_input: fn(input: String) -> Result>, + calldata: fn(proof: Proof) -> Result>, ) -> Result<()> { match Command::parse() { Command::Query { guest_binary, input, - } => query(guest_binary, input, parse_input)?, + } => query(guest_binary, input, serialize_input)?, Command::Publish { chain_id, rpc_url, @@ -145,8 +145,8 @@ pub fn run( rpc_url, contract, input, - parse_input, - parse_output, + serialize_input, + calldata, )?, }