diff --git a/docs/architecture/adr-010.md b/docs/architecture/adr-010.md index 49ef38d7cf..678d3d01e8 100644 --- a/docs/architecture/adr-010.md +++ b/docs/architecture/adr-010.md @@ -16,7 +16,7 @@ App-chain specific logics can be embedded to the pre-compiled so that it could b ### Fork go-ethereum for stateful precompiled support One of the major difficulties in supporting pre-compiled is the lack of flexibility in geth for defining custom precompiled and its non-ability to modify the state. -We made the choice of forking geth and implement additional interfaces and logics so that app-chain can define its own precompiled. +We made the choice of forking geth and implement additional interfaces so that app-chain can define its own precompiled. The PR [#7](https://github.com/evmos/go-ethereum/pull/7) implements the ability to set custom precompiled to the EVM. while this PR [#10](https://github.com/evmos/go-ethereum/pull/10) allows the precompiled to modify the state (for stateful precompiled) @@ -26,9 +26,7 @@ In the future, we are planning to maintain the following fork permanently ### Implement pre-compiled for cosmos native module -We provide pre-compile for cosmos native module such as bank module. - -The input and output of methods are mapped with those defined cosmos native transactions +We provide pre-compiles for cosmos native module such as bank module. ```solidity @@ -41,10 +39,14 @@ interface IBankModule { ``` +The input and output of methods are mapped with those defined cosmos native transactions. +Because the precompiled is called at the evm layer, it uses the evm authentication instead of the cosmos authentication for transactions. +It is important to define for each precompiled module the range of action "authorized" for each request. +For the bank module, the precompiled is authenticated with `msg.sender` address. The smart contracts or users can only mint/burn cosmos coins denoted by the denom `evm/0x{msg.sender}` or transfer coins from the `0x{msg.sender}` account. -To call a precompiled, create an instance of the module interface with the precompiled address. -The methods are ABI encoded, and can be called directly as calling the function through the interface: +To call a precompiled from a smart contract, create an instance of the module interface with the precompiled address. +The methods are ABI encoded, and can be called directly as calling the function through the interface: ```solidity @@ -94,26 +96,33 @@ const ( -> TODO describe the change in go-relayer #### ICA -For ICA, we are following the same standard as for the cosmos module. -The ICA precompiled interface is defined by: + +The ICA precompiled interface is defined by : ```solidity interface IICAModule { event SubmitMsgsResult(uint64 seq); + function registerAccount(string calldata connectionID, string calldata version) external payable returns (bool); function queryAccount(string calldata connectionID, address addr) external view returns (string memory); function submitMsgs(string calldata connectionID, bytes calldata data, uint256 timeout) external payable returns (uint64); } ``` +The request is authenticated by `msg.sender` and it can only send request on behalf of this account. -The calldata in `submitMsgs` represents the cosmos proto-encoded msg to be sent to the destination app-chain. Only one msg is supported at the moment. +The calldata in `submitMsgs` represents the cosmos proto-encoded message to be sent to the destination app-chain. Only one message can be sent at the moment. -For example to call a bank transaction to another app-chain +For example to call a bank transaction to another app-chain : ```solidity -#todo -``` + function ICACallBank(string memory connectionID, uint256 timeout, params.....) public returns (uint64) { + msg = bankMsgSendProto.encode(params) + lastSeq = ica.submitMsgs(connectionID, msg, timeout); + return lastSeq; + } + +``` In case of ICA, it is also important to be able to track the result of the transaction `submitMsgs` so that the user or the smart contract can respond accordingly. The function `submitMsgs` returns a sequence number that can be used by the user or smart contract to track the state of the msg using the precompiled `ICACallback`.