diff --git a/.github/workflows/qa.yml b/.github/workflows/qa.yml new file mode 100644 index 0000000..63d2296 --- /dev/null +++ b/.github/workflows/qa.yml @@ -0,0 +1,37 @@ +name: QA + +on: + pull_request: + branches: + - main + +defaults: + run: + shell: bash + +jobs: + qa: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v2 + + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + profile: minimal + components: rustfmt, clippy + override: true + + - uses: actions/cache@v3 + continue-on-error: false + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ${{ runner.os }}-cargo-${{ hashFiles('Cargo.lock') }} + + - run: | + make qa diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..57f6531 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,93 @@ +name: Release + +on: + push: + tags: + - '*' + +defaults: + run: + shell: bash + +jobs: + qa: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v2 + + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + profile: minimal + components: rustfmt, clippy + override: true + + - uses: actions/cache@v3 + continue-on-error: false + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ${{ runner.os }}-cargo-${{ hashFiles('Cargo.lock') }} + + - run: | + make qa + + build: + needs: + - qa + runs-on: ${{ matrix.platform.on }} + name: ${{ matrix.platform.name }} + strategy: + fail-fast: false + matrix: + platform: + - { on: ubuntu-20.04, name: linux-amd64, target: x86_64-unknown-linux-musl } + - { on: ubuntu-20.04, name: freebsd-amd64, target: x86_64-unknown-freebsd } + - { on: macos-11, name: darwin-amd64, target: x86_64-apple-darwin } + - { on: macos-11, name: darwin-arm64, target: aarch64-apple-darwin } + - { on: windows-2022, name: windows-amd64, target: x86_64-pc-windows-gnu } + + steps: + - uses: actions/checkout@v2 + + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + target: ${{ matrix.platform.target }} + profile: minimal + override: true + + - uses: actions/cache@v3 + continue-on-error: false + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ${{ runner.os }}-cargo-release-${{ hashFiles('Cargo.lock') }} + + - run: | + make release + tar -czvf sold-${{ github.ref_name }}-${{ matrix.platform.name }}.tar.gz -C release sold* + + - uses: actions/upload-artifact@v3 + with: + name: sold-${{ github.ref_name }}-${{ matrix.platform.name }} + path: | + release/sold* + + - uses: softprops/action-gh-release@v1 + if: ${{ startsWith(github.ref, 'refs/tags/') }} + with: + draft: false + files: | + sold-${{ github.ref_name }}-${{ matrix.platform.name }}.tar.gz + prerelease: true + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index 1457516..68ea87e 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ build/ sold/target/ target/ .idea/ +.deps-ready +release diff --git a/API.md b/API.md index 082a7c8..a8b8955 100644 --- a/API.md +++ b/API.md @@ -1,13 +1,12 @@ -# **TON Solidity API** +# **Ever Solidity** -TON Solidity compiler expands Solidity language with different API functions to facilitate TON -contract development. +Ever Solidity compiler expands Solidity language with different API functions to facilitate contract development. ## Table of Contents * [Compiler version](#compiler-version) -* [TON specific types](#ton-specific-types) - * [TON units](#ton-units) +* [Specific types](#specific-types) + * [Units](#units) * [TvmCell](#tvmcell) * [\.depth()](#tvmcelldepth) * [\.dataSize()](#tvmcelldatasize) @@ -68,10 +67,10 @@ contract development. * [\.pop()](#vectortypepop) * [\.length()](#vectortypelength) * [\.empty()](#vectortypeempty) -* [TON specific control structures](#ton-specific-control-structures) +* [Specific control structures](#specific-control-structures) * [Range-based for loop](#range-based-for-loop) * [repeat](#repeat) - * [try-catch](#trycatch) + * [try-catch](#try-catch) * [Changes and extensions in Solidity types](#changes-and-extensions-in-solidity-types) * [Integers](#integers) * [bitSize() and uBitSize()](#bitsize-and-ubitsize) @@ -274,7 +273,7 @@ contract development. ### Compiler version -TON Solidity compiler add its current version to the generated code. This version can be obtained: +Ever Solidity compiler add its current version to the generated code. This version can be obtained: 1) using [tvm_linker](https://github.com/tonlabs/TVM-linker#2-decoding-of-boc-messages-prepared-externally) from a `*.tvc` file: @@ -288,13 +287,13 @@ tvm_linker decode --tvm tonos-cli decode tvc [--tvc] [--boc] ``` -### TON specific types +### Specific types -TON Solidity compiler expands functionality of some existing types and adds several new TVM specific types: TvmCell, TvmSlice, TvmBuilder and ExtraCurrencyCollection. Full description of these types can be found in [TVM][1] and [TON Blockchain][2] specifications. +Ever Solidity compiler expands functionality of some existing types and adds several new TVM specific types: TvmCell, TvmSlice, TvmBuilder and ExtraCurrencyCollection. Full description of these types can be found in [TVM][1] and [TON Blockchain][2] specifications. -#### TON units +#### Units -A literal number can take a suffix to specify a subdenomination of TON currency, where numbers without a postfix are assumed to be nanotons. +A literal number can take a suffix to specify a subdenomination of currency, where numbers without a postfix are assumed to be nanotons. ```TVMSolidity uint a0 = 1 nano; // a0 == 1 @@ -645,7 +644,7 @@ Skips the first `length` bits and `refs` references from the `TvmSlice`. #### TvmBuilder -`TvmBuilder` represents *TVM cell builder* ([TVM][1] - 1.1.3). TON Solidity compiler defines the following +`TvmBuilder` represents *TVM cell builder* ([TVM][1] - 1.1.3). Ever Solidity compiler defines the following functions to work with this type: ##### \.toSlice() @@ -994,7 +993,7 @@ vector(uint) vect; bool is_empty = vect.empty(); ``` -### TON specific control structures +### Specific control structures ### Range-based for loop @@ -1376,7 +1375,7 @@ If `bytes` object has less than **N** bytes, extra bytes are padded with zero bi #### string -TON Solidity compiler expands `string` type with the following functions: +Ever Solidity compiler expands `string` type with the following functions: **Note**: Due to VM restrictions string length can't exceed `1024 * 127 = 130048` bytes. @@ -1558,7 +1557,7 @@ If `string` object has less than **N** bytes, extra bytes are padded with zero b #### address `address` represents different types of TVM addresses: **addr_none**, **addr_extern**, -**addr_std** and **addr_var**. TON Solidity compiler expands `address` type with the following +**addr_std** and **addr_var**. Ever Solidity compiler expands `address` type with the following members and functions: ##### Object creating @@ -1771,7 +1770,7 @@ See example of `address.transfer()` usage: #### mapping -TON Solidity compiler expands `mapping` type with the following functions. In examples +Ever Solidity compiler expands `mapping` type with the following functions. In examples below `\` defines the object of `mapping(KeyType => ValueType)` type. Address, bytes, string, bool, contract, enum, fixed bytes, integer and struct types can @@ -1805,6 +1804,9 @@ If `bytes`, `string` or `TvmCell` types are used as `KeyType` then `mapping` sto only hashes of mapping keys. That's why for these types the `delMin`/`min`/`next` and another mapping methods return `uint256` as key (not `bytes`/`string`/`TvmCell`). +If you use mapping as an input or output param for public/external functions, +`KeyType` of the mapping can only be of type `address` or of `int`/`uint` types with M from 8 to 256. + See example of how to work with mappings: * [database](https://github.com/tonlabs/samples/blob/master/solidity/13_BankCollector.sol) @@ -2146,7 +2148,7 @@ contract MyContract { ##### Function call via object -In TON solidity **arguments of a function call passed by value not by +In Ever Solidity **arguments of a function call passed by value not by reference**. It's effective for numbers and even for huge arrays. See ([TVM][1] - A.2.3.2). **But if a library function is called like `obj.func(b, c)` then the @@ -2202,7 +2204,7 @@ contract MyContract { ### Import -TON Solidity compiler allows user to import remote files using link starting with `http`. +Ever Solidity compiler allows user to import remote files using link starting with `http`. If import file name starts with `http`, then compiler tries to download the file using this link and saves it to the folder `.solc_imports`. If compiler fails to create this folder or to download the file, then an error is emitted. @@ -2283,7 +2285,7 @@ pragma AbiHeader expire; Defines headers that are used in external messages: -* `pubkey` (`uint256`) - optional public key that the message can be signed with. +* `pubkey` (`uint256`) - optional public key that can be used to verify the signature of the message. * `time` (`uint64`) - local time when message was created. Used for replay protection. * `expire` (`uint32`) - time when the message should be meant as expired. @@ -2556,6 +2558,9 @@ function onCodeUpgrade(...) private { } ``` +Function `onCodeUpgrade` had function id = 2 (for compiler <= 0.65.0). Now, it has another id, but you can set +`functionID(2)` in new contracts for the `onCodeUpgrade` to upgrade old ones. + See example of how to upgrade code of the contract: * [old contract](https://github.com/tonlabs/samples/blob/master/solidity/12_BadContract.sol) @@ -2765,7 +2770,7 @@ function f(uint n) public responsible pure { ### External function calls -TON Solidity compiler allows specifying different parameters of the outbound internal message that +Ever Solidity compiler allows specifying different parameters of the outbound internal message that is sent via external function call. Note, all external function calls are asynchronous, so callee function will be called after termination of the current transaction. `value`, `currencies`, `bounce` or `flag` options can be set. See [\.transfer()](#addresstransfer) @@ -2849,7 +2854,7 @@ and [4.1_CurrencyExchange.sol](https://github.com/tonlabs/samples/blob/master/so #### Synchronous calls -TON Solidity compiler allows user to perform synchronous calls. To do it user should call a remote contract +Ever Solidity compiler allows user to perform synchronous calls. To do it user should call a remote contract function with `.await` suffix. Example: ```TVMSolidity @@ -3494,7 +3499,7 @@ uint16 dataDepth = data.depth(); uint256 hash = tvm.stateInitHash(codeHash, dataHash, codeDepth, dataDepth); ``` -See also [internal doc](https://github.com/tonlabs/TON-Solidity-Compiler/blob/master/docs/internal/stateInit_hash.md) to read more about this +See also [internal doc](docs/internal/stateInit_hash.md) to read more about this function mechanics. ##### Deploy via new @@ -4174,7 +4179,7 @@ Returns the starting logical time of the current block. The pseudorandom number generator uses the random seed. The initial value of the random seed before a smart contract execution in -TON Blockchain is a hash of the smart contract address and the global +Everscale is a hash of the smart contract address and the global block random seed. If there are several runs of the same smart contract inside a block, then all of these runs will have the same random seed. This can be fixed, for example, by running `rnd.shuffle()` (without diff --git a/Cargo.lock b/Cargo.lock index 515cbef..3344dd9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -58,9 +58,9 @@ checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" [[package]] name = "assert_cmd" -version = "2.0.4" +version = "2.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93ae1ddd39efd67689deb1979d80bad3bf7f2b09c6e6117c8d1f2443b5e2f83e" +checksum = "d5c2ca00549910ec251e3bd15f87aeeb206c9456b9a77b43ff6c97c54042a472" dependencies = [ "bstr", "doc-comment", @@ -113,32 +113,9 @@ dependencies = [ [[package]] name = "base64" -version = "0.13.0" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" - -[[package]] -name = "bindgen" -version = "0.60.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "062dddbc1ba4aca46de6338e2bf87771414c335f7b2f2036e8f3e9befebf88e6" -dependencies = [ - "bitflags", - "cexpr", - "clang-sys", - "clap 3.2.22", - "env_logger", - "lazy_static", - "lazycell", - "log", - "peeking_take_while", - "proc-macro2", - "quote", - "regex", - "rustc-hash", - "shlex", - "which", -] +checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" [[package]] name = "bitflags" @@ -215,9 +192,9 @@ checksum = "b4ae4235e6dac0694637c763029ecea1a2ec9e4e06ec2729bd21ba4d9c863eb7" [[package]] name = "bumpalo" -version = "3.11.0" +version = "3.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1ad822118d20d2c234f427000d5acc36eabe1e29a348c89b63dd60b13f28e5d" +checksum = "572f695136211188308f16ad2ca5c851a712c464060ae6974944458eb83880ba" [[package]] name = "byte-tools" @@ -240,15 +217,6 @@ dependencies = [ "jobserver", ] -[[package]] -name = "cexpr" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" -dependencies = [ - "nom", -] - [[package]] name = "cfg-if" version = "1.0.0" @@ -270,17 +238,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "clang-sys" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa2e27ae6ab525c3d369ded447057bca5438d86dc3a68f6faafb8269ba82ebf3" -dependencies = [ - "glob", - "libc", - "libloading", -] - [[package]] name = "clap" version = "2.34.0" @@ -291,36 +248,21 @@ dependencies = [ "atty", "bitflags", "strsim 0.8.0", - "textwrap 0.11.0", + "textwrap", "unicode-width", "vec_map", ] [[package]] name = "clap" -version = "3.2.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86447ad904c7fb335a790c9d7fe3d0d971dc523b8ccd1561a520de9a85302750" -dependencies = [ - "atty", - "bitflags", - "clap_lex 0.2.4", - "indexmap", - "strsim 0.10.0", - "termcolor", - "textwrap 0.15.1", -] - -[[package]] -name = "clap" -version = "4.0.14" +version = "4.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ea54a38e4bce14ff6931c72e5b3c43da7051df056913d4e7e1fcdb1c03df69d" +checksum = "335867764ed2de42325fafe6d18b8af74ba97ee0c590fa016f157535b42ab04b" dependencies = [ "atty", "bitflags", "clap_derive", - "clap_lex 0.3.0", + "clap_lex", "once_cell", "strsim 0.10.0", "termcolor", @@ -328,9 +270,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.0.13" +version = "4.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c42f169caba89a7d512b5418b09864543eeb4d497416c917d7137863bd2076ad" +checksum = "16a1b0f6422af32d5da0c58e2703320f379216ee70198241c84173a8c5ac28f3" dependencies = [ "heck", "proc-macro-error", @@ -339,15 +281,6 @@ dependencies = [ "syn", ] -[[package]] -name = "clap_lex" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" -dependencies = [ - "os_str_bytes", -] - [[package]] name = "clap_lex" version = "0.3.0" @@ -455,9 +388,9 @@ dependencies = [ [[package]] name = "cxx" -version = "1.0.78" +version = "1.0.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19f39818dcfc97d45b03953c1292efc4e80954e1583c4aa770bac1383e2310a4" +checksum = "6b7d4e43b25d3c994662706a1d4fcfc32aaa6afd287502c111b237093bb23f3a" dependencies = [ "cc", "cxxbridge-flags", @@ -467,9 +400,9 @@ dependencies = [ [[package]] name = "cxx-build" -version = "1.0.78" +version = "1.0.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e580d70777c116df50c390d1211993f62d40302881e54d4b79727acb83d0199" +checksum = "84f8829ddc213e2c1368e51a2564c552b65a8cb6a28f31e576270ac81d5e5827" dependencies = [ "cc", "codespan-reporting", @@ -482,15 +415,15 @@ dependencies = [ [[package]] name = "cxxbridge-flags" -version = "1.0.78" +version = "1.0.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56a46460b88d1cec95112c8c363f0e2c39afdb237f60583b0b36343bf627ea9c" +checksum = "e72537424b474af1460806647c41d4b6d35d09ef7fe031c5c2fa5766047cc56a" [[package]] name = "cxxbridge-macro" -version = "1.0.78" +version = "1.0.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "747b608fecf06b0d72d440f27acc99288207324b793be2c17991839f3d4995ea" +checksum = "309e4fb93eed90e1e14bea0da16b209f81813ba9fc7830c20ed151dd7bc0a4d7" dependencies = [ "proc-macro2", "quote", @@ -592,19 +525,6 @@ version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" -[[package]] -name = "env_logger" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c90bf5f19754d10198ccb95b70664fc925bd1fc090a0fd9a6ebc54acc8cd6272" -dependencies = [ - "atty", - "humantime", - "log", - "regex", - "termcolor", -] - [[package]] name = "failure" version = "0.1.8" @@ -674,9 +594,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.7" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6" +checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" dependencies = [ "cfg-if", "libc", @@ -689,18 +609,6 @@ version = "0.26.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "22030e2c5a68ec659fde1e949a745124b48e6fa8b045b7ed5bd1fe4ccc5c4e5d" -[[package]] -name = "glob" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" - -[[package]] -name = "hashbrown" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" - [[package]] name = "heck" version = "0.4.0" @@ -728,12 +636,6 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" -[[package]] -name = "humantime" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" - [[package]] name = "iana-time-zone" version = "0.1.51" @@ -750,24 +652,14 @@ dependencies = [ [[package]] name = "iana-time-zone-haiku" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fde6edd6cef363e9359ed3c98ba64590ba9eecba2293eb5a723ab32aee8926aa" +checksum = "0703ae284fc167426161c2e3f1da3ea71d94b21bedbcc9494e92b28e334e3dca" dependencies = [ "cxx", "cxx-build", ] -[[package]] -name = "indexmap" -version = "1.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" -dependencies = [ - "autocfg", - "hashbrown", -] - [[package]] name = "itertools" version = "0.10.5" @@ -807,27 +699,11 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" -[[package]] -name = "lazycell" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" - [[package]] name = "libc" -version = "0.2.135" +version = "0.2.136" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68783febc7782c6c5cb401fbda4de5a9898be1762314da0bb2c10ced61f18b0c" - -[[package]] -name = "libloading" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "efbc0f03f9a775e9f6aed295c6a1ba2253c5757a9e03d55c6caa46a681abcddd" -dependencies = [ - "cfg-if", - "winapi", -] +checksum = "55edcf6c0bb319052dea84732cf99db461780fd5e8d3eb46ab6ff312ab31f197" [[package]] name = "link-cplusplus" @@ -861,12 +737,6 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" -[[package]] -name = "minimal-lexical" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" - [[package]] name = "miniz_oxide" version = "0.5.4" @@ -876,16 +746,6 @@ dependencies = [ "adler", ] -[[package]] -name = "nom" -version = "7.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8903e5a29a317527874d0402f867152a3d21c908bb0b933e416c65e301d4c36" -dependencies = [ - "memchr", - "minimal-lexical", -] - [[package]] name = "normalize-line-endings" version = "0.3.0" @@ -1018,12 +878,6 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "30fceb411f9a12ff9222c5f824026be368ff15dc2f13468d850c7d3f502205d6" -[[package]] -name = "peeking_take_while" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" - [[package]] name = "ppv-lite86" version = "0.2.16" @@ -1086,9 +940,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.46" +version = "1.0.47" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94e2ef8dbfc347b10c094890f778ee2e36ca9bb4262e86dc99cd217e35f3470b" +checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725" dependencies = [ "unicode-ident", ] @@ -1161,7 +1015,7 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "getrandom 0.2.7", + "getrandom 0.2.8", ] [[package]] @@ -1219,7 +1073,7 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4b18820d944b33caa75a71378964ac46f58517c92b6ae5f762636247c09e78fb" dependencies = [ - "base64 0.13.0", + "base64 0.13.1", "blake2b_simd", "constant_time_eq", "crossbeam-utils", @@ -1231,12 +1085,6 @@ version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342" -[[package]] -name = "rustc-hash" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" - [[package]] name = "ryu" version = "1.0.11" @@ -1251,18 +1099,18 @@ checksum = "9c8132065adcfd6e02db789d9285a0deb2f3fcb04002865ab67d5fb103533898" [[package]] name = "serde" -version = "1.0.145" +version = "1.0.147" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "728eb6351430bccb993660dfffc5a72f91ccc1295abaa8ce19b27ebe4f75568b" +checksum = "d193d69bae983fc11a79df82342761dfbf28a99fc8d203dca4c3c1b590948965" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.145" +version = "1.0.147" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fa1584d3d1bcacd84c277a0dfe21f5b0f6accf4a23d04d4c6d61f1af522b4c" +checksum = "4f1d362ca8fc9c3e3a7484440752472d68a6caa98f1ab81d99b5dfe517cec852" dependencies = [ "proc-macro2", "quote", @@ -1271,9 +1119,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.86" +version = "1.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41feea4228a6f1cd09ec7a3593a682276702cd67b5273544757dae23c096f074" +checksum = "6ce777b7b150d76b9cf60d28b55f5847135a003f7d7350c6be7a773508ce7d45" dependencies = [ "itoa", "ryu", @@ -1316,12 +1164,6 @@ dependencies = [ "digest 0.10.5", ] -[[package]] -name = "shlex" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3" - [[package]] name = "signature" version = "1.6.4" @@ -1356,12 +1198,11 @@ checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" [[package]] name = "sold" -version = "0.65.0" +version = "0.66.6" dependencies = [ "assert_cmd", "atty", - "bindgen", - "clap 4.0.14", + "clap 4.0.18", "cmake", "dunce", "failure", @@ -1405,9 +1246,9 @@ checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" [[package]] name = "syn" -version = "1.0.102" +version = "1.0.103" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fcd952facd492f9be3ef0d0b7032a6e442ee9b361d4acc2b1d0c4aaa5f613a1" +checksum = "a864042229133ada95abf3b54fdc62ef5ccabe9515b64717bcb9a1919e59445d" dependencies = [ "proc-macro2", "quote", @@ -1461,12 +1302,6 @@ dependencies = [ "unicode-width", ] -[[package]] -name = "textwrap" -version = "0.15.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "949517c0cf1bf4ee812e2e07e08ab448e3ae0d23472aee8a06c985f0c8815b16" - [[package]] name = "time" version = "0.1.44" @@ -1505,7 +1340,7 @@ name = "ton_block" version = "1.8.3" source = "git+https://github.com/tonlabs/ton-labs-block.git?tag=1.8.3#19a77eb0cccf6dc097ac934458976e1e91402ade" dependencies = [ - "base64 0.13.0", + "base64 0.13.1", "crc 3.0.0", "ed25519", "ed25519-dalek", @@ -1538,7 +1373,7 @@ name = "ton_types" version = "1.11.4" source = "git+https://github.com/tonlabs/ton-labs-types.git?tag=1.11.4#7f0063faa486298ba57ceb97e1d6e38447d6e0e3" dependencies = [ - "base64 0.13.0", + "base64 0.13.1", "crc 1.8.1", "failure", "hex 0.4.3", @@ -1577,10 +1412,10 @@ dependencies = [ [[package]] name = "tvm_linker" -version = "0.18.3" -source = "git+https://github.com/tonlabs/TVM-linker.git?tag=0.18.3#afb91fa5bac8d4343fa38bd510d0f5a47cf86278" +version = "0.18.4" +source = "git+https://github.com/tonlabs/TVM-linker.git?tag=0.18.4#4e97449a48c05600af00027d652519de61190b53" dependencies = [ - "base64 0.13.0", + "base64 0.13.1", "clap 2.34.0", "crc 3.0.0", "ed25519", @@ -1591,7 +1426,7 @@ dependencies = [ "log", "num", "num-traits", - "rand 0.7.3", + "rand 0.8.5", "regex", "serde", "serde_json", @@ -1748,17 +1583,6 @@ version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f" -[[package]] -name = "which" -version = "4.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c831fbbee9e129a8cf93e7747a82da9d95ba8e16621cae60ec2cdc849bacb7b" -dependencies = [ - "either", - "libc", - "once_cell", -] - [[package]] name = "winapi" version = "0.3.9" diff --git a/Cargo.toml b/Cargo.toml index b3eb5ca..6da6461 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,3 +2,6 @@ members = [ 'sold' ] + +[profile.release] +strip = true # Automatically strip symbols from the binary. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f47fc54 --- /dev/null +++ b/Makefile @@ -0,0 +1,35 @@ +UNAME := $(shell uname) + +ifeq ($(UNAME), win) +TARGET = sold.exe +else +TARGET = sold +endif + +.deps-ready: + bash script/toolchain.sh -s + touch .deps-ready + +clean: + rm -fr release + cargo clean + +test: .deps-ready + cargo test + +fmt: + cargo fmt + +lint: .deps-ready + cargo fmt --all -- --check + cargo clippy --all-targets + +qa: lint test + +target/release/$(TARGET): .deps-ready + cargo build --release + +release: target/release/$(TARGET) + mkdir -p release + cp target/release/$(TARGET) release/ + diff --git a/README.md b/README.md index 831a82e..7e3421b 100644 --- a/README.md +++ b/README.md @@ -1,62 +1,17 @@ -# Sol2TVM Compiler +
+

ever-solidity

+

+ Solidity compiler for Everscale Virtual Machine +

+
-Port of the Solidity smart-contract [compiler](https://github.com/ethereum/solidity) generating TVM bytecode for TON blockchain. Please refer to upstream README.md for information on the language itself. +- [Documentation](API.md) +- [Getting started with smart contracts development](https://docs.everscale.network/develop/smart-contract/getting-started/) +- [Changelog](changelog.md) -## TON Solidity API reference - -[API documentation is here](https://github.com/tonlabs/TON-Solidity-Compiler/blob/master/API.md) - -## Build and Install - -Original Instructions about how to build and install the Solidity compiler can be found in the [Solidity documentation](https://solidity.readthedocs.io/en/latest/installing-solidity.html#building-from-source). - -### Ubuntu Linux - -```shell -git clone git@github.com:tonlabs/TON-Solidity-Compiler.git -cd TON-Solidity-Compiler -sh ./compiler/scripts/install_deps.sh -mkdir build -cd build -cmake ../compiler/ -DCMAKE_BUILD_TYPE=Release -cmake --build . -- -j8 -``` - -Make other TON toolchain utilities aware of the language runtime library location via an environment variable: specify path to `stdlib_sol.tvm`. - -```shell -sh ./compiler/scripts/install_lib_variable.sh -``` - -### Windows 10 - -Install Visual Studio, Git bash, cmake. -Run Visual Studio Developer Command Prompt +## Build ```shell -git clone https://github.com/tonlabs/TON-Solidity-Compiler -cd TON-Solidity-Compiler -cmake -P compiler\scripts\install_deps.cmake -mkdir build -cd build -cmake ..\compiler -cmake --build . --config Release -j 8 +make qa +make release ``` - -To facilitate work with other TON tools add path to stdlib_sol.tvm into environment variable TVM_LINKER_LIB_PATH. - -## Sold driver - -Documentation is available at [README.md](https://github.com/tonlabs/TON-Solidity-Compiler/blob/master/sold/README.md). - -## Links - -Code samples in Solidity for TON can be found there: [https://github.com/tonlabs/samples/tree/master/solidity](https://github.com/tonlabs/samples/tree/master/solidity) - -TVM linker repository: [https://github.com/tonlabs/TVM-linker](https://github.com/tonlabs/TVM-linker) - -TON OS command line tool: [https://github.com/tonlabs/tonos-cli](https://github.com/tonlabs/tonos-cli) - -Example of usage TON OS for working (deploying, calling and etc.) with TON blockchain can be found there: [Write smart contract in Solidity](https://docs.ton.dev/86757ecb2/p/950f8a-write-smart-contract-in-solidity) - -Change log: [Changelog_TON.md](https://github.com/tonlabs/TON-Solidity-Compiler/blob/master/Changelog_TON.md) diff --git a/Changelog_TON.md b/changelog.md similarity index 98% rename from Changelog_TON.md rename to changelog.md index 0a7f464..4c1e2d8 100644 --- a/Changelog_TON.md +++ b/changelog.md @@ -1,3 +1,13 @@ +### 0.66.0 (2022-10-25) + +Bugfixes: + * Fixed problem with getting inherited function `afterSignatureCheck`. + * Support overloading for function `onCodeUpgrade`. + +Breaking change: + * Function `onCodeUpgrade` had function id = 2. Now, it has another id, but you can set `functionID(2)` in new +contracts to upgrade old ones. + ### 0.65.0 (2022-10-08) Compiler features: diff --git a/compiler/CMakeLists.txt b/compiler/CMakeLists.txt index b997ac1..dfd31ee 100644 --- a/compiler/CMakeLists.txt +++ b/compiler/CMakeLists.txt @@ -10,7 +10,7 @@ include(EthPolicy) eth_policy() # project name and version should be set after cmake_policy CMP0048 -set(PROJECT_VERSION "0.65.0") +set(PROJECT_VERSION "0.66.0") project(solidity VERSION ${PROJECT_VERSION} LANGUAGES C CXX) include(TestBigEndian) diff --git a/compiler/libsolidity/analysis/TypeChecker.cpp b/compiler/libsolidity/analysis/TypeChecker.cpp index e17cbc6..ef6f5a1 100644 --- a/compiler/libsolidity/analysis/TypeChecker.cpp +++ b/compiler/libsolidity/analysis/TypeChecker.cpp @@ -3622,7 +3622,17 @@ bool TypeChecker::visit(FunctionCallOptions const& _functionCallOptions) int setFlags = -1; FunctionType::Kind kind = expressionFunctionType->kind(); + + bool isLib = false; + if (expressionFunctionType->hasDeclaration()) { + if (auto func = dynamic_cast(&expressionFunctionType->declaration())) { + if (func->annotation().contract->isLibrary()) { + isLib = true; + } + } + } if ( + !isLib && kind != FunctionType::Kind::Creation && kind != FunctionType::Kind::External && kind != FunctionType::Kind::BareCall && diff --git a/compiler/libsolidity/ast/Types.cpp b/compiler/libsolidity/ast/Types.cpp index ab90e81..fa4d369 100644 --- a/compiler/libsolidity/ast/Types.cpp +++ b/compiler/libsolidity/ast/Types.cpp @@ -5090,6 +5090,15 @@ MemberList::MemberMap TvmBuilderType::nativeMembers(const ContractDefinition *) false, StateMutability::Pure )); + members.emplace_back("toExotic", TypeProvider::function( + TypePointers{}, + TypePointers{TypeProvider::tvmcell()}, + strings{}, + strings{string()}, + FunctionType::Kind::TVMBuilderMethods, + false, StateMutability::Pure + )); + members.emplace_back("toSlice", TypeProvider::function( TypePointers{}, TypePointers{TypeProvider::tvmslice()}, diff --git a/compiler/libsolidity/codegen/TVMAnalyzer.cpp b/compiler/libsolidity/codegen/TVMAnalyzer.cpp index ffd759c..8372765 100644 --- a/compiler/libsolidity/codegen/TVMAnalyzer.cpp +++ b/compiler/libsolidity/codegen/TVMAnalyzer.cpp @@ -38,11 +38,28 @@ bool TVMAnalyzer::analyze(const SourceUnit &_sourceUnit) bool TVMAnalyzer::visit(MemberAccess const& _node) { auto funType = to(_node.annotation().type); if (funType) { - if (funType->bound() && (m_functionCall.empty() || m_functionCall.back()->expression() != _node)) { - m_errorReporter.fatalTypeError( + if (funType->bound()) { + auto printError = [&]{ + m_errorReporter.fatalTypeError( _node.location(), - "Function references are not supported for structures." - ); + "Function references are not supported if the function is called as arg1.fun(arg2, ..., argn)." + ); + }; + + if (m_functionCall.empty()) { + printError(); + } else { + Expression const& expr = m_functionCall.back()->expression(); + Expression const* targetExpr{}; + if (auto opt = dynamic_cast(&expr)) { + targetExpr = &opt->expression(); + } else { + targetExpr = &m_functionCall.back()->expression(); + } + if (*targetExpr != _node) { + printError(); + } + } } } return true; diff --git a/compiler/libsolidity/codegen/TVMCommons.cpp b/compiler/libsolidity/codegen/TVMCommons.cpp index 25b8043..579800c 100644 --- a/compiler/libsolidity/codegen/TVMCommons.cpp +++ b/compiler/libsolidity/codegen/TVMCommons.cpp @@ -463,6 +463,9 @@ ABITypeSize::ABITypeSize(const Type *type) { } else if (to(type)) { maxBits = 32; maxRefs = 0; + } else if (to(type) || to(type)) { + maxBits = 1023; + maxRefs = 3; } else { solUnimplemented("Undefined type: " + type->toString()); } diff --git a/compiler/libsolidity/codegen/TVMFunctionCall.cpp b/compiler/libsolidity/codegen/TVMFunctionCall.cpp index 7792469..b39572b 100644 --- a/compiler/libsolidity/codegen/TVMFunctionCall.cpp +++ b/compiler/libsolidity/codegen/TVMFunctionCall.cpp @@ -1766,6 +1766,12 @@ bool FunctionCallCompiler::checkForTvmBuilderMethods(MemberAccess const &_node, return true; } + if (_node.memberName() == "toExotic") { + acceptExpr(&_node.expression()); + m_pusher.push(-1+1, "ENDXC"); + return true; + } + if (_node.memberName() == "toSlice") { acceptExpr(&_node.expression()); m_pusher.push(-1+1, "ENDC"); @@ -2935,8 +2941,8 @@ bool FunctionCallCompiler::checkLocalFunctionOrLibCall(const Identifier *identif ContractDefinition const* contractDecl= funDecl.annotation().contract; bool isLib = contractDecl->isLibrary(); std::string name; + auto fd = to(&funDecl); if (isLib) { - auto fd = to(&funDecl); name = TVMCompilerContext::getLibFunctionName(fd, false); } else { name = m_pusher.ctx().getFunctionInternalName(functionDefinition, false); @@ -3732,4 +3738,4 @@ void FunctionCallCompiler::cellBitRefQty(bool forCell) { m_pusher.ifElse(); m_pusher.endOpaque(2, 1, true); -} \ No newline at end of file +} diff --git a/compiler/libsolidity/codegen/TVMFunctionCompiler.cpp b/compiler/libsolidity/codegen/TVMFunctionCompiler.cpp index 1983543..a2117a4 100644 --- a/compiler/libsolidity/codegen/TVMFunctionCompiler.cpp +++ b/compiler/libsolidity/codegen/TVMFunctionCompiler.cpp @@ -328,7 +328,9 @@ TVMFunctionCompiler::generateOnCodeUpgrade(TVMCompilerContext& ctx, FunctionDefi pusher.push(0, "COMMIT"); pusher._throw("THROW 0"); int take = function->parameters().size(); - return createNode(take, 0, "onCodeUpgrade", Function::FunctionType::OnCodeUpgrade, pusher.getBlock()); + const std::string name = ctx.getFunctionInternalName(function, false); + return createNode(take, 0, name, Function::FunctionType::OnCodeUpgrade, + pusher.getBlock(), function); } Pointer diff --git a/compiler/libsolidity/codegen/TVMPusher.cpp b/compiler/libsolidity/codegen/TVMPusher.cpp index 1ac4404..58c7477 100644 --- a/compiler/libsolidity/codegen/TVMPusher.cpp +++ b/compiler/libsolidity/codegen/TVMPusher.cpp @@ -2053,7 +2053,7 @@ void StackPusher::pushCallOrCallRef( ret = ft->returnParameterTypes().size(); } - if (boost::ends_with(functionName, "_macro") || functionName == ":onCodeUpgrade") { + if (boost::ends_with(functionName, "_macro")) { pushMacroCallInCallRef(take, ret, functionName); return; } @@ -2061,8 +2061,10 @@ void StackPusher::pushCallOrCallRef( auto _to = to(&ft->declaration()); FunctionDefinition const* v = m_ctx->getCurrentFunction(); bool hasLoop = m_ctx->addAndDoesHaveLoop(v, _to); - if (hasLoop) { - pushPrivateFunctionId(*_to); + auto fd = to(&ft->declaration()); + const bool isOnCodeUpgrade = fd->name() == "onCodeUpgrade"; + if (hasLoop || isOnCodeUpgrade) { + pushPrivateFunctionId(*_to); pushC3(); execute(take + 2, ret); } else { @@ -2559,9 +2561,6 @@ string TVMCompilerContext::getFunctionInternalName(FunctionDefinition const* _fu if (isStdlib()) { return _function->name(); } - if (_function->name() == "onCodeUpgrade") { - return ":onCodeUpgrade"; - } if (_function->isFallback()) { return "fallback"; } @@ -2606,12 +2605,16 @@ bool TVMCompilerContext::ignoreIntegerOverflow() const { } FunctionDefinition const *TVMCompilerContext::afterSignatureCheck() const { - for (FunctionDefinition const* f : m_contract->definedFunctions()) { - if (f->name() == "afterSignatureCheck") { - return f; + FunctionDefinition const *res = {}; + for (ContractDefinition const* c : m_contract->annotation().linearizedBaseContracts) { + for (FunctionDefinition const *f: c->definedFunctions()) { + if (f->name() == "afterSignatureCheck") { + solAssert(res == nullptr, ""); + res = f; + } } } - return nullptr; + return res; } bool TVMCompilerContext::storeTimestampInC4() const { diff --git a/compiler/libsolidity/codegen/TVMTypeChecker.cpp b/compiler/libsolidity/codegen/TVMTypeChecker.cpp index 168463f..a3a9a0b 100644 --- a/compiler/libsolidity/codegen/TVMTypeChecker.cpp +++ b/compiler/libsolidity/codegen/TVMTypeChecker.cpp @@ -52,7 +52,7 @@ void TVMTypeChecker::checkOverrideAndOverload() { m_errorReporter.typeError( f->location(), SecondarySourceLocation().append("Declaration of the function with the same function ID: ", funcId2Decl.at(id)->location()), - "Two functions have have the same functionID."); + "Two functions have the same functionID."); } } else { funcId2Decl[id] = f; @@ -187,8 +187,8 @@ bool TVMTypeChecker::visit(const FunctionDefinition &f) { if (f.functionID().has_value() && f.functionID().value() == 0) { m_errorReporter.typeError(f.location(), "functionID can't be equal to zero because this value is reserved for receive function."); } - if (f.functionID().has_value() && !f.isPublic()) { - m_errorReporter.typeError(f.location(), "Only public/external functions can have functionID."); + if (f.functionID().has_value() && (!f.isPublic() && f.name() != "onCodeUpgrade")) { + m_errorReporter.typeError(f.location(), "Only public/external functions and function `onCodeUpgrade` can have functionID."); } if (f.functionID().has_value() && (f.isReceive() || f.isFallback() || f.isOnTickTock() || f.isOnBounce())) { m_errorReporter.typeError(f.location(), "functionID isn't supported for receive, fallback, onBounce and onTickTock functions."); diff --git a/compiler/libsolidity/codegen/TvmAst.cpp b/compiler/libsolidity/codegen/TvmAst.cpp index 7a7e0e4..1780be7 100644 --- a/compiler/libsolidity/codegen/TvmAst.cpp +++ b/compiler/libsolidity/codegen/TvmAst.cpp @@ -545,6 +545,7 @@ Pointer gen(const std::string& cmd) { {"DEC", {1, 1}}, {"DICTEMPTY", {1, 1, true}}, {"ENDC", {1, 1}}, + {"ENDXC", {1, 1}}, {"EQINT", {1, 1, true}}, {"FITS", {1, 1}}, {"GASTOGRAM", {1, 1, true}}, @@ -1086,4 +1087,4 @@ Pointer getZeroOrNullAlignment(bool isZero, bool isSwap, bool isNot) { return std::make_shared(cmd); } -} // end solidity::frontend \ No newline at end of file +} // end solidity::frontend diff --git a/compiler/libsolidity/codegen/TvmAst.hpp b/compiler/libsolidity/codegen/TvmAst.hpp index 71a6bfe..dfeca4b 100644 --- a/compiler/libsolidity/codegen/TvmAst.hpp +++ b/compiler/libsolidity/codegen/TvmAst.hpp @@ -460,7 +460,8 @@ namespace solidity::frontend OnCodeUpgrade, OnTickTock }; - Function(int take, int ret, std::string name, FunctionType type, Pointer block, FunctionDefinition const* _function = {}); + Function(int take, int ret, std::string name, FunctionType type, Pointer block, + FunctionDefinition const* _function = {}); void accept(TvmAstVisitor& _visitor) override; bool operator==(TvmAstNode const&) const override { return false; } // TODO int take() const { return m_take; } diff --git a/compiler/libsolidity/codegen/TvmAstVisitor.cpp b/compiler/libsolidity/codegen/TvmAstVisitor.cpp index c735003..3557dbd 100644 --- a/compiler/libsolidity/codegen/TvmAstVisitor.cpp +++ b/compiler/libsolidity/codegen/TvmAstVisitor.cpp @@ -22,6 +22,7 @@ #include #include #include "TVMCommons.hpp" +#include "TVMABI.hpp" using namespace solidity::frontend; @@ -661,33 +662,39 @@ bool Printer::visit(Contract &_node) { } bool Printer::visit(Function &_node) { + const std::string &funName = _node.name(); switch (_node.type()) { case Function::FunctionType::PrivateFunction: case Function::FunctionType::PrivateFunctionWithObj: - m_out << ".globl\t" << _node.name() << std::endl; - m_out << ".type\t" << _node.name() << ", @function" << std::endl; + m_out << ".globl\t" << funName << std::endl; + m_out << ".type\t" << funName << ", @function" << std::endl; + break; + case Function::FunctionType::OnCodeUpgrade: { + solAssert(_node.functionDefinition(), ""); + std::optional id = _node.functionDefinition()->functionID(); + if (!id.has_value()) { + id = ChainDataEncoder::toHash256(funName) & 0x7FFFFFFFu; + } + m_out << ".internal-alias " << funName << ", " << *id << std::endl + << ".internal " << funName << std::endl; break; + } case Function::FunctionType::Macro: case Function::FunctionType::MacroGetter: - m_out << ".macro " << _node.name() << std::endl; + m_out << ".macro " << funName << std::endl; break; case Function::FunctionType::MainInternal: - solAssert(_node.name() == "main_internal", ""); + solAssert(funName == "main_internal", ""); m_out << ".internal-alias :main_internal, 0" << std::endl << ".internal :main_internal" << std::endl; break; case Function::FunctionType::MainExternal: - solAssert(_node.name() == "main_external", ""); + solAssert(funName == "main_external", ""); m_out << ".internal-alias :main_external, -1" << std::endl << ".internal :main_external" << std::endl; break; - case Function::FunctionType::OnCodeUpgrade: - solAssert(_node.name() == "onCodeUpgrade", ""); - m_out << ".internal-alias :onCodeUpgrade, 2" << std::endl - << ".internal :onCodeUpgrade" << std::endl; - break; case Function::FunctionType::OnTickTock: - solAssert(_node.name() == "onTickTock", ""); + solAssert(funName == "onTickTock", ""); m_out << ".internal-alias :onTickTock, -2" << std::endl << ".internal :onTickTock" << std::endl; break; diff --git a/compiler/scripts/install_deps.sh b/compiler/scripts/install_deps.sh index 0b68620..93a857f 100755 --- a/compiler/scripts/install_deps.sh +++ b/compiler/scripts/install_deps.sh @@ -93,14 +93,14 @@ case $(uname -s) in 10.15) echo "Installing solidity dependencies on macOS 10.15 Catalina." ;; - 11.0 | 11.1 | 11.2 | 11.3 | 11.4) - echo "Installing solidity dependencies on macOS 11.0 / 11.1 / 11.2 / 11.3 / 11.4 Big Sur." + 11.*) + echo "Installing solidity dependencies on macOS 11.x Big Sur." ;; 12.*) echo "Installing solidity dependencies on macOS 12 Monterey." ;; *) - echo "Unsupported macOS version." + echo "Unsupported macOS version: $(sw_vers -productVersion)" echo "We only support Mavericks, Yosemite, El Capitan, Sierra, High Sierra, Mojave, Catalina, Big Sur and Monterey." exit 1 ;; @@ -177,7 +177,7 @@ case $(uname -s) in Debian*) #Debian . /etc/os-release - + # Install "normal packages" sudo apt-get -y update sudo apt-get -y install \ @@ -254,7 +254,7 @@ case $(uname -s) in Ubuntu|LinuxMint) #LinuxMint is a distro on top of Ubuntu. #Ubuntu - + sudo apt-get -y update sudo apt-get -y install \ build-essential \ diff --git a/docs/internal/stateInit_hash.md b/docs/internal/stateInit_hash.md index 4f37d06..f996ce8 100644 --- a/docs/internal/stateInit_hash.md +++ b/docs/internal/stateInit_hash.md @@ -1,9 +1,10 @@ -TVM Solidity Compiler allows user to calculate hash of the stateInit using data and code cells. -According to section 1.1.3 and 1.1.4 of the [TBLKCH][2] representation hash of the stateInit Cell *c* -is calculated with this formula: +# State Init hash -```Math - Hash(c) = SHA256(CellRepr(c)) +Ever Solidity Compiler allows user to calculate hash of the stateInit using data and code cells. +According to section 1.1.3 and 1.1.4 of the [TBLKCH][2] representation hash of the stateInit Cell *c* is calculated with this formula: + +```math +Hash(c) = SHA256(CellRepr(c)) ``` where `CellRepr` is “standard representation” of the Cell and consists of the following data: @@ -16,8 +17,8 @@ where `CellRepr` is “standard representation” of the Cell and consists of t while the last bit of *d2* is the completion tag, equal to one if l is not divisible by eight. Therefore, -``` - d2 = 2 * floor(l/8) + [l mod 8 /= 0] = floor(l/8) + ceil(l/8) +```math +d2 = 2 * floor(l/8) + [l mod 8 /= 0] = floor(l/8) + ceil(l/8) ``` StateInit structure: diff --git a/script/toolchain.sh b/script/toolchain.sh new file mode 100644 index 0000000..c77047f --- /dev/null +++ b/script/toolchain.sh @@ -0,0 +1,101 @@ +#!/usr/bin/env bash + +set -o errexit + +projectDir=$(cd "$(dirname "${0}")/.." && pwd) +# shellcheck source=script/util.sh +source "${projectDir}/script/util.sh" || source ./util.sh + +usage() { + println "POSIX-compliant bash script to manage toolchain for develop project" + println "Usage: ${0}