Skip to main content

ovmi/predicates/
verify_inclusion.rs

1use crate::executor::*;
2use crate::predicates::*;
3
4pub struct VerifyInclusionPredicate<'a, Ext: ExternalCall> {
5    pub ext: &'a Ext,
6}
7
8impl<'a, Ext: ExternalCall> AtomicPredicateInterface<AddressOf<Ext>>
9    for VerifyInclusionPredicate<'a, Ext>
10{
11    fn decide(&self, inputs: Vec<Vec<u8>>) -> ExecResult<AddressOf<Ext>> {
12        require!(inputs.len() > 4);
13        let address = Ext::bytes_to_address(&inputs[1])?;
14        Ok(self.ext.ext_verify_inclusion_with_root(
15            Ext::hash_of(&inputs[0]),
16            address,
17            &inputs[2][..], // range
18            &inputs[3][..], // inclusionProof
19            &inputs[4][..], // bytes32
20        ))
21    }
22}
23impl<'a, Ext: ExternalCall> AtomicHelperInterface<AddressOf<Ext>>
24    for VerifyInclusionPredicate<'a, Ext>
25{
26    type Hash = HashOf<Ext>;
27    fn ext_address(&self) -> AddressOf<Ext> {
28        self.ext.ext_address()
29    }
30    fn ext_set_predicate_decision(
31        &self,
32        game_id: Self::Hash,
33        decision: bool,
34    ) -> ExecResult<AddressOf<Ext>> {
35        self.ext.ext_set_predicate_decision(game_id, decision)
36    }
37    fn ext_get_property_id(&self, property: &Property<AddressOf<Ext>>) -> Self::Hash {
38        self.ext.ext_get_property_id(property)
39    }
40}
41
42impl<'a, Ext: ExternalCall> DecidablePredicateInterface<AddressOf<Ext>>
43    for VerifyInclusionPredicate<'a, Ext>
44{
45    fn decide_with_witness(
46        &self,
47        inputs: Vec<Vec<u8>>,
48        _witness: Vec<Vec<u8>>,
49    ) -> ExecResult<AddressOf<Ext>> {
50        Self::decide(self, inputs)
51    }
52}
53
54impl<'a, Ext: ExternalCall> BaseAtomicPredicateInterface<AddressOf<Ext>>
55    for VerifyInclusionPredicate<'a, Ext>
56{
57}