Skip to content
This repository was archived by the owner on Feb 18, 2025. It is now read-only.

Commit b46d7bc

Browse files
committed
TIP 51
1 parent b0590b7 commit b46d7bc

File tree

1 file changed

+135
-0
lines changed

1 file changed

+135
-0
lines changed

tips/TIP-0051/tip-0051.md

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
---
2+
tip: 51
3+
title: ISC request Output metadata encoding
4+
description: describes the encoding to send request outputs to an ISC chain
5+
author: Jorge Silva (@jorgemmsilva) <[email protected]>
6+
status: Draft
7+
type: Standards
8+
layer: L2 Smart Contracts
9+
created: 2023-09-27
10+
requires: None
11+
replaces: None
12+
---
13+
14+
## Summary
15+
16+
This document describes the encoding of an ISC request to be included in a request output Metadata feature.
17+
18+
## Motivation
19+
20+
In order to interact with ISC chains using L1 output requests, the metadata for a request must be specified in the Metadata feature of the created output.
21+
22+
## Specification
23+
24+
(LE stands for Little Endian, BE stands for Big Endian.)
25+
26+
### Request Metadata
27+
28+
Encoding of the request metadata follows the following structure, in strict order:
29+
30+
| Description | Type | Encoding |
31+
| ---------------- | ---------------- | --------------------------------------------------------------------------------- |
32+
| SenderContract | ContractIdentity | [custom](./###ContractIdentity) |
33+
| TargetContract | HName (uint32) | LE encoding uint32 (4 bytes) |
34+
| TargetEntryPoint | HName (uint32) | LE encoding uint32 (4 bytes) |
35+
| Params | Dictionary | [custom](./###Dictionary) |
36+
| Allowance | Assets | [custom](./###Assets) |
37+
| GasBudget | uint64 | LE encoding uint64 (8 bytes) - Value +1 <br>(1 must be encoded as 2, 3 as 4 ,etc) |
38+
39+
### ContractIdentity
40+
41+
Is used to identify a contract on a given chain (for the time being, contracts can only be of type `EVM` or `ISC`).
42+
43+
When sending requests from non-chain identities (regular user wallet), the `ContractIdentity` should always be `null`.
44+
45+
There are 3 types of `ContractIdentity`:
46+
47+
- `null` - encoded as a single Kind `0` byte
48+
- `EVM` - encoded as a Kind byte `1`, followed by the EVM address (20 bytes)
49+
- `ISC` - encoded as a kind byte `2`, followed by an uint32 LE encoding (4 bytes)
50+
51+
### Dictionary
52+
53+
A dictionary is a set of Key/Value pairs.
54+
Must be encoded in the following way:
55+
56+
- Length Prefix (number of kv pairs) using [Optimized Size Encode](https://github.com/iotaledger/wasp/blob/c362291b053f70c9b14a16961dd74b3b4176bba5/packages/util/rwutil/convert.go#L108-L137)
57+
- Each kv pair: [
58+
- `Key` bytes, prefixed with size in [Optimized Size Encode](https://github.com/iotaledger/wasp/blob/c362291b053f70c9b14a16961dd74b3b4176bba5/packages/util/rwutil/convert.go#L108-L137)
59+
- \+ `Value` bytes prefixed with size in [Optimized Size Encode](https://github.com/iotaledger/wasp/blob/c362291b053f70c9b14a16961dd74b3b4176bba5/packages/util/rwutil/convert.go#L108-L137)]
60+
61+
### Assets
62+
63+
The Assets encoding starts with a bitmask:
64+
65+
```go
66+
hasBaseTokens = 0x80
67+
hasNativeTokens = 0x40
68+
hasNFTs = 0x20
69+
```
70+
71+
followed by the 3 optional parts, in strict order:
72+
73+
- Base Tokens - uint64 - LE encoding
74+
- Native Tokens:
75+
- length prefix (number of different tokens - uint16 LE encoding)
76+
- \+ each [TokenID (38 bytes) + amount ([uint256 special encoding](./###Uint256))]
77+
- NFTs
78+
- length prefix (number of NFTs - uint16 LE encoding)
79+
- \+ the bytes off all the NFTIDs (32 bytes each)
80+
81+
### Uint256
82+
83+
Uint256 values are encoded using BE and unused bytes removed. Must prefixed by the length of the encoded bytes using the [Optimized Size Encode](https://github.com/iotaledger/wasp/blob/c362291b053f70c9b14a16961dd74b3b4176bba5/packages/util/rwutil/convert.go#L108-L137).
84+
85+
## Example
86+
87+
Follows an example of a deposit from L1 to an EVM address on a target chain:
88+
89+
```go
90+
{
91+
SenderContract: nil,
92+
TargetContract: 1011572226 ( = 0x3c4b5e02),
93+
EntryPoint: 603251617 ( = 0x23f4e3a1),
94+
Params: [
95+
{ k: "a", v: EthereumAgentID(
96+
address: 0xE913CAc59E0bA840039aDD645D5df83C294CC230,
97+
chainID: 0xe14c3499349cb8d2fd771e09829883e4ecfae02e6b09c9b6a0fb3c7504b4e2f4)
98+
},
99+
],
100+
Allowance: {
101+
BaseTokens:0,
102+
NativeTokens:[
103+
{
104+
ID: 0x08e14c3499349cb8d2fd771e09829883e4ecfae02e6b09c9b6a0fb3c7504b4e2f40100000000,
105+
Amount: 50
106+
}
107+
],
108+
NFTs: [],
109+
},
110+
GasBudget: 10000,
111+
}
112+
```
113+
114+
The `TargetContract` is `"accounts"` and `TargetEntrypoint` is `"transferAllowanceTo"`.
115+
The hnames can be calculated from: Blake2B Hash of an UTF-encoded string, then taking the initial 4 bytes:
116+
117+
```go
118+
Blake2B("accounts") // yields 0x3c4b5e02.....
119+
```
120+
121+
results in the following metadata:
122+
123+
```hex
124+
0x00025e4b3ca1e3f423914e0101613503e14c3499349cb8d2fd771e09829883e4ecfae02e6b09c9b6a0fb3c7504b4e2f4e913cac59e0ba840039add645d5df83c294cc230400108e14c3499349cb8d2fd771e09829883e4ecfae02e6b09c9b6a0fb3c7504b4e2f401000000000132
125+
```
126+
127+
## Libraries
128+
129+
The Wasp repo already provides function to Encode/Decode request metadata (in Go).
130+
131+
A javascript library should be produced to be re-used across client applications.
132+
133+
## Copyright
134+
135+
Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/).

0 commit comments

Comments
 (0)