Specification of the isaddrinternal and etx opcodes additions on Quai Network.
isaddrinternal
isaddrinternal
opcode is used to verify that an address is within a specific chain’s scope. It is most often used in contracts to determine whether the contract should initiate a traditional in-scope transaction or opt for an external transaction.Below is a simple implementation of the opcode in a ERC20 smart contract:transfer
function handles token transfers between two wallets. Inline assembly and the isaddrinternal
opcode are used to verify that an address is internal.If the check returns true, the function executes the transfer normally. If the check returns false, the transfer is not executed and the user is directed to utilize another function to complete a cross-chain transfer.etx
etx
opcode.A basic example of etx
implementation in the same ERC20 contract from the isaddrinternal can be seen below. The crossChainTransfer
function should be called if the check inside of transfer returns false.crossChainTransfer
utilizes an initial check to ensure that the destination is address is outside of the current context scope. The contract then executes in this fashion:Burn
amount
of tokens on the origin chain.Set Destination
toAddr
to the public key of a sister contract on the destination chain.Calculate Gas
totalGas
provided by the user and checks that the provided gas is sufficient to execute the transaction.Encode Data
encoded
.Build the ETX
etx
opcode via inline assembly.Send the ETX
isaddrinternal
and etx
opcodes provide key cross-chain functionality to
smart contracts deployed on Quai Network. The convert
opcode provides
functionality to convert tokens from Quai ledger to Qi ledger. They provide the
basis for contracts in different contexts to communicate and interact with each
other in a trustless fashion and allow developers to create multi-chain
applications that span the entire network.