ovmi/predicates/
is_valid_signature.rs

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