Skip to content

Commit 54cf21c

Browse files
authored
TEP-85: SBT Standard
Soul bound token (SBT) is a special kind of NFT which can be transferred only between its owner's accounts. For this, it stores immutable public key of the owner, and it is needed to send transfer from new address with signature in payload to change owner's address. There is a useful type of token which allows to give social permissions/roles or certificates to some users. For example, it can be used by marketplaces to give discounts to owners of SBT, or by universities to give attestation certificates in SBT form. Mechanics with ownership proof allows to easily prove to any contract that you are an owner of some SBT. SBT implements NFT standard interface but transfer should always be rejected, pull_ownership is used instead.
1 parent 2bd5b0e commit 54cf21c

File tree

1 file changed

+274
-0
lines changed

1 file changed

+274
-0
lines changed

text/0083-sbt-standard.md

Lines changed: 274 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,274 @@
1+
- **TEP**: [0](https://github.com/ton-blockchain/TEPs/pull/0)
2+
- **title**: SBT Contract
3+
- **status**: Draft
4+
- **type**: Contract Interface
5+
- **authors**: [Oleg Baranov](https://github.com/xssnick), [Narek Abovyan](https://github.com/Naltox), [Kirill Emelyanenko](https://github.com/EmelyanenkoK), [Oleg Andreev](https://github.com/oleganza)
6+
- **created**: 09.08.2022
7+
8+
# Summary
9+
10+
Soul bound token (SBT) is a special kind of NFT which can not be transferred. It includes optional certificate mechanics with revoke by authority and onchain ownership proofs. Holder can destroy his SBT in any time.
11+
12+
# Motivation
13+
14+
There is a useful type of token which allows to give social permissions/roles or certificates to some users. For example, it can be used by marketplaces to give discounts to owners of SBT, or by universities to give attestation certificates in SBT form. Mechanics with ownership proof allows to easily prove to any contract that you are an owner of some SBT.
15+
16+
# Specification
17+
18+
SBT implements [NFT standard interface](https://github.com/ton-blockchain/TIPs/issues/62) but `transfer` should always be rejected.
19+
20+
#### 1. `prove_ownership`
21+
22+
TL-B schema of inbound message:
23+
```
24+
prove_ownership#04ded148 query_id:uint64 dest:MsgAddress
25+
forward_payload:^Cell with_content:Bool = InternalMsgBody;
26+
```
27+
`query_id` - arbitrary request number.
28+
29+
`dest` - address of the contract to which the ownership of SBT should be proven.
30+
31+
`forward_payload` - arbitrary data required by target contract.
32+
33+
`with_content` - if true, SBT's content cell will be included in message to contract.
34+
35+
**Should do:**
36+
37+
Send message with TL-B schema to `dest` contract:
38+
```
39+
ownership_proof#0524c7ae query_id:uint64 item_id:uint256 owner:MsgAddress
40+
data:^Cell revoked_at:uint64 content:(Maybe ^Cell) = InternalMsgBody;
41+
```
42+
43+
`query_id` - request number passed in `prove_ownership`.
44+
45+
`item_id` - id of NFT.
46+
47+
`owner` - current owner's address.
48+
49+
`data` - data cell passed in `prove_ownership`.
50+
51+
`revoked_at` - unix time when SBT was revoked, 0 if it was not.
52+
53+
`content` - NFT's content, it is passed if `with_content` was true in `prove_ownership`.
54+
55+
In case when `ownership_proof` was bounced back to NFT, NFT should send message to owner with schema:
56+
```
57+
ownership_proof_bounced#c18e86d2 query_id:uint64 item_id:uint256 owner:MsgAddress
58+
data:^Cell content:(Maybe ^Cell) = InternalMsgBody;
59+
```
60+
61+
#### 2. `request_owner`
62+
63+
TL-B schema of inbound message:
64+
```
65+
request_owner#d0c3bfea query_id:uint64 dest:MsgAddress
66+
forward_payload:^Cell with_content:Bool = InternalMsgBody;
67+
```
68+
`query_id` - arbitrary request number.
69+
70+
`dest` - address of the contract to which the ownership of SBT should be proven.
71+
72+
`forward_payload` - arbitrary data required by target contract.
73+
74+
`with_content` - if true, SBT's content cell will be included in message to contract.
75+
76+
**Should do:**
77+
78+
Send message with TL-B schema to `dest` contract:
79+
```
80+
owner_info#0dd607e3 query_id:uint64 item_id:uint256 initiator:MsgAddress owner:MsgAddress
81+
data:^Cell revoked_at:uint64 content:(Maybe ^Cell) = InternalMsgBody;
82+
```
83+
84+
`query_id` - request number passed in `prove_ownership`.
85+
86+
`item_id` - id of NFT.
87+
88+
`initiator` - address of request initiator.
89+
90+
`owner` - current owner's address.
91+
92+
`data` - data cell passed in `prove_ownership`.
93+
94+
`revoked_at` - unix time when SBT was revoked, 0 if it was not.
95+
96+
`content` - SBT's content, it is passed if `with_content` was true in `request_owner`.
97+
98+
In case when `owner_info` was bounced back to SBT, SBT should send message to **initiator** with schema:
99+
```
100+
owner_info_bounced#7ca7b0fe query_id:uint64 item_id:uint256 initiator:MsgAddress owner:MsgAddress
101+
data:^Cell content:(Maybe ^Cell) = InternalMsgBody;
102+
```
103+
104+
#### 3. `destroy`
105+
106+
TL-B schema of an internal message:
107+
```
108+
destroy#1f04537a query_id:uint64 = InternalMsgBody;
109+
```
110+
`query_id` - arbitrary request number.
111+
112+
Should be rejected if:
113+
* Sender address is not an owner's address.
114+
115+
Otherwise should do:
116+
* Set owner's address and authority to null.
117+
* Send message to sender with schema `excesses#d53276db query_id:uint64 = InternalMsgBody;` that will pass contract's balance amount.
118+
119+
#### 4. `revoke`
120+
121+
TL-B schema of inbound message:
122+
```
123+
revoke#6f89f5e3 query_id:uint64 = InternalMsgBody;
124+
```
125+
`query_id` - arbitrary request number.
126+
127+
**Should be rejected if:**
128+
* Sender address is not an authority's address.
129+
* Was already revoked
130+
131+
**Otherwise should do:**
132+
Set revoked_at to current unix time.
133+
134+
**GET methods**
135+
1. `get_nft_data()` - same as in [NFT standard](https://github.com/ton-blockchain/TIPs/issues/62).
136+
2. `get_authority_address()` - returns `slice`, that is authority's address. Authority can revoke SBT.
137+
**This method is mandatory for SBT, if there is no authority it should return addr_none (2 zero bits)**
138+
3. `get_revoked_time()` - returns `int`, that is unix time of when it was revoked. It is 0 when not revoked.
139+
140+
### Implementation example
141+
https://github.com/getgems-io/nft-contracts/blob/main/packages/contracts/sources/sbt-item.fc
142+
143+
# Guide
144+
145+
#### Minting
146+
It can be done using basic NFT collection, SBT should be an item. In mint message additionally authority address should be passed, [after content](https://github.com/getgems-io/nft-contracts/blob/main/packages/contracts/sources/sbt-item.fc#L90).
147+
148+
Before mint, issuer is recommended to check the wallet code and confirm that it is standartized wallet and not some transferrable contract that can be sold to 3rd parties.
149+
150+
#### Proving you ownership to contracts
151+
SBT contracts has a feature that let you implement interesting mechanics with contracts by proving ownership onchain.
152+
153+
You can send message to SBT, and it will proxify message to target contract with its index, owner's address and initiator address in body, together with any useful for contract payload,
154+
this way target contract could know that you are owner of SBT which relates to expected collection. Contract could know that SBT relates to collection by calculating address of SBT using code and index, and comparing it with sender.
155+
156+
There are 2 methods which allow to use this functionality, **ownership proof** and **ownership info**.
157+
The difference is that proof can be called only by SBT owner, so it is preferred to use when you need to accept messages only from owner, for example votes in DAO.
158+
159+
##### Ownership proof
160+
**SBT owner** can send message to SBT with this schema:
161+
```
162+
prove_ownership#04ded148 query_id:uint64 dest:MsgAddress
163+
forward_payload:^Cell with_content:Bool = InternalMsgBody;
164+
```
165+
After that SBT will send transfer to `dest` with scheme:
166+
```
167+
ownership_proof#0524c7ae query_id:uint64 item_id:uint256 owner:MsgAddress
168+
data:^Cell revoked_at:uint64 content:(Maybe ^Cell)
169+
```
170+
If something goes wrong and target contract not accepts message, and it will be bounced back to SBT, SBT will proxy this bounce to owner, this way coins will not stuck on SBT.
171+
172+
##### Ownership info
173+
**anyone** can send message to SBT with this schema:
174+
```
175+
request_owner#d0c3bfea query_id:uint64 dest:MsgAddress
176+
forward_payload:^Cell with_content:Bool = InternalMsgBody;
177+
```
178+
After that SBT will send transfer to `dest` with scheme:
179+
```
180+
owner_info#0dd607e3 query_id:uint64 item_id:uint256 initiator:MsgAddress owner:MsgAddress
181+
data:^Cell revoked_at:uint64 content:(Maybe ^Cell)
182+
```
183+
If something goes wrong and target contract not accepts message, and it will be bounced back to SBT, SBT will proxy this bounce to initiator, this way coins will not stuck on SBT.
184+
185+
#### Verify SBT contract example
186+
187+
```C
188+
int op::ownership_proof() asm "0x0524c7ae PUSHINT";
189+
190+
int equal_slices (slice a, slice b) asm "SDEQ";
191+
192+
_ load_data() {
193+
slice ds = get_data().begin_parse();
194+
195+
return (
196+
ds~load_msg_addr(), ;; collection_addr
197+
ds~load_ref() ;; sbt_code
198+
);
199+
}
200+
201+
slice calculate_sbt_address(slice collection_addr, cell sbt_item_code, int wc, int index) {
202+
cell data = begin_cell().store_uint(index, 64).store_slice(collection_addr).end_cell();
203+
cell state_init = begin_cell().store_uint(0, 2).store_dict(sbt_item_code).store_dict(data).store_uint(0, 1).end_cell();
204+
205+
return begin_cell().store_uint(4, 3)
206+
.store_int(wc, 8)
207+
.store_uint(cell_hash(state_init), 256)
208+
.end_cell()
209+
.begin_parse();
210+
}
211+
212+
213+
() recv_internal(int balance, int msg_value, cell in_msg_full, slice in_msg) impure {
214+
slice cs = in_msg_full.begin_parse();
215+
int flags = cs~load_uint(4);
216+
217+
slice sender_address = cs~load_msg_addr();
218+
219+
int op = in_msg~load_uint(32);
220+
int query_id = in_msg~load_uint(64);
221+
222+
if (op == op::ownership_proof()) {
223+
int id = in_msg~load_uint(256);
224+
225+
(slice collection_addr, cell sbt_code) = load_data();
226+
throw_unless(403, equal_slices(sender_address, collection_addr.calculate_sbt_address(sbt_code, 0, id)));
227+
228+
slice owner_addr = in_msg~load_msg_addr();
229+
cell payload = in_msg~load_ref();
230+
231+
int revoked_at = in_msg~load_uint(64);
232+
throw_if(403, revoked_at > 0);
233+
234+
int with_content = in_msg~load_uint(1);
235+
if (with_content != 0) {
236+
cell sbt_content = in_msg~load_ref();
237+
}
238+
239+
;;
240+
;; sbt verified, do something
241+
;;
242+
243+
return ();
244+
}
245+
246+
throw(0xffff);
247+
}
248+
```
249+
250+
# Rationale and alternatives
251+
252+
- **Why is this design the best in the space of possible designs?**
253+
254+
This design allows us to use SBT as certificates, with revoke and onchain proofs, and in the same time allows to make true SBT if authority in not set.
255+
256+
- **What other designs have been considered and what is the rationale for not choosing them?**
257+
258+
Initially, the design similar to ETH with address-bounded tokens was considered, but it was extended with usefull onchain proofs and revoke option.
259+
260+
- **What is the impact of not doing this?**
261+
262+
Currently, TON have no owner-bounded token standard, so it is a problem to issue tokens that cannot be transferred to 3rd parties. So, if we ignore this or any similar standard that introduces such mechanics, TON could miss some interesting and perspective products.
263+
264+
# Prior art
265+
266+
In ETH ([EIP-4973 ABT](https://eips.ethereum.org/EIPS/eip-4973)) - SBT was done as an NFT which could not be transferred between accounts at all. We did tha same but extended the logic with onchain proofs, and added authority which can revoke, so SBT can be used as fully functional certificate.
267+
# Drawbacks
268+
269+
[EIP-4973 ABT](https://eips.ethereum.org/EIPS/eip-4973) has equip/unequip mechanics which allows to show/hide SBT temporarily. In current proposal we can only destroy SBT. Actually not sure that show/hide logic is needed for us.
270+
271+
# Future possibilities
272+
273+
Standard looks finalized.
274+

0 commit comments

Comments
 (0)