|
| 1 | +use aarm_core::compliance::ComplianceInstance; |
1 | 2 | use compliance_circuit::COMPLIANCE_GUEST_ID;
|
| 3 | +use k256::ProjectivePoint; |
2 | 4 | use risc0_zkvm::Receipt;
|
3 | 5 | use serde::{Deserialize, Serialize};
|
4 | 6 |
|
@@ -43,36 +45,68 @@ impl Action {
|
43 | 45 |
|
44 | 46 | true
|
45 | 47 | }
|
| 48 | + |
| 49 | + pub fn get_delta(&self) -> Vec<ProjectivePoint> { |
| 50 | + self.compliance_units |
| 51 | + .iter() |
| 52 | + .map(|receipt| { |
| 53 | + let instance: ComplianceInstance = receipt.journal.decode().unwrap(); |
| 54 | + instance.delta_projective() |
| 55 | + }) |
| 56 | + .collect() |
| 57 | + } |
| 58 | + |
| 59 | + pub fn get_delta_msg(&self) -> Vec<u8> { |
| 60 | + let mut msg = Vec::new(); |
| 61 | + for receipt in &self.compliance_units { |
| 62 | + let instance: ComplianceInstance = receipt.journal.decode().unwrap(); |
| 63 | + msg.extend_from_slice(&instance.delta_msg()); |
| 64 | + } |
| 65 | + msg |
| 66 | + } |
46 | 67 | }
|
47 | 68 |
|
48 |
| -#[test] |
49 |
| -fn test_action() { |
50 |
| - use aarm_core::{compliance::ComplianceWitness, constants::TREE_DEPTH, utils::GenericEnv}; |
| 69 | +#[cfg(test)] |
| 70 | +pub mod tests { |
| 71 | + use super::*; |
| 72 | + use aarm_core::{ |
| 73 | + compliance::ComplianceWitness, constants::TREE_DEPTH, delta_proof::DeltaWitness, |
| 74 | + utils::GenericEnv, |
| 75 | + }; |
51 | 76 | use bincode;
|
52 | 77 | use compliance_circuit::COMPLIANCE_GUEST_ELF;
|
53 | 78 | use risc0_zkvm::{default_prover, ExecutorEnv};
|
54 | 79 | use serde_bytes::ByteBuf;
|
55 | 80 |
|
56 |
| - let compliance_witness: ComplianceWitness<TREE_DEPTH> = |
57 |
| - ComplianceWitness::<TREE_DEPTH>::default(); |
58 |
| - let generic_env = GenericEnv { |
59 |
| - data: ByteBuf::from(bincode::serialize(&compliance_witness).unwrap()), |
60 |
| - }; |
| 81 | + pub fn create_an_action() -> (Action, DeltaWitness) { |
| 82 | + let compliance_witness: ComplianceWitness<TREE_DEPTH> = |
| 83 | + ComplianceWitness::<TREE_DEPTH>::default(); |
| 84 | + let generic_env = GenericEnv { |
| 85 | + data: ByteBuf::from(bincode::serialize(&compliance_witness).unwrap()), |
| 86 | + }; |
61 | 87 |
|
62 |
| - let env = ExecutorEnv::builder() |
63 |
| - .write(&generic_env) |
64 |
| - .unwrap() |
65 |
| - .build() |
66 |
| - .unwrap(); |
| 88 | + let env = ExecutorEnv::builder() |
| 89 | + .write(&generic_env) |
| 90 | + .unwrap() |
| 91 | + .build() |
| 92 | + .unwrap(); |
67 | 93 |
|
68 |
| - let prover = default_prover(); |
| 94 | + let prover = default_prover(); |
69 | 95 |
|
70 |
| - let receipt = prover.prove(env, COMPLIANCE_GUEST_ELF).unwrap().receipt; |
| 96 | + let receipt = prover.prove(env, COMPLIANCE_GUEST_ELF).unwrap().receipt; |
71 | 97 |
|
72 |
| - let compliance_units = vec![receipt.clone()]; |
73 |
| - let logic_proofs = vec![receipt]; |
| 98 | + let compliance_units = vec![receipt.clone()]; |
| 99 | + let logic_proofs = vec![receipt]; |
74 | 100 |
|
75 |
| - let action = Action::new(compliance_units, logic_proofs); |
| 101 | + let action = Action::new(compliance_units, logic_proofs); |
| 102 | + assert!(action.verify()); |
76 | 103 |
|
77 |
| - assert!(action.verify()); |
| 104 | + let delta_witness = DeltaWitness::from_scalars(&[compliance_witness.rcv]); |
| 105 | + (action, delta_witness) |
| 106 | + } |
| 107 | + |
| 108 | + #[test] |
| 109 | + fn test_action() { |
| 110 | + let _ = create_an_action(); |
| 111 | + } |
78 | 112 | }
|
0 commit comments