Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1369 #87

Open
wants to merge 129 commits into
base: feature/optimisation
Choose a base branch
from
Open

1369 #87

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
129 commits
Select commit Hold shift + click to select a range
88ba4f6
chore: build script
siandreev Nov 20, 2023
dbb7292
Merge remote-tracking branch 'origin/main'
siandreev Nov 20, 2023
0b95549
chore: ci updated
siandreev Nov 21, 2023
6145f6b
Merge branch 'main' into feature/optimisation
Skydev0h Jan 23, 2024
6a245a2
Added root cell repacking algorithm with enforced Asm version
Skydev0h Jan 24, 2024
e70ff08
Added size constants and changed stored seqno type from ui32 to i33
Skydev0h Jan 24, 2024
194f803
Changed sign op for internal messages to sint to avoid replay attacks
Skydev0h Jan 24, 2024
04a363d
Removed set_data and temporarily disabled the relevant tests
Skydev0h Jan 24, 2024
3222372
Added actions checking (send_msg w/ mode 2 enforced) and set pk enabled
Skydev0h Jan 24, 2024
54a28d3
Add guidelines and code to be able to make unsafe version
Skydev0h Jan 24, 2024
7abb84d
Optimized verify_actions by rearranging loop and conditions
Skydev0h Jan 24, 2024
12b6e05
Added more info about sequence and fixed some cases in getters
Skydev0h Jan 24, 2024
c5c65d1
Adjusted comments to be more correct and precise
Skydev0h Jan 24, 2024
0c9fa87
Removed unneccessary noop middleware and renamed method to classic name
Skydev0h Jan 24, 2024
74cc7f6
Removed throwif from the comment about seqno
Skydev0h Jan 24, 2024
4217b8a
Made internal messages bounce-safe (replaced throws with soft checks)
Skydev0h Jan 24, 2024
dc6b4e9
Added quick return for empty internal messages
Skydev0h Jan 24, 2024
3ad3a7a
[Docs] Moved contest note to separate file and tidied up README a bit
Skydev0h Jan 24, 2024
0d9ffef
[Docs] Slight readme tidy-up
Skydev0h Jan 24, 2024
507b821
[Docs] Updated specification in accordance with new contract features
Skydev0h Jan 24, 2024
b5bdf24
[Docs] Update types.tlb
Skydev0h Jan 24, 2024
f2601ae
[Docs] Add use cases for disabling public key
Skydev0h Jan 27, 2024
9545120
Updated actions, allow naming, empty ref check, docs, actions wrapper
Skydev0h Jan 27, 2024
c7bd87a
Added gas tests for incoming messages
Skydev0h Jan 28, 2024
916ed76
Removed fift optimizations that might create problems for tooling
Skydev0h Jan 28, 2024
43eba0d
Flattened and split some asm functions for understanding and toolings
Skydev0h Jan 28, 2024
167347a
Add external message bit to signed message part
Skydev0h Jan 30, 2024
e580224
Changed signed message prefix from 1 bit to 32-bit message tag
Skydev0h Feb 3, 2024
41f3063
Moved signature to the end of the message (includes opcode)
Skydev0h Feb 9, 2024
033b63e
Adjusted TLB definitions to match signature at the end
Skydev0h Feb 9, 2024
34a8556
Adjusted all tests to match new signature place (in end)
Skydev0h Feb 9, 2024
c724855
Fixed accounting for seqno twice on signature disabling
Skydev0h Feb 12, 2024
4bf0feb
Added throw for unknown ext-act, setcode/data neg tests, test-only acts
Skydev0h Feb 15, 2024
3f76dbb
Added tests for signature disallow cases, incorrect allow act now throws
Skydev0h Feb 15, 2024
7f786ea
Added a test for separate auth disable by extension
Skydev0h Feb 15, 2024
a840198
Merge pull request #13 from Skydev0h/feature/optimisation
oleganza Feb 19, 2024
7739099
improved overview wording
oleganza Feb 20, 2024
c2734f0
Bounce internal signed messages to protect relayer against abuse
oleganza Feb 20, 2024
b233fb7
fix throw argument
oleganza Feb 20, 2024
55a383d
Merge pull request #14 from tonkeeper/oleganza/sint-bounce
oleganza Feb 20, 2024
4cd9181
Fixed failing tests after adding back throw (bounce) for sint after sig
Skydev0h Feb 20, 2024
53cf00c
Merge pull request #15 from Skydev0h/skydev/fix-bouncing-tests
oleganza Feb 20, 2024
8661ce2
Added safeguard against deleting last ext with disabled key (need tests)
Skydev0h Feb 21, 2024
4458be0
Fix prefix clashing bug and adjust code style (reported by @behrang)
Skydev0h Feb 23, 2024
51358ad
Fixed tests and added cases for deleting last ext with disallowed pubkey
Skydev0h Feb 23, 2024
fa1b372
Merge pull request #16 from Skydev0h/skydev/del-ext-safeguard
oleganza Feb 23, 2024
d373fb0
Introduction improvements
oleganza Jun 13, 2024
92471dd
Some improvements and changes to the contract
Skydev0h Jun 14, 2024
7d1d144
Plugins now bound to same workchain as the wallet, no packing (6)
Skydev0h Jun 14, 2024
1f9b0a3
Moved signature_auth_disable to separate variable from seq_no sign (3)
Skydev0h Jun 14, 2024
a210caa
Fix `getExtensionsArray()` method when address hash starts with `00`
Skydev0h Jun 14, 2024
ba7e312
add builds to git
rise1507 Jun 21, 2024
1d44704
cosmetic: rename constants (no changes in compiled code)
rise1507 Jun 21, 2024
99493bc
cosmetic: types (no changes in compiled code)
rise1507 Jun 21, 2024
0d5cc02
cosmetic: rename vars, avoid abbreviations (no changes in compiled code)
rise1507 Jun 21, 2024
ce56813
cosmetic: remove comments about optimizations (no changes in compiled…
rise1507 Jun 21, 2024
b58bbb9
cosmetic: add additional consts for sizes (no changes in compiled code)
rise1507 Jun 21, 2024
f1f4cb4
cosmetic: add error const (no changes in compiled code)
rise1507 Jun 21, 2024
0537f52
cosmetic: subwallet_id->wallet_id in comments (no changes in compiled…
rise1507 Jun 21, 2024
0574f37
don't store workchain in extensions dict values
rise1507 Jun 21, 2024
2f20a49
remove unnecessary micro-optimiazations
rise1507 Jun 21, 2024
edef797
simplify
rise1507 Jun 21, 2024
4f77395
refactor signature_allowed
rise1507 Jun 21, 2024
9869fef
preload_dict
rise1507 Jun 21, 2024
5a21842
get-methods cosmetic
rise1507 Jun 21, 2024
ad1d90b
simplify
rise1507 Jun 21, 2024
2e31a01
simplify
rise1507 Jun 21, 2024
5424092
c5 comments
rise1507 Jun 21, 2024
b3d712d
fix size check
rise1507 Jun 21, 2024
520dec7
fix error naming
rise1507 Jun 21, 2024
243d7d2
simplify
rise1507 Jun 21, 2024
a39b7b0
simplify
rise1507 Jun 21, 2024
fe128dd
cosmetic-optimization
rise1507 Jun 21, 2024
ab0233d
explicit () in binary operations
rise1507 Jun 22, 2024
477bf6d
cosmetic
rise1507 Jun 22, 2024
029e60a
fix return
rise1507 Jun 22, 2024
5910896
simplify
rise1507 Jun 22, 2024
2ba7fda
commit only for external
rise1507 Jun 22, 2024
c10105a
xctos comment
rise1507 Jun 22, 2024
1f3c177
update stdlib from stablecoin-contract
rise1507 Jun 22, 2024
464e68d
rename get_is_signature_auth_allowed -> is_signature_allowed
rise1507 Jun 22, 2024
d5ea381
comments
rise1507 Jun 24, 2024
816e446
add query_id to extension request so that the extension can recognise…
rise1507 Jun 24, 2024
43fabdf
action prefix 8bit
rise1507 Jun 25, 2024
68a0866
wallet_id 32bit
rise1507 Jun 25, 2024
21f229a
change refs in message (tests not synced yet)
rise1507 Jun 25, 2024
0a40931
only extension can change signature mode (tests not synced yet)
rise1507 Jun 25, 2024
3d822d9
allow work with (~ is_signature_allowed) and empty extensions
rise1507 Jun 25, 2024
c5dc057
refactor errors - only only_extension_can_change_signature_mode numbe…
rise1507 Jun 26, 2024
c678610
refactor errors naming
rise1507 Jun 26, 2024
aff9c49
refactor errors
rise1507 Jun 26, 2024
e4b8c5b
cosmetic (bytecode not changed)
rise1507 Jun 26, 2024
dd9ff28
cosmetic comment (bytecode not changed)
rise1507 Jun 26, 2024
b7b8fd8
simplify
rise1507 Jun 26, 2024
3dc030e
fix mistake
rise1507 Jun 26, 2024
e6ef9e4
receive tons
rise1507 Jun 26, 2024
39d0feb
get_wallet_id -> get_subwallet_id, same with v4
rise1507 Jun 26, 2024
444ddde
return_unless not work
rise1507 Jun 26, 2024
3bd769e
update wrappers and tests
rise1507 Jun 26, 2024
38f7e3a
fix typo
rise1507 Jun 27, 2024
64cff84
change error codes to avoid collision with tvm-exit-codes
rise1507 Jun 28, 2024
6e81ad3
remove return_if, return_unless because its dangerous
rise1507 Jun 28, 2024
facbfcf
additional checks for c5
rise1507 Jul 1, 2024
84eaf15
fix numbers
rise1507 Jul 1, 2024
ee52524
Upgrade packages
Jul 2, 2024
047852a
Migrate to @ton packages
Jul 2, 2024
982f304
Minor fix
Jul 2, 2024
ff8cd74
Extra moar utils for the utils god
Jul 2, 2024
d349886
Test wrapper and constants
Jul 2, 2024
57e37aa
W5 wallet tests
Jul 2, 2024
e805cde
Merge pull request #1 from Trinketer22/w5_tests
tolya-yanot Jul 3, 2024
6220bd6
rebuild
rise1507 Jul 3, 2024
2f962c3
optimize bounced check
rise1507 Jul 3, 2024
b66b103
more accurate check
rise1507 Jul 3, 2024
62bfd99
delete unused code
rise1507 Jul 3, 2024
0bfb383
update tlb
rise1507 Jul 3, 2024
2c1b964
update tlb
rise1507 Jul 3, 2024
e02e43c
delete v4
rise1507 Jul 3, 2024
26ab229
update Specification.md
rise1507 Jul 3, 2024
230e48b
simplify
rise1507 Jul 3, 2024
5e711b2
strict func version
rise1507 Jul 3, 2024
5962103
update tlb
rise1507 Jul 3, 2024
c5465be
Merge pull request #28 from tolya-yanot/main
KuznetsovNikita Jul 3, 2024
d5f0a0d
add additional comments to the smart contract code
rise1507 Jul 4, 2024
badcbfb
delete docs about optimization contest
rise1507 Jul 4, 2024
0ed97d4
delete docs about optimization contest
rise1507 Jul 4, 2024
2f2eaca
update readme and deploy script
rise1507 Jul 4, 2024
4fab977
add more info to README
rise1507 Jul 4, 2024
88557eb
fix comment
rise1507 Jul 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Run tests

on:
push:
branches: [ "main" ]
branches: [ "main", "feature/optimisation" ]
pull_request:
branches: [ "main" ]
branches: [ "main", "feature/optimisation" ]

jobs:
test:
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
node_modules
temp
build
.idea
.env
447 changes: 0 additions & 447 deletions Improvements.rst

This file was deleted.

90 changes: 60 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,59 +1,89 @@
# Wallet V5
# W5: wallet smart contract v5

This is an extensible wallet specification aimed at replacing V4 and allowing arbitrary extensions.
New version of wallet smart contract, the previous one was [v4r2](https://github.com/ton-blockchain/wallet-contract).

Wallet V5 has 25% lower fees, can delegate payments for gas to third parties and supports flexible extension mechanism.
The entire concept is proposed by the [Tonkeeper team](https://tonkeeper.com/).

## Warning! Contest note!
New Features:

<div align="center">
<img alt="Contest logo" src="contest.png" height="280" width="280">
</div>
- Send up to 255 messages at once;

**Because of the extreme amount of optimizations, developer's discretion is advised!** *Evil laugh*
- Signed actions can be sent not only by external message, but also by internal messages (can be used for gasless transactions);

The build system is the same as in the original Wallet V5, **no security features have been sacrificed**
for performance improvements, that is - there are **practically no tradeoffs or compromises**.
- Unlimited extensions;

Message and storage layouts were **not changed**, although some rearragement might squeeze a little more gas,
but that may break existing optimizations due to stack reordering.
- Extension can prohibit signed actions in the wallet (can be used for 2fa or key recovery);

Also, **tests were improved** - a **Global Gas Counter** mechanism was added that accounts for gas in all transactions
of all test suites and cases (except for negative and getter ones). This allows to keep an eye on other non-contest
cases to track how bad is tradeoff when performing optimizations here and there.
- Optimizations to reduce network fees;

Another utility that was developed for contest is ***scalpel script***, that allows for a detailed, *really* detailed optimizations
of the code by comparing lines of code function by function, printing out diffs, and providing detailed TVM files with
stack comments and rewrites. This utility allowed to make some latter optimizations, since with each optimization
next one becomes exponentionally harder to make. While result is not entirely precise and is needed to be verified
by tests, this allows to instantly estimate whether there is some progress or not, since scalpel is executed immediately,
while tests take approximately 10 seconds to execute.

### Details of optimizations, their rationale and explanations, comparison of consumed gas both in test cases and not in test cases (global gas counter) are provided on a dedicated page: [Gas improvements](Improvements.rst).
- Better foolproofing safety - reply-protection for external messages, wallet id rethinking;

## Project structure

- [Specification](Specification.md)
- `contracts` - source code of all the smart contracts of the project and their dependencies.
- `wrappers` - wrapper classes (implementing `Contract` from ton-core) for the contracts, including any [de]serialization primitives and compilation functions.
- `tests` - tests for the contracts.
- `scripts` - scripts used by the project, mainly the deployment scripts.
- **[Gas improvements](Improvements.rst)** (detailed by contest paths, global gas counters per commit)
- `scripts` - scripts used by the project, mainly the deployment scripts, additionally contains utilities for gas optimisation.
- `fift` - contains standard Fift v0.4.4 library including the assembler and disassembler for gas optimisation utilities.

## How to use

### Build

`npm run build:v5`
`npm run build`

### Test

`npm run test`

### Deployment
1. Deploy library: `npm run deploy-library`
2. Deploy wallet: `npm run deploy-wallet`

### Get wallet compiled code
Deploy wallet: `npm run deploy-wallet`

### Known issues

1) Since the `valid_until` is uint32 it will not work after 2106 year. We believe new versions of wallet smart contract will be available by then.

2) If the `action_send_msg` content is invalid and the sendmode has +2, the error will not be ignored. An update of the node is planned where this behaviour will be changed (with +2 sendmode and `action_send_msg` invalid content the error will be ignored).

3) It would be good to do `end_parse()` for messages and contract data. But this is not done within optimisations.

### Gasless flow

1. When sending an USDt (or other Jetton) the user signs one message containing two outgoing USDt transfers:

* USDt transfer to the recipient's address.

* Transfer of a small amount of USDt in favor of the Service.

2. This signed message is sent offchain by HTTPS to the Service backend. The Service backend checks message and sends it to the TON blockchain paying Toncoins for network fees.

### Gasless known issues

1) By requesting a gasless service, a user can have time to increase the seqno on his own, or via another service.

In this case, the gasless service will incur gas costs.

However, this is a non-scalable scenario, as it requires the user to incur gas costs as well.

A blacklist on the service backend side solves the problem.

2) The user can request a gasless service and by means of a specialised extension have time to withdraw the entire balance of Jettons without change seqno.

In this case, the Jetton transfer message from the service will encounter a balance shortage and the Toncoins attached to message will return to the user's wallet.

However, this is a non-scalable scenario, as it requires the user to incur gas costs as well.

A blacklist on the service backend side solves the problem.

### Suggested extensions

1) Decentralised subscriptions. The extension can withdraw a given number of Toncoins or Jettons once in a given period.

2) 2FA: Multisig extension is added, extension prohibits wallet signature;

3) Key recovery: 2FA, but in multisig extension there is an option to change the control keys. Possible cooldown period when the other party can cancel the key change.

4) Key compromise: An extension with a new key is added, extension prohibits wallet signature;

`npm run print-wallet-code`
133 changes: 18 additions & 115 deletions Specification.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ This is an extensible wallet specification aimed at replacing V4 and allowing ar
* [Features](#features)
* [Overview](#overview)
* [Discussion](#discussion)
* [Wallet ID](#wallet-id)
* [Packed address](#packed-address)
* [TL-B definitions](#tl-b-definitions)
* [Source code](#source-code)

Expand All @@ -19,34 +17,35 @@ Thanks to [Andrew Gutarev](https://github.com/pyAndr3w) for the idea to set c5 r

Thanks to [@subden](https://t.me/subden), [@botpult](https://t.me/botpult) and [@tvorogme](https://t.me/tvorogme) for ideas and discussion.

Thanks to [Skydev](https://github.com/Skydev0h) for optimization and preparing the second revision of the contract.


## Features

* 25% smaller computation fees.
* Arbitrary amount of outgoing messages is supported via action list.
* Wallet code can be upgraded transparently without breaking user's address in the future.
* Wallet code can be extended by anyone in a decentralized and conflict-free way: multiple feature extensions can co-exist.
* Extensions can perform the same operations as the signer: emit arbitrary messages on behalf of the owner, add and remove extensions.
* Signed requests can be delivered via internal message to allow 3rd party pay for gas.
* For consistency and ease of indexing, external messages also receive a 32-bit opcode.
* To lay foundation for support of scenarios like 2FA or access recovery it is possible to disable signature authentication by extension.

## Overview

Wallet V5 supports **2 authentication modes**, all standard output actions (send message, set library, code replacement) plus additional **3 operation types**.
Wallet V5 supports **2 authentication modes** and **3 operations types**.

Authentication:
* by signature
* by extension

Operation types:
* standard output actions
* “set data” operation
* install extension
* remove extension
Operations:
* standard "send message" action (up to 255 messages at once),
* enable/disable signature authentication (can be invoked only by extension),
* install/remove extension.

Signed messages can be delivered both by external and internal messages.

All operation types are available to all authentication modes.
All operations are available to all authentication modes.

## Discussion

Expand All @@ -63,40 +62,12 @@ User may delegate this job to other apps via extensions.

### Extending the wallet

**A. Use extensions**

The best way to extend functionality of the wallet is to use the extensions mechanism that permit delegating access to the wallet to other contracts.

From the perspective of the wallet, every extension can perform the same actions as the owner of a private key. Therefore limits and capabilities can be embedded in such an extension with a custom storage scheme.

Extensions can co-exist simultaneously, so experimental capabilities can be deployed and tested independently from each other.

**B. Code optimization**

Backwards compatible code optimization **can be performed** with a single `set_code` action (`action_set_code#ad4de08e`) signed by the user. That is, hypothetical upgrade from `v5R1` to `v5R2` can be done in-place without forcing users to change their wallet address.

If the optimized code requires changes to the data layout (e.g. reordering fields) the user can sign a request with two actions: `set_code` (in the standard action) and `set_data` (an extended action per this specification). Note that `set_data` action must make sure `seqno` is properly incremented after the upgrade as to prevent replays. Also, `set_data` must be performed right before the standard actions to not get overwritten by extension actions. The updated wallet **must** have the new subwallet ID to prevent accidental repeated migrations.

User agents **should not** make `set_code` and `set_data` actions available via general-purpose API to prevent misuse and mistakes. Instead, they should be used as a part of migration logic for a specific wallet code.

To restore the wallet by a seed phrase, user agent should use the original code and should expect the upgraded code to work in exactly the same way as previously.

**C. Emergency upgrades**

This is a variant of (B), so the same consideration apply. The difference is that functionality may be modified as to prevent user from suffering loss of funds. E.g. some previously possible actions or signed messages would lead to a failure.

Just like with (B), user agents **should not** make `set_code` and `set_data` actions available via general-purpose API to prevent misuse and mistakes. Instead, they should be used as a part of migration logic for a specific wallet code.

New users’ wallets **should not** be deployed with upgraded code. Instead, the improved wallet code should also be released as a new wallet version (e.g. v6, with a separate subwallet ID) and new wallets should be deployed with that code. This way `set_code` would be used as an emergency patch for existing wallets, while new wallets would be deployed directly with the major next version.


**D. Substantial upgrades**

We **do not recommend** performing substantial wallet upgrades in-place using `set_code`/`set_data` actions. Instead, user agents should have support for multiple accounts and easy switching between them.

In-place migration requires maintaining backwards compatibility for all wallet features, which in turn could lead to increase in code size and higher gas and rent costs.


### Can the wallet outsource payment for gas fees?

Yes! You can deliver signed messages via an internal message from a 3rd party wallet. Also, the message is handled exactly like an external one: after the basic checks the wallet takes care of the fees itself, so that 3rd party does not need to overpay for users who actually do have TONs.
Expand All @@ -123,92 +94,24 @@ You need to put two requests in your message body:

Yes. We have considered constant-size schemes where the wallet only stores trusted extension code. However, extension authentication becomes combursome and expensive: plugin needs to transmit additional data and each request needs to recompute plugin’s address. We estimate that for the reasonably sized wallets (less than 100 plugins) authentication via the dictionary lookup would not exceed costs of indirect address authentication.

### Why it can be useful to disallow authentication with signature?

Ability to disallow authentication with signature enables two related use-cases:

1. Two-factor authentication schemes: where control over wallet is fully delegated to an extension that checks two signatures: the user’s one and the signature from the auth service. Naturally, if the signature authentication in the wallet remains allowed, the second factor check is bypassed.

2. Account recovery: delegating full control to another wallet in case of key compromise or loss. Wallet may contain larger amount of assets and its address could be tied to long-term contracts, therefore delegation to another controlling account is preferred to simply transferring the assets.

### What is library on masterchain?

Library is a special code storage mechanism that allows to reduce storage cost for a new Wallet V5 contract instance. Wallet V5 contract code is stored into a masterchain library.
When wallet contract is being deployed, original code hash is being used as the contract code.
Library contract itself data and code are empty cells. That leads to the inability to change the library code, delete the contract, or withdraw funds from it.
Therefore, any Wallet V5 user can top up the library contract balance if they are afraid that the library code of their wallet will be frozen.

## Wallet ID

Wallet ID disambiguates requests signed with the same public key to different wallet versions (V3/V4/V5) or wallets deployed on different chains.

For Wallet V5 we suggest using the following wallet ID:

```
wallet_id$_ global_id:int32 wc:int8 version:(## 8) subwallet_number:(## 32) = WalletID;
```

- `global_id` is a TON chain identifier. TON Mainnet `global_id = -239` and TON Testnet `global_id = -3`.
- `wc` is a Workchain. -1 for Masterchain and 0 for Basechain.
- `version`: current version of wallet v5 is `0`.
- `subwallet_number` can be used to get multiplie wallet contracts binded to the single keypair.

## Packed address

To make authorize extensions efficiently we compress 260-bit address (workchain + sha256 of stateinit) into a 256-bit integer:

```
int addr = addr_hash ^ (wc + 1)
```

Previously deployed wallet v4 was packing the address into a cell which costs ≈500 gas, while access to dictionary costs approximately `120*lg2(N)` in gas, that is serialization occupies more than half of the access cost for wallets with up to 16 extensions. This design makes packing cost around 50 gas and allows cutting the authentication cost 2-3x for reasonably sized wallets.

As of 2023 TON network consists of two workchains: -1 (master) and 0 (base). This means that the proposed address packing reduces second-preimage resistance of sha256 by 1 bit which we consider negligible. Even if the network is expanded with 254 more workchains in a distant future, our scheme would reduce security of extension authentication by only 8 bits down to 248 bits. Note that birthday attack is irrelevant in our setting as the user agent is not installing random extensions, although the security margin is plenty anyway (124 bits).



## TL-B definitions

Action types:

```tl-b
// Standard actions from block.tlb:
out_list_empty$_ = OutList 0;
out_list$_ {n:#} prev:^(OutList n) action:OutAction
= OutList (n + 1);
action_send_msg#0ec3c86d mode:(## 8)
out_msg:^(MessageRelaxed Any) = OutAction;
action_set_code#ad4de08e new_code:^Cell = OutAction;
action_reserve_currency#36e6b809 mode:(## 8)
currency:CurrencyCollection = OutAction;
libref_hash$0 lib_hash:bits256 = LibRef;
libref_ref$1 library:^Cell = LibRef;
action_change_library#26fa1dd4 mode:(## 7) { mode <= 2 }
libref:LibRef = OutAction;

// Extended actions in W5:
action_list_basic$0 {n:#} actions:^(OutList n) = ActionList n 0;
action_list_extended$1 {m:#} {n:#} action:ExtendedAction prev:^(ActionList n m) = ActionList n (m+1);

action_set_data#1ff8ea0b data:^Cell = ExtendedAction;
action_add_ext#1c40db9f addr:MsgAddressInt = ExtendedAction;
action_delete_ext#5eaef4a4 addr:MsgAddressInt = ExtendedAction;
```

Authentication modes:

```tl-b
signed_request$_
signature: bits512 // 512
subwallet_id: uint32 // 512+32
valid_until: uint32 // 512+32+32
msg_seqno: uint32 // 512+32+32+32 = 608
inner: InnerRequest = SignedRequest;

internal_signed#7369676E signed:SignedRequest = InternalMsgBody;
internal_extension#6578746E inner:InnerRequest = InternalMsgBody;
external_signed#7369676E signed:SignedRequest = ExternalMsgBody;

actions$_ {m:#} {n:#} actions:(ActionList n m) = InnerRequest;
```

Contract state:
```tl-b
wallet_id$_ global_id:int32 wc:int8 version:(## 8) subwallet_number:(## 32) = WalletID;
contract_state$_ seqno:# wallet_id:WalletID public_key:(## 256) extensions_dict:(HashmapE 256 int8) = ContractState;
```
See `types.tlb`.

## Source code

Expand Down
1 change: 1 addition & 0 deletions build/library-deployer.compiled.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"hash":"7b886902938fda7f8ee72fe31ee250744bf82489579c0b8e502105a49cb72e2a","hashBase64":"e4hpApOP2n+O5y/jHuJQdEv4JIlXnAuOUCEFpJy3Lio=","hex":"b5ee9c72410106010030000114ff00f4a413f4bcf2c80b0102012002050202d1030400053c006000193b511cbec1b232483ec13b55200006f2f0014136d496"}
1 change: 1 addition & 0 deletions build/wallet_v5.compiled.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"hash":"20834b7b72b112147e1b2fb457b84e74d1a30f04f737d4f62a668e9552d2b72f","hashBase64":"IINLe3KxEhR+Gy+0V7hOdNGjDwT3N9T2KmaOlVLSty8=","hex":"b5ee9c7241021401000281000114ff00f4a413f4bcf2c80b01020120020d020148030402dcd020d749c120915b8f6320d70b1f2082106578746ebd21821073696e74bdb0925f03e082106578746eba8eb48020d72101d074d721fa4030fa44f828fa443058bd915be0ed44d0810141d721f4058307f40e6fa1319130e18040d721707fdb3ce03120d749810280b99130e070e2100f020120050c020120060902016e07080019adce76a2684020eb90eb85ffc00019af1df6a2684010eb90eb858fc00201480a0b0017b325fb51341c75c875c2c7e00011b262fb513435c280200019be5f0f6a2684080a0eb90fa02c0102f20e011e20d70b1f82107369676ebaf2e08a7f0f01e68ef0eda2edfb218308d722028308d723208020d721d31fd31fd31fed44d0d200d31f20d31fd3ffd70a000af90140ccf9109a28945f0adb31e1f2c087df02b35007b0f2d0845125baf2e0855036baf2e086f823bbf2d0882292f800de01a47fc8ca00cb1f01cf16c9ed542092f80fde70db3cd81003f6eda2edfb02f404216e926c218e4c0221d73930709421c700b38e2d01d72820761e436c20d749c008f2e09320d74ac002f2e09320d71d06c712c2005230b0f2d089d74cd7393001a4e86c128407bbf2e093d74ac000f2e093ed55e2d20001c000915be0ebd72c08142091709601d72c081c12e25210b1e30f20d74a111213009601fa4001fa44f828fa443058baf2e091ed44d0810141d718f405049d7fc8ca0040048307f453f2e08b8e14038307f45bf2e08c22d70a00216e01b3b0f2d090e2c85003cf1612f400c9ed54007230d72c08248e2d21f2e092d200ed44d0d2005113baf2d08f54503091319c01810140d721d70a00f2e08ee2c8ca0058cf16c9ed5493f2c08de20010935bdb31e1d74cd0b4d6c35e"}
Binary file removed contest.png
Binary file not shown.
Loading