Skip to content

Commit

Permalink
Merge pull request #141 from tonlabs/0.71.0
Browse files Browse the repository at this point in the history
0.71.0
  • Loading branch information
BorisI authored Jul 27, 2023
2 parents af55112 + 2480ac6 commit 53686a3
Show file tree
Hide file tree
Showing 62 changed files with 1,428 additions and 1,149 deletions.
434 changes: 267 additions & 167 deletions API.md

Large diffs are not rendered by default.

209 changes: 103 additions & 106 deletions Cargo.lock

Large diffs are not rendered by default.

34 changes: 29 additions & 5 deletions Changelog_TON.md → Changelog.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,31 @@
### 0.71.0 (2023-07-20)

Bugfixes:
* Fixed segmentation fault of the compiler that could occur in some cases of using `try-catch` (experimental feature).
* Fixed compilation error in case of using operator `+` for constant strings.
* Fixed segmentation fault of the compiler that could occur in the case of using `constructor` with `functionID()`.
* Fixed an exception which could occur on contract upgrade in case of state variables number being reduced, yet still exceeding 16.

Breaking changes:
* Now [msg.data](API.md#msgdata) returns the whole message instead of the message body. Use [msg.body](API.md#msgbody) to get the message body (payload).
* `<address>.unpack` returns `(int32, uint256)` instead of `(int8, uint256)`.

Compiler features:
* Supported [<optional(T)>.getOr()](API.md#optionaltgetor) and [<optional(T)>.getOrDefault()](API.md#optionaltgetordefault).
* Supported creating empty cell via `TvmCell()`.
* Supported `<TvmBuilder>.store()` for `varInt`/`varUint`.
* Supported [msg.forwardFee](API.md#msgforwardfee).
* Supported [msg.importFee](API.md#msgimportfee).
* Supported [gasleft](API.md#gasleft).
* Supported [\<mapping\>.getDel()](API.md#mappinggetdel).

Gas optimizations:
* Assorted stack optimizations.

### 0.70.0 (2023-06-14)

Compiler features:
* Supported [inline assembly](./API.md#assembly).
* Supported [inline assembly](API.md#assembly).
* Supported overriding `onCodeUpgrade` function.
* Supported [User-defined Value Types](https://docs.soliditylang.org/en/latest/types.html#user-defined-value-types). You can also use this type in public functions.
* [Supported `type(T).min` and `type(T).max`](API.md#type-information).
Expand Down Expand Up @@ -643,14 +667,14 @@ Bugfixes:

### 0.30 (2020-08-21)

APIs for common TON-specific functionality:
APIs for common TVM-specific functionality:
* Supported tick and tock transactions. See onTickTock function.
Bug fixes.


### 0.29 (2020-08-19)

APIs for common TON-specific functionality:
APIs for common TVM-specific functionality:
* Supported optional type
* Added methods for optional type: set, hasValue, get

Expand All @@ -659,7 +683,7 @@ Changed APIs to handle mappings: fetch, min, max, prev, next and ect.

### 0.20 (2020-03-30)

APIs for common TON-specific functionality:
APIs for common TVM-specific functionality:

* Migrated frontend to 0.6.3
* Native types support
Expand All @@ -675,7 +699,7 @@ APIs for common TON-specific functionality:

### 0.18 (2020-01-30)

APIs for common TON-specific functionality:
APIs for common TVM-specific functionality:
* Address constructors and accessors
* Extended address format that includes workchain ID
* Members for workchain ID and the actual address part
Expand Down
42 changes: 20 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<meta name="title" content="TON-Solidity-Compiler">
<meta name="description" content="Solidity compiler for TON Virtual Machine">
<meta name="title" content="TVM-Solidity-Compiler">
<meta name="description" content="Solidity compiler for TVM">
<meta name='keywords' content='compiler, smart-contracts, blockchain, solidity, tvm, everscale, everos, venom-blockchain, venom-developer-program'>

# Sol2TVM Compiler
# the TVM Solidity compiler

[![GitHub](https://img.shields.io/github/license/tonlabs/TON-Solidity-Compiler?style=for-the-badge)](./LICENSE)
[![Everscale](https://custom-icon-badges.demolab.com/badge/-everscale-13173e?style=for-the-badge&logoColor=yellow&logo=everscale)](https://everscale.network/)


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.
Port of the Solidity smart-contract [compiler](https://github.com/ethereum/solidity) generating TVM bytecode for TVM compatible blockchains (Everscale, Venom, Gosh, TON). Please refer to upstream README.md for information on the language itself.

## TON Solidity API reference
## TVM Solidity API reference

[API documentation is here](https://github.com/tonlabs/TON-Solidity-Compiler/blob/master/API.md)

Expand All @@ -24,7 +24,13 @@ Port of the Solidity smart-contract [compiler](https://github.com/ethereum/solid

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
### Sold driver

Documentation is available at [README.md](https://github.com/tonlabs/TON-Solidity-Compiler/blob/master/sold/README.md) (RECOMMENDED).

### Building compiler

#### Ubuntu Linux

```shell
git clone https://github.com/tonlabs/TON-Solidity-Compiler
Expand All @@ -36,13 +42,13 @@ 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`.
Make other 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
#### Windows 10

Install Visual Studio Build Tools 2019, Git bash, cmake.
Run Developer PowerShell for VS 2019
Expand All @@ -57,23 +63,15 @@ cmake -DBoost_DIR="..\compiler\deps\boost\lib\cmake\Boost-1.77.0" -DCMAKE_MSVC_R
cmake --build . --config Release -- /m
```

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).
To facilitate work with other toolchain utilities add path to `stdlib_sol.tvm` into environment variable `TVM_LINKER_LIB_PATH`.

## 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)
* [Code samples](https://github.com/tonlabs/samples/tree/master/solidity) in TVM Solidity
* [TVM linker repository](https://github.com/tonlabs/TVM-linker)
* [tonos-cli](https://github.com/tonlabs/tonos-cli) command line interface for TVM compatible blockchains
* Example of usage `tonos-cli` for working (deploying, calling and etc.) with TVM compatible blockchains can be found there: [Write smart contract in Solidity](https://docs.ton.dev/86757ecb2/p/950f8a-write-smart-contract-in-solidity)
* [Changelog](https://github.com/tonlabs/TON-Solidity-Compiler/blob/master/Changelog_TON.md)

## License
[GNU GENERAL PUBLIC LICENSE Version 3](./LICENSE)
2 changes: 1 addition & 1 deletion compiler/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ include(EthPolicy)
eth_policy()

# project name and version should be set after cmake_policy CMP0048
set(PROJECT_VERSION "0.70.0")
set(PROJECT_VERSION "0.71.0")
# OSX target needed in order to support std::visit
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.14")
project(solidity VERSION ${PROJECT_VERSION} LANGUAGES C CXX)
Expand Down
3 changes: 2 additions & 1 deletion compiler/libsolidity/analysis/GlobalContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ int magicVariableToID(std::string const& _name)
else if (_name == "block") return -4;
else if (_name == "blockhash") return -5;
else if (_name == "ecrecover") return -6;
else if (_name == "format") return -105;
else if (_name == "gasleft") return -7;
else if (_name == "format") return -105;
else if (_name == "keccak256") return -8;
else if (_name == "logtvm") return -102;
else if (_name == "math") return -103;
Expand Down Expand Up @@ -86,6 +86,7 @@ inline vector<shared_ptr<MagicVariableDeclaration const>> constructMagicVariable
magicVarDecl("addmod", TypeProvider::function(strings{"uint256", "uint256", "uint256"}, strings{"uint256"}, FunctionType::Kind::AddMod, StateMutability::Pure)),
magicVarDecl("assert", TypeProvider::function(strings{"bool"}, strings{}, FunctionType::Kind::Assert, StateMutability::Pure)),
magicVarDecl("block", TypeProvider::magic(MagicType::Kind::Block)),
magicVarDecl("gasleft", TypeProvider::function(strings(), {"uint64"}, FunctionType::Kind::GasLeft, StateMutability::Pure)),
magicVarDecl("msg", TypeProvider::magic(MagicType::Kind::Message)),
magicVarDecl("mulmod", TypeProvider::function(strings{"uint256", "uint256", "uint256"}, strings{"uint256"}, FunctionType::Kind::MulMod, StateMutability::Pure)),
magicVarDecl("now", TypeProvider::uint(32)),
Expand Down
43 changes: 25 additions & 18 deletions compiler/libsolidity/analysis/TypeChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1157,24 +1157,26 @@ bool TypeChecker::visit(IfStatement const& _ifStatement)
void TypeChecker::endVisit(TryStatement const& _tryStatement)
{
TryCatchClause const& clause = _tryStatement.clause();
std::vector<ASTPointer<VariableDeclaration>> const& errArgs = clause.parameters()->parameters();
if (clause.parameters() != nullptr) {
std::vector<ASTPointer<VariableDeclaration>> const& errArgs = clause.parameters()->parameters();

auto printError = [&](SourceLocation const& loc){
m_errorReporter.typeError(
228_error,
loc,
"Expected `catch (variant value, uint number) { ... }`.");
};
if (errArgs.size() != 2) {
printError(clause.location());
return;
}
if (*errArgs.at(0)->type() != *TypeProvider::variant()) {
printError(errArgs.at(0)->location());
}
if (*errArgs.at(1)->type() != *TypeProvider::uint(16)) {
printError(errArgs.at(1)->location());
}
auto printError = [&](SourceLocation const& loc){
m_errorReporter.typeError(
228_error,
loc,
"Expected `catch (variant value, uint16 number) { ... }`.");
};
if (errArgs.size() != 2) {
printError(clause.location());
return;
}
if (*errArgs.at(0)->type() != *TypeProvider::variant()) {
printError(errArgs.at(0)->location());
}
if (*errArgs.at(1)->type() != *TypeProvider::uint(16)) {
printError(errArgs.at(1)->location());
}
}
}

bool TypeChecker::visit(WhileStatement const& _whileStatement)
Expand Down Expand Up @@ -1901,7 +1903,11 @@ Type const* TypeChecker::typeCheckTypeConversionAndRetrieveReturnType(
bool const isPositionalCall = _functionCall.names().empty();

Type const* resultType = dynamic_cast<TypeType const&>(*expressionType).actualType();
if (arguments.size() != 1)
if (arguments.empty() && resultType->category() == Type::Category::TvmCell)
{
// all right
}
else if (arguments.size() != 1)
m_errorReporter.typeError(
2558_error,
_functionCall.location(),
Expand Down Expand Up @@ -2154,6 +2160,7 @@ void TypeChecker::typeCheckTvmEncodeArg(Type const* type, Expression const& node
case Type::Category::TvmBuilder:
case Type::Category::TvmCell:
case Type::Category::TvmSlice:
case Type::Category::VarInteger:
break;
case Type::Category::Optional:
{
Expand Down
5 changes: 5 additions & 0 deletions compiler/libsolidity/analysis/ViewPureChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ void ViewPureChecker::endVisit(MemberAccess const& _memberAccess)
member == "add" ||
member == "getSet" ||
member == "getAdd" ||
member == "getDel" ||
member == "getReplace") {
if (isStateVar)
mutability = StateMutability::NonPayable;
Expand Down Expand Up @@ -365,6 +366,9 @@ void ViewPureChecker::endVisit(MemberAccess const& _memberAccess)
{MagicType::Kind::Math, "muldivmod"},
{MagicType::Kind::Math, "muldivr"},
{MagicType::Kind::Math, "sign"},
{MagicType::Kind::Message, "body"},
{MagicType::Kind::Message, "forwardFee"},
{MagicType::Kind::Message, "importFee"},
{MagicType::Kind::Message, "createdAt"},
{MagicType::Kind::Message, "currencies"},
{MagicType::Kind::Message, "data"},
Expand Down Expand Up @@ -403,6 +407,7 @@ void ViewPureChecker::endVisit(MemberAccess const& _memberAccess)
{MagicType::Kind::TVM, "functionId"},
{MagicType::Kind::TVM, "hash"},
{MagicType::Kind::TVM, "hexdump"},
{MagicType::Kind::TVM, "initCodeHash"},
{MagicType::Kind::TVM, "insertPubkey"},
{MagicType::Kind::TVM, "log"},
{MagicType::Kind::TVM, "rawConfigParam"},
Expand Down
2 changes: 1 addition & 1 deletion compiler/libsolidity/ast/AST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ FunctionDefinition const* ContractDefinition::constructor() const

bool ContractDefinition::canBeDeployed() const
{
// In TON, libraries are also not deployable.
// In TVM, libraries are also not deployable.
return !abstract() && !isInterface() && !isLibrary();
}

Expand Down
Loading

0 comments on commit 53686a3

Please sign in to comment.