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

sip-0002: SIP EVM IBC Transfer proposal #1

Open
BoThe1K opened this issue Feb 5, 2024 · 0 comments
Open

sip-0002: SIP EVM IBC Transfer proposal #1

BoThe1K opened this issue Feb 5, 2024 · 0 comments

Comments

@BoThe1K
Copy link

BoThe1K commented Feb 5, 2024

SIP-0002 : SIP EVM IBC Transfer proposal

Number:  SIP-0002
Title:   SIP EVM IBC Transfer Proposal
Type:    Informational
Status:  Living
Authors: Bohdan Kurinnyi <[email protected]>
Created: 2024-01-05

Abstract

IBC Transfers allow to execution of transactions across different cosmos networks, mostly with the supported tokens inside of the blockchain. The proposal extends an opportunity for this type of transfer to use them more and in a more easy way, without a deeper understanding of internals.

Motivation

From the implementation for the prepay, we have an opportunity to support IBC transfers with corresponding opcode and perform as execution of IBC transfers via smart contracts. This will extend smart contract capabilities to bridge native STOS via different cosmos networks through the DApps.

Rational

EVM IBC Transfers provides an opportunity to interact with a single method through another smart contract in case of bridging assets to other cosmos chains. Currently, IBC is only available via standard cosmos functionality, but it is more complicated for th ddaps to be integrated because of:

  1. No atomic execution (should be done on server checks);
  2. Could not be executed via smart contracts (as there is no interaction between evm tx with cosmos tx as different handling)
  3. Gas prediction stability

I assume that some of the executions should be redone and used with a new evm.StateDB.GetKeestateDB() to have a snapshot revert in case of some step failure.

Body

NOTE: Not a final, so some params from these specs should be taken into account:
https://github.com/cosmos/ibc/blob/main/spec/app/ics-020-fungible-token-transfer/README.md
https://github.com/cosmos/ibc/blob/main/spec/app/ics-721-nft-transfer/README.md

One of the short examples that could be used to interact with IBC via solidity:

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.18;

import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";

import "./versions/Version0.sol";

contract IBCTransfer is Version0, OwnableUpgradeable {
    event IBCTransferCreated(
        bytes32 indexed channel,
        address indexed guy,
        address indexed dst,
        uint256 amt
    );

    // ----- proxy ------
    uint256[49] private __gap;

    // ===== fallbacks =====

    receive() external payable {}

    // Initialize function for proxy constructor. Must be used atomically
    function initialize() public initializer {
        // proxy inits
        __Context_init_unchained();
        __Ownable_init_unchained();
    }

    function ibc_transfer(bytes32 channel, address dst) external payable {
        uint256 amount = msg.value;
        require(amount != 0, "P: ZERO_AMOUNT");

        bytes32[3] memory input;
        input[0] = channel;
        input[1] = bytes32(uint256(uint160(msg.sender)) << 96);
        input[2] = bytes32(uint256(uint160(dst)) << 96);

        uint256[1] memory output;

        assembly {
            if iszero(call(not(0), 0xf2, amount, input, 0x60, output, 0x20)) {
                revert(0x0, 0x0)
            }
        }

        emit IBCTransferCreated(channel, msg.sender, dst, amount);
    }
}

In keeper_amplifier.go also corresponding opcode should be registered

var handlerNumToOpcode = map[int64]OpCode{
	0xf1: PREPAY,
	0xf2: IBC_TRANSFER, <-- FROM PROPOSAL
}

opcodes.go

// 0xdc range - closures. Stratos chain only
const (
	PREPAY              OpCode = 0xdc
	IBC_TRANSFER OpCode = 0xdd  <-- FROM PROPOSAL
)

in jump_table.go:

func newKeeperInstructionSet(instructionSet JumpTable) JumpTable {
	instructionSet[PREPAY] = &operation{
		execute:     opPrepay,
		constantGas: CallGasPrepay,
		dynamicGas:  gasPrepay,
		minStack:    minStack(6, 1),
		maxStack:    maxStack(6, 1),
		memorySize:  memoryPrepay,
	}
	<-- FROM PROPOSAL
	instructionSet[IBC_TRANSFER] = &operation{
		execute:     opIBCTransfer,
		constantGas: CallGasIBCTransfer,
		dynamicGas:  gasIBCTransfer,
		minStack:    minStack(6, 1),
		maxStack:    maxStack(6, 1),
		memorySize:  memoryIBCTransfer,
	}
	return validate(instructionSet)
}

and implementation instructions.go

func opIBCTransfer(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
    << -- impl
}

References

In continuation with: stratosnet/stratos-chain#337

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

No branches or pull requests

1 participant