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

feat(ampd): add Stacks handlers with custom ITS logic & verify logic for contract deployments #676

Open
wants to merge 26 commits into
base: main
Choose a base branch
from

Conversation

raress96
Copy link
Contributor

@raress96 raress96 commented Nov 4, 2024

Description

Besides the normal stacks_verify_msg and stacks_verify_verifier_set handlers, we needed to add custom logic for Stacks in order to support integration with the ITS Hub:

  1. On Stacks, a smart contract can NOT deploy another smart contract

    • because the ITS contract needs to deploy NativeInterchainToken & Token Manager contracts, we need an untrusted 3rd party (eg: the Relayer or any other user account) that deploys the contracts first
    • then we need a way to verify that the deployed contracts are actually correct
    • we use the Axelar Network in order to verify that the deployed contracts have the correct code (on Stacks the code is interpreted and stored on chain), by first deploying reference contract implementations that Axelar Validators support Stacks need to add in their config
    • this flow is also triggered only in the case of a cross chain call from Stacks -> Stacks and from the Stacks ITS contract to itself
    • Axelar Network validators ONLY verify that the deployed contract code is correct and hasn't been modified at all. The Stacks ITS contract will further call the contract(s) and check if they have the required data stored (correct name/symbol/decimals, correct operator/minter etc)
  2. The Stacks ITS contract can NOT support ABI encoding

    • due to the fact that the Clarity smart contract language used for Stacks is non-turing complete, there was no way to implement ABI encoding/decoding on Stacks
    • because of that, for outbound contract calls from Stacks -> other blockchains, we will use the Axelar Validator code to translate the Clarity payload into ABI encoded payload
    • if there is a cross chain call from the Stacks ITS contract known to Axelar Validators supporting Stacks, then the payloadHash in the Message should be the hash of the ABI encoded payload, and NOT of the actual Clarity payload
    • the whole flow works like this:
      • the Relayer will convert the Clarity payload into ABI encoded payload and send it & the new payloadHash to the Axelar GMP API
      • when receiving this message, the Axelar Validators for Stacks will also convert the Clarity payload into ABI and check that the payloadHash is correct
      • this way the flow is supported out of the box, without any modifications needed on GMP API or other CosmWasm contracts

@raress96 raress96 requested a review from a team as a code owner November 4, 2024 08:40
Comment on lines 30 to 31
pub tx_id: Hash,
pub event_index: u32,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We updated voting verifier recently to emit the message_id string in the event instead and deprecated the old fields. Now you can directly decode into the typed MsgIdFormat, see example here. We'll be announcing this in the upcoming release's changelog. But you can update multiversX/stacks handlers to use this already. The new voting verifier contract will need to be deployed first so the new field is emitted for ampd to parse

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

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

Successfully merging this pull request may close these issues.

2 participants