Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIT generation from Application configurations #16

Open
Tracked by #17
jakehemmerle opened this issue Jul 19, 2023 · 0 comments
Open
Tracked by #17

WIT generation from Application configurations #16

jakehemmerle opened this issue Jul 19, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@jakehemmerle
Copy link
Contributor

jakehemmerle commented Jul 19, 2023

The only other option is to hand-code each WIT file and then generate types from it, which is needlessly tedious.

Let's use a simple EVM ACL whitelisting program as an example. In this case, the configuration for the ACL is quite literally just the ACL struct:

pub struct Acl<Address> {
    pub addresses: Vec<Address>,
    pub kind: AclKind,
    pub allow_null_recipient: bool,
}

Since we have implemented SatisfiableByArchitecture, the following evaluation logic is included in the Wasm blob:

impl SatisfiableForArchitecture<Evm> for Acl<<Evm as Architecture>::AddressRaw> {
    fn is_satisfied_by(
        self,
        tx: &<Evm as Architecture>::TransactionRequest,
    ) -> Result<(), CoreError> {
        if tx.to.is_none() {
            return match self.allow_null_recipient {
                true => Ok(()),
                false => Err(CoreError::Evaluation(
                    "Null recipients are not allowed.".to_string(),
                )),
            };
        }

        let converted_addresses: Vec<NameOrAddress> = self
            .addresses
            .into_iter()
            .map(|a| NameOrAddress::Address(H160::from(a)))
            .collect();

        match (
            converted_addresses.contains(&tx.to.clone().unwrap()),
            self.kind,
        ) {
            (true, AclKind::Allow) => Ok(()),
            (false, AclKind::Deny) => Ok(()),
            _ => Err(CoreError::Evaluation(
                "Transaction not allowed.".to_string(),
            )),
        }
    }
}

Before doing this, we should rewrite evaluation in an Architecture generic way eg.

impl <A: Architecture> SatisfiableForArchitecture<A> for Acl<A::AddressRaw> { ...

In this example program, we want to we want to generate a WIT file that includes a this Config (maybe record?) from the Acl and SatisfiableForArchitecture<Architecture>, resulting in ConfigBtc, ConfigEvm, etc.

package username:acl

use entropy:core

world acl {
  export evaluate: func(config: config-eth) -> result<_, error>
  export evaluate: func(config: config-btc) -> result<_, error>

  record config-eth {
    /// The preimage of the user's data under constraint evaulation (eg. RLP-encoded ETH transaction request).
    addresses: list<list<u8>>
    kind: (whatever WIT enum is)
    allow_null_recipient: bool
  }
   record config-btc {
    addresses: list<list<u8>>
    kind: (whatever WIT enum is)
    allow_null_recipient: bool
  }
... you get the idea

}

We should probably generate a WIT record and evaluate export from each SatisfiableForArchitecture monomorphic function (or whatever related trait is appropriate by then).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant