Skip to content

Commit

Permalink
Merge pull request #866 from everx-labs/rebranding
Browse files Browse the repository at this point in the history
Fix docs
  • Loading branch information
IgorKoval authored Apr 23, 2024
2 parents ac34d50 + c173638 commit f47ce50
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 175 deletions.
26 changes: 13 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ license-file = 'LICENSE.md'
name = 'tvm_linker'
readme = 'README.md'
repository = 'https://github.com/everx-labs/TVM-linker'
version = '0.21.2'
version = '0.21.3'

[[bin]]
name = 'tvm_linker'
Expand All @@ -31,10 +31,10 @@ serde = { features = [ 'derive' ], version = '1.0' }
serde_json = '1.0'
sha2 = '0.10'
simplelog = '0.6'
ever_abi = { git = 'https://github.com/everx-labs/ever-abi.git', tag = '2.5.1' }
ever_assembler = { features = [ 'gosh' ], git = 'https://github.com/everx-labs/ever-assembler.git', tag = '1.5.3' }
ever_block = { features = [ 'gosh' ], git = 'https://github.com/everx-labs/ever-block.git', tag = '1.10.0' }
ever_vm = { features = [ 'gosh' ], git = 'https://github.com/everx-labs/ever-vm.git', tag = '2.1.2' }
ever_abi = { git = 'https://github.com/everx-labs/ever-abi.git', tag = '2.5.2' }
ever_assembler = { features = [ 'gosh' ], git = 'https://github.com/everx-labs/ever-assembler.git', tag = '1.5.4' }
ever_block = { features = [ 'gosh' ], git = 'https://github.com/everx-labs/ever-block.git', tag = '1.10.1' }
ever_vm = { features = [ 'gosh' ], git = 'https://github.com/everx-labs/ever-vm.git', tag = '2.1.3' }

[dev-dependencies]
assert_cmd = '2.0.5'
Expand Down
152 changes: 10 additions & 142 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
# TVM linker

This repository stores the source code for tvm_linker utility. It takes TVM (https://test.ton.org/tvm.pdf)
assembly source code of TON smart contract, compiles it and links its parts, adds standard selector
and runtime and stores it into binary TVC file. Also, it can immediately execute a smart
contract by emulating the computing phase of TON transaction.

TVM assembly can be generated by one of TVM compilers:
- TVM solidity compiler (https://github.com/everx-labs/TVM-Solidity-Compiler)
- C and C++ compiler for TVM (https://github.com/everx-labs/TON-Compiler)
This repository stores the source code for `tvm_linker` utility. It can immediately execute a smart
contract by emulating the computing phase of transaction.

## Prerequisites

Expand All @@ -18,154 +12,28 @@ TVM assembly can be generated by one of TVM compilers:
## How to build

```bash
$ cargo update && cargo build --release -j8
$ cargo update && cargo build --release
```

## How to use

tvm_linker has several modes of work:

### 1) Generating a ready-to-deploy contract.

```bash
$ tvm_linker compile [--lib <lib_file>] [--abi-json <abi_file>] [-w <workchain_id>] [--debug] [--print_code] [--silent] [--debug-map <debug_info_path>] <source>
```

Here `source` is a name of tvm assembly source file, `library` is a runtime library file (can be more than one: `--lib`
should be supplied for every file). If `--lib` option is not specified linker looks for environment variable
`TVM_LINKER_LIB_PATH`, if it is set that path is used to load a library.

If there is an ABI file, it is better to use `--abi-json` option to supply a contract ABI file. Function IDs are
generated according to function signatures in the ABI. If neither `-a` nor `--abi-json` option is specified, linker
checks whether file `source`(without extension) + `.abi.json` exists. If file exists, linker loads ABI from it.

Linker generates the `<address>.tvc` file, where `<address>` is a hash from initial data and code of the contract.

Linker prints initial contract address in different formats: raw and user-friendly (testnet and mainnet). Define the workchain
ID option `-w` to generate proper user-friendly address. -1 is used by default.

To add a key to the contract data and obtain real contract address user should use [`ever-cli genaddr` command](https://github.com/everx-labs/ever-cli/blob/master/README.md#41-generate-contract-address).

While execution if option `--debug-map <debug_info_path>` is specified, this command can generate a debug info file,
which contains mapping that can bind contract code with source files. This file can be used while debugging the
contract.

`--print_code` option allows user only generate code and print it without creating the TVC file.
`--silent` option mutes all extra notifications.

### 2) Decoding of .boc messages prepared externally.
To use this method, call

```bash
$ tvm_linker decode [--tvc] boc-file
```

If `--tvc` is omitted, `boc-file` is a file with a serialized message, otherwise it is a contract `tvc` file.

### 3) Preparing an external inbound messages in .boc format.

First, generate a contract as described in 1). Then use `message` subcommand to create external inbound message in boc
format:
`tvm_linker` has several modes of work:

* Decoding of `.boc` messages prepared externally.
```bash
$ tvm_linker message <contract-address> [--init] [--data] [-w]
$ tvm_linker message <contract-address> [--init] --abi-json <abi_file> --abi-method <method_name> --abi-params {json_with_params} [-w]
tvm_linker decode ...
```

`contract-address` - the name of the compiled contract file without extension. The contract .tvc file should be placed in the current directory.

To create a `constructor message` with contract's code and data, use `--init` option.

Additionally, you can add a raw body to the message. Use the `--data` option:

* Preparing an external inbound messages in `.boc` format.
```bash
$ tvm_linker message <contract-address> --data <data_string>
tvm_linker message ...
```

Instead of `<data_string>`, specify the necessary message body in hex format.

Or make a message with ABI call using combination of options:
- `--abi-json <abi_file>` - path to a .json with contract interface described according to ABI specification;
- `--abi-method <method-name>` - name of the contract method to call;
- `--abi-params {<json-string-with-params>}` - arguments of the method declared in json like this: `{"arg_a": "0x1234", "arg_b": "x12345678"}`.

By default, -1 is used as a workchain id in contract address. To use another one, use `-w` option:

```bash
$ tvm_linker message -w 0
```

### 4) Emulating contract execution:
* Emulating contract execution:

Linker can emulate compute phase of blockchain transaction. It is useful for contract debugging.

```bash
$ tvm_linker test <contract-address> --body XXXX... [--sign key-file] [--trace] [--decode-c6] [--internal <value>] [--src address] [--now unixtime] [-s source-file] [--balance <value>]
tvm_linker test ...
```

Loads contract from file by contract address `address` and emulates contract call sending external inbound message (by default) with body defined after `--body` parameter to the contract. `XXXX...` is a hex string.

If `--sign` specified, the body will be signed with the private key from `key-file` file.

Use `--trace` flag to trace VM execution: stack, registers and gas will be printed after each executed VM command.

Use `--decode-c6` to see output actions in user-friendly format.

Use `--balance <value>` to define account balance in nanograms. It will be available at the bottom of initial stake and in SmartContractInfo tuple from c7 register .

Use `--config <tvc_file>` to define the config parameters to run VM with. The TVC file is a state of the config smart-contract.
The capabilities field of the config defines the VM mode of operation. If the config parameter is omitted, the capabilities default value of 0x880116ae is used.
For the available capability codes consult [here](https://github.com/everx-labs/ever-block/blob/master/src/config_params.rs#L336)

Note: configuration smart-contract resides at the address: -1:5555555555555555555555555555555555555555555555555555555555555555


Use `--internal` to send internal message to the contract with defined nanograms in `value`. By default, source address in internal message in zero address (`0000...0000`), to define another address use option `--src <address>`, where address should be in the format <wc>:<bytes32> (i.e. "0:1122...AABB").

Account and message balance can have extended format with extra currencies: `{ "main": int, "extra": {"i": int, ...} }`.

Example: `--internal 100000 --src "0:6011b66a47238cf992f1033fe6aff00ce0f850df387ee92468d9c26b5564ba53"`

Use `--now <unixtime>` option to define transaction creation time. By default, current time is used.

Use `--bounced` flag to emulate bounced internal message, use this flag only with `--internal` option.

An ABI body can be generated if `abi-params`, `abi-json` and `abi-method` will be used instead of `--body XXXX...`.

If `--body` is used, contract's public function ids can be encoded by their names using `$...$` syntax:`$name:[0len][type]$`,
where `name` is a name of public function, `len` - length in chars of the id (if `len` is bigger than `name`'s length in chars than
zeros will be added on the left side to fit required length), `type` can be `x` or `X` - hexadecimal integer in lowercase or uppercase. You have to set `-s source` option when you use $...$ syntax.

Example:

```bash
$ tvm_linker address test --body 00$main$ -s source //main id will be inserted as decimal string. Dont use this case, just as example
$ tvm_linker address test --body 00$main:08X$ -s source
$ tvm_linker address test --body 00$main:X$ -s source
$ tvm_linker address test --body 00$main:x$ -s source
```

The `--body-from-boc` option is analogous to `--body` but extracts the message body from the specified message boc file.

### 5) Disassembler

There are a number of tools under the `disasm` umbrella:

`dump` outputs a pseudo-graphical representation of a tree of cells.
`text` disassembles a tvc produced by Solidity and FunC compilers.
`graphviz` produces an output in dot format for generation of graphical DAG representation of a tvc.

### More Help
Use `tvm_linker --help` for detailed description about all options, flags and subcommands.

## Input format

As a temporary measure, some LLVM-assembler like input is used. The source code should contain several function types:

- `.internal` - special functions, which are used only by contract's runtime. There are some wellknown internal functions:

`main_external`, `main_internal`, `onTickTock`, `onBounce`.

## Support

Get more documents at docs.ton.dev and check our [YouTube Channel](https://www.youtube.com/channel/UC9kJ6DKaxSxk6T3lEGdq-Gg) for tutorials. Stay tuned.
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific TON DEV software governing permissions and
* See the License for the specific EVERX DEV software governing permissions and
* limitations under the License.
*/
use std::process::Command;
Expand Down
2 changes: 1 addition & 1 deletion src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific TON DEV software governing permissions and
* See the License for the specific EVERX DEV software governing permissions and
* limitations under the License.
*/
use ever_abi::{Contract, json_abi::{encode_function_call, decode_function_response}};
Expand Down
2 changes: 1 addition & 1 deletion src/keyman.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific TON DEV software governing permissions and
* See the License for the specific EVERX DEV software governing permissions and
* limitations under the License.
*/
use failure::format_err;
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific TON DEV software governing permissions and
* See the License for the specific EVERX DEV software governing permissions and
* limitations under the License.
*/

Expand Down
12 changes: 4 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific TON DEV software governing permissions and
* See the License for the specific EVERX DEV software governing permissions and
* limitations under the License.
*/

Expand Down Expand Up @@ -51,20 +51,17 @@ fn linker_main() -> Status {
);
let matches = clap_app!(tvm_linker =>
(version: build_info.as_str())
(author: "TON Labs")
(about: "Tool for executing TVM code")
(@subcommand decode =>
(about: "take apart a message boc or a tvc file")
(about: "Take apart a message boc or a tvc file")
(version: build_info.as_str())
(author: "TON Labs")
(@arg INPUT: +required +takes_value "BOC file")
(@arg TVC: --tvc "BOC file is tvc file")
)
(@subcommand test =>
(@setting AllowLeadingHyphen)
(about: "execute contract in test environment")
(about: "Execute contract in test environment")
(version: build_info.as_str())
(author: "TON Labs")
(@arg SOURCE: -s --source +takes_value "Contract source file")
(@arg BODY: --body +takes_value "Body for external inbound message (a bitstring like x09c_ or a hex string)")
(@arg BODY_FROM_BOC: --("body-from-boc") +takes_value "Body from message boc file")
Expand All @@ -90,9 +87,8 @@ fn linker_main() -> Status {
)
(@subcommand message =>
(@setting AllowNegativeNumbers)
(about: "generate inbound message for the blockchain")
(about: "Generate inbound message for the blockchain")
(version: build_info.as_str())
(author: "TON Labs")
(@arg INIT: -i --init "Generates constructor message with code and data of the contract")
(@arg DATA: -d --data +takes_value "Supplies body for the message in hex format (empty data by default)")
(@arg INTERNAL: --internal +takes_value "Generates inbound internal message with provided value (instead of external message by default)")
Expand Down
2 changes: 1 addition & 1 deletion src/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific TON DEV software governing permissions and
* See the License for the specific EVERX DEV software governing permissions and
* limitations under the License.
*/
use failure::format_err;
Expand Down
2 changes: 1 addition & 1 deletion src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific TON DEV software governing permissions and
* See the License for the specific EVERX DEV software governing permissions and
* limitations under the License.
*/
use base64::encode;
Expand Down
2 changes: 1 addition & 1 deletion src/testcall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific TON DEV software governing permissions and
* See the License for the specific EVERX DEV software governing permissions and
* limitations under the License.
*/

Expand Down

0 comments on commit f47ce50

Please sign in to comment.