Skip to content

Commit

Permalink
add authentication details
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-nguy committed Oct 3, 2023
1 parent 300fac3 commit d8ffbaa
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions docs/architecture/adr-010.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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`.
Expand Down

0 comments on commit d8ffbaa

Please sign in to comment.