-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib.rs
More file actions
88 lines (78 loc) · 2.58 KB
/
Copy pathlib.rs
File metadata and controls
88 lines (78 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//! Host-side prover for GenericCall resource logic.
//!
//! `GENERIC_CALL_ELF` and `GENERIC_CALL_ID` are placeholders. After building
//! the guest with the RISC0 toolchain (`cd crates/generic_call_circuit && cargo build`),
//! copy the output ELF to `elf/generic-call-guest.bin` and update `GENERIC_CALL_ID`
//! with the printed image ID.
pub use anoma_generic_call_witness::GenericCall;
use anoma_generic_call_witness::GenericCallWitness;
use anoma_rm_risc0::{
Digest, logic_proof::LogicProver, nullifier_key::NullifierKey, resource::Resource,
};
use hex::FromHex;
use lazy_static::lazy_static;
use serde::{Deserialize, Serialize};
pub const GENERIC_CALL_ELF: &[u8] = include_bytes!("../elf/generic-call-guest.bin");
lazy_static! {
pub static ref GENERIC_CALL_ID: Digest =
Digest::from_hex("de1d88738d93b2c67bcd7d2515e22a093bbf7f08ecd88ab24030c301a416621a")
.unwrap();
}
/// Wraps a `GenericCallWitness` and implements `LogicProver` so it can be used
/// for proof generation inside the RISC0 zkVM.
#[derive(Clone, Default, Deserialize, Serialize)]
pub struct GenericCallLogic {
pub witness: GenericCallWitness,
}
impl GenericCallLogic {
/// Logic for a consumed ephemeral GenericCall resource (e.g. the resource
/// representing the intent to execute EVM calls).
pub fn consumed_ephemeral_resource_logic(
resource: Resource,
action_tree_root: Digest,
nf_key: NullifierKey,
forwarder_addr: Vec<u8>,
calls: Vec<GenericCall>,
) -> Self {
Self {
witness: GenericCallWitness {
resource,
is_consumed: true,
action_tree_root,
nf_key: Some(nf_key),
forwarder_addr,
calls,
},
}
}
/// Logic for a created ephemeral GenericCall resource (balancing resource).
pub fn created_ephemeral_resource_logic(
resource: Resource,
action_tree_root: Digest,
forwarder_addr: Vec<u8>,
calls: Vec<GenericCall>,
) -> Self {
Self {
witness: GenericCallWitness {
resource,
is_consumed: false,
action_tree_root,
nf_key: None,
forwarder_addr,
calls,
},
}
}
}
impl LogicProver for GenericCallLogic {
type Witness = GenericCallWitness;
fn proving_key() -> &'static [u8] {
GENERIC_CALL_ELF
}
fn verifying_key() -> Digest {
*GENERIC_CALL_ID
}
fn witness(&self) -> &Self::Witness {
&self.witness
}
}