Skip to content

Commit 47daa4e

Browse files
committed
add authentication details
1 parent 300fac3 commit 47daa4e

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

docs/architecture/adr-010.md

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ App-chain specific logics can be embedded to the pre-compiled so that it could b
1616
### Fork go-ethereum for stateful precompiled support
1717

1818
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.
19-
We made the choice of forking geth and implement additional interfaces and logics so that app-chain can define its own precompiled.
19+
We made the choice of forking geth and implement additional interfaces so that app-chain can define its own precompiled.
2020

2121
The PR [#7](https://github.com/evmos/go-ethereum/pull/7) implements the ability to set custom precompiled to the EVM.
2222
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
2626

2727
### Implement pre-compiled for cosmos native module
2828

29-
We provide pre-compile for cosmos native module such as bank module.
30-
31-
The input and output of methods are mapped with those defined cosmos native transactions
29+
We provide pre-compiles for cosmos native module such as bank module.
3230

3331
```solidity
3432
@@ -41,10 +39,14 @@ interface IBankModule {
4139
4240
4341
```
42+
The input and output of methods are mapped with those defined cosmos native transactions.
43+
Because the precompiled is called at the evm layer, it uses the evm authentication instead of the cosmos authentication for transactions.
44+
It is important to define for each precompiled module the range of action "authorized" for each request.
45+
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.
4446

45-
To call a precompiled, create an instance of the module interface with the precompiled address.
46-
The methods are ABI encoded, and can be called directly as calling the function through the interface:
4747

48+
To call a precompiled from a smart contract, create an instance of the module interface with the precompiled address.
49+
The methods are ABI encoded, and can be called directly as calling the function through the interface:
4850

4951
```solidity
5052
@@ -94,26 +96,33 @@ const (
9496
-> TODO describe the change in go-relayer
9597

9698
#### ICA
97-
For ICA, we are following the same standard as for the cosmos module.
98-
The ICA precompiled interface is defined by:
99+
100+
The ICA precompiled interface is defined by :
99101

100102
```solidity
101103
interface IICAModule {
102104
event SubmitMsgsResult(uint64 seq);
105+
103106
function registerAccount(string calldata connectionID, string calldata version) external payable returns (bool);
104107
function queryAccount(string calldata connectionID, address addr) external view returns (string memory);
105108
function submitMsgs(string calldata connectionID, bytes calldata data, uint256 timeout) external payable returns (uint64);
106109
}
107110
```
111+
The request is authenticated by `msg.sender` and it can only send request on behalf of this account.
108112

109-
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.
113+
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.
110114

111-
For example to call a bank transaction to another app-chain
115+
For example to call a bank transaction to another app-chain :
112116

113117
```solidity
114-
#todo
115-
```
116118
119+
function ICACallBank(string memory connectionID, uint256 timeout, params.....) public returns (uint64) {
120+
msg = bankMsgSendProto.encode(params)
121+
lastSeq = ica.submitMsgs(connectionID, msg, timeout);
122+
return lastSeq;
123+
}
124+
125+
```
117126

118127
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.
119128
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`.

0 commit comments

Comments
 (0)