2019-09-07 10:03:22 +00:00
|
|
|
/*
|
|
|
|
This file is part of TON Blockchain Library.
|
|
|
|
|
|
|
|
TON Blockchain Library is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
TON Blockchain Library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
along with TON Blockchain Library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2020-02-06 17:56:46 +00:00
|
|
|
Copyright 2017-2020 Telegram Systems LLP
|
2019-09-07 10:03:22 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "common/refcnt.hpp"
|
|
|
|
#include "common/refint.h"
|
|
|
|
#include "vm/cells.h"
|
|
|
|
#include "vm/cellslice.h"
|
|
|
|
#include "vm/dict.h"
|
|
|
|
#include "vm/boc.h"
|
|
|
|
#include <ostream>
|
|
|
|
#include "tl/tlblib.hpp"
|
|
|
|
#include "td/utils/bits.h"
|
|
|
|
#include "ton/ton-types.h"
|
|
|
|
#include "block/block.h"
|
|
|
|
#include "block/mc-config.h"
|
|
|
|
|
|
|
|
namespace block {
|
|
|
|
using td::Ref;
|
|
|
|
using LtCellRef = std::pair<ton::LogicalTime, Ref<vm::Cell>>;
|
|
|
|
|
|
|
|
struct Account;
|
2023-02-02 07:03:45 +00:00
|
|
|
|
|
|
|
namespace transaction {
|
2019-09-07 10:03:22 +00:00
|
|
|
struct Transaction;
|
2023-02-02 07:03:45 +00:00
|
|
|
} // namespace transaction
|
2019-09-07 10:03:22 +00:00
|
|
|
|
|
|
|
struct CollatorError {
|
|
|
|
std::string msg;
|
|
|
|
CollatorError(std::string _msg) : msg(_msg) {
|
|
|
|
}
|
|
|
|
CollatorError(const char* _msg) : msg(_msg) {
|
|
|
|
}
|
|
|
|
std::string get_msg() const {
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline bool operator<(const LtCellRef& a, const LtCellRef& b) {
|
|
|
|
return a.first < b.first;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct LtCellCompare {
|
|
|
|
bool operator()(const LtCellRef& a, const LtCellRef& b) {
|
|
|
|
return a.first < b.first;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct NewOutMsg {
|
|
|
|
ton::LogicalTime lt;
|
|
|
|
Ref<vm::Cell> msg;
|
|
|
|
Ref<vm::Cell> trans;
|
|
|
|
NewOutMsg(ton::LogicalTime _lt, Ref<vm::Cell> _msg, Ref<vm::Cell> _trans)
|
|
|
|
: lt(_lt), msg(std::move(_msg)), trans(std::move(_trans)) {
|
|
|
|
}
|
2020-04-10 19:06:01 +00:00
|
|
|
bool operator<(const NewOutMsg& other) const& {
|
2019-09-07 10:03:22 +00:00
|
|
|
return lt < other.lt || (lt == other.lt && msg->get_hash() < other.msg->get_hash());
|
|
|
|
}
|
2020-04-10 19:06:01 +00:00
|
|
|
bool operator>(const NewOutMsg& other) const& {
|
2019-09-07 10:03:22 +00:00
|
|
|
return lt > other.lt || (lt == other.lt && other.msg->get_hash() < msg->get_hash());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct StoragePhaseConfig {
|
|
|
|
const std::vector<block::StoragePrices>* pricing{nullptr};
|
|
|
|
td::RefInt256 freeze_due_limit;
|
|
|
|
td::RefInt256 delete_due_limit;
|
TVM Upgrade (#686)
* New TVM instructions
* Remove PREVBLOCKS
* Separate target ton_crypto into TVM-related and -unrelared code
* Add fine for failed "send message"; rework SENDMSG
* Fix include
* Fix bugs, improve action fines
* Disable fines for special accounts
* Handle msg_balance_remaining.grams == null in transaction.cpp
* Bugfixes in SENDMSG
* Fix fee calculation in SENDMSG
* Fix CellStorageStat and transaction.cpp after merge
* SETBOUNCEONACTIONPHASEFAIL instruction
* ADDDIVMOD instructions
* RUNVM, RUNVMX instructions
* Changes in RUNVM
* Tests for adddiv and runvm
* HASHEXT instruction
* Improve opcode-timing
More iterations
Don't measure preliminary run
Remove logs and other excessive operations
Add "error" to output
* Increase RUNVM gas price
* Optimize HASHEXT, adjust gas price
* Add "bounce of action fail" flag to actions
* Stack operations with unlimited arguments
* Ristretto255 instructions
* Adjust gas consumption
* Optional fixed number of return values in RUNVM, fix exception handling
* Adjust gas consumption
* Simplify gas consumption logic
* Support of secp256k1 and sodium libraries in builds (#11)
* add support of secp256k1 library to the builds (linux, win)
* add support of secp256k1 library to the builds (linux, win)
* install secp256k1 via brew
* install libsodium via brew;
change sodium to upper case in FindSodium.cmake
* install libsodium via brew;
change sodium to upper case in FindSodium.cmake
* simplify FindSodium.cmake
* bug fixing
* bug fixing
* bug fixing
* add macro SODIUM_STATIC
* adjust build command for windows
* put back original FindSodium.cmake
* put back original FindSodium.cmake
* fix sodium unzipped path for windows;
add ninja
* fix sodium unzipped path for windows;
add ninja
* fix sodium unzipped path for windows;
add ninja
* Win32 github build for secp256k1
* x64 architecture github build for secp256k1
* fix sodium linking on linux
* enable docker buildx arm64 builds from forked repos
* enable docker buildx arm64 builds from forked repos
* enable docker buildx arm64 builds from forked repos
* adjust mac builds for secp2561k and sodium
* fix tonlib jni generation
* minor fix
* sync fixes across platforms
* add libsodium build script for android and precompiled static libraries
* build tonlib for android (fails)
* FindSodium uppercase
* remove system libsodium for android, use precompiled instead;
specify SECP256K1_INCLUDE_DIR fir mac 12.6
* uppercase sodium
* simplify FindSodium
* fix windows build sodium path;
use ninja for windows
* simplify sodium 2
* adjust windows sodium paths;
add paths to android jni
* add ninja build windows
* add ninja build windows
* add ninja build windows 2
* remove win ninja
* fix 1
* fix 2
* fix win 3
* fix linux compile 3
* fix jni 1
* fix jni 2 and mac
* fix jni 3
* fix jni 4
* fix jni 5
* fix mac 6
* fix mac 7 and jni paths
* fix jni 8
* rework sodium for android
* rework sodium for android
* rework sodium for android 2
* fixed sodium for android 2
* fixed sodium for android 3
* static secp256k1 for android
* add precompiled arm secp256k1
* add precompiled arm secp256k1
* build native-lib with secp256k1 x86-64 (non arm)
* update precompiled with NDK libsecp256k1.a
* update precompiled with NDK libsecp256k1.a
* update precompiled with NDK libsecp256k1.a
* refactor llvm-strip location
* refactor llvm-strip location
* add native-lib.so for armv7a, armv8a
* add native-lib.so for armv7a, armv8a
* test armv7a, armv8a
* armv7a - fails linking on sodium, test -> armv8a
* works x86-64, armv7a - fails linking on sodium, armv8a - fails linking secp256k1 (incompatible with aarch64linux)
* update libpsec256k1, sodium static libs
* test x86 android native-lib
* test armv7 android native-lib
* test armv8 android native-lib
* x86_64 and arm64 android native-lib works
* x86_64 and arm64 android native-lib works
* x86_64 and arm64 android native-lib works
* test armv7 android native-lib
* test all android native-libs
* test all android native-libs
* test all android native-libs
* test all android native-libs - without SodiumAndroid
* test all android native-libs - with FindSodiumAndroid.cmake
* win, with Sodium via SODIUM_DIR
* win, with Sodium via SODIUM_DIR env
* win, with Sodium via SODIUM_DIR env
* win, with Sodium via SODIUM_DIR env and SODIUM_USE_STATIC_LIBS
* win, with Sodium via SODIUM_DIR, SODIUM_USE_STATIC_LIBS and SODIUM_INCLUDE_DIR
* android, with FindSodium
* android, with FindSodium with SODIUM_USE_STATIC_LIBS
* remove if not apple
* target_link_libraries(ton_crypto_core PUBLIC secp256k1)
* android SECP256K1_INCLUDE_DIRS
* android SECP256K1_INCLUDE_DIR
* add libsecp256k1.a/so pre-compiled with ubuntu 22 x86-64
* add libsecp256k1.a/so pre-compiled with ubuntu 22 x86-64
* sodium dirs
* sodium dirs
* sodium dirs
* remove NOT APPLE and SodiumAndroid
* add NOT APPLE and remove SodiumAndroid
* add NOT APPLE and remove SodiumAndroid
* remove build scripts for 18.04, reduce CMakeLists.txt
* remove build scripts for 18.04, reduce CMakeLists.txt
* Fix cas consumption during library load
* Fix fetch_config_params after merge
* Add all ADDDIVMOD ops to Asm.fif
* Save unpaid storage fee to due_payment
* Add "set prev blocks info" to emulator
* Adjusted builds (#13)
* Update flake.nix
Add libsodium
* add libsecp256k1-dev and libsodium-dev into wasm build
* make back emulator a shared library;
put emulator to artifacts;
compile wasm artifacts with sodium and secp256k1.
* add secp256k1 to nix
* compile emulator statically with nix
* compile emulator statically with nix
* compile emulator lib statically with nix
* compile emulator lib statically with nix
* add libemulator to artifacts
* add shared libemulator library to artifacts
* minor release fix
* update set-output commands;
add recent_changelog.md
* releases fixes
* releases fixes, multiline
* releases fixes, multiline
* releases fixes, multiline
* put back multiline changelog
* put back multiline changelog
* ConfigParam 19 (global-id) and GLOBALID instruction
* Fix gas consumption in HASHEXT
* Add blst library
* Add bls instructions
* Allow passing long code to opcode-timing
* Add bls testcase
* More BLS instructions
* Fix tests, add bls tests
* Add more bls tests
* Improve some bls operations
* Adjust some BLS gas prices
* Adjust BLS gas prices
* Enable __BLST_PORTABLE__ flag only if PORTABLE flag is set
* Add tests for BLS_PAIRING
* GASCONSUMED instruction
* Fix compilation against docker with blst library; (#14)
* fix compilation against docker with blst library;
add precompiled libblst.a to android builds
* minor fix
* Adjust BLKSWX gas
* Fix comparison with NAN
* Allow arbitrary integers for scalars in ristretto multiplication, fix test
* Adjust nix builds according to PR 694 (#15)
* integrate and test PR-694
* integrate and test PR-694, test 2
* Add P256_CHKSIGN (secp256r1)
---------
Co-authored-by: SpyCheese <mikle98@yandex.ru>
Co-authored-by: neodiX42 <namlem@gmail.com>
2023-05-24 18:14:13 +00:00
|
|
|
bool enable_due_payment{false};
|
2019-09-07 10:03:22 +00:00
|
|
|
StoragePhaseConfig() = default;
|
|
|
|
StoragePhaseConfig(const std::vector<block::StoragePrices>* _pricing, td::RefInt256 freeze_limit = {},
|
|
|
|
td::RefInt256 delete_limit = {})
|
|
|
|
: pricing(_pricing), freeze_due_limit(freeze_limit), delete_due_limit(delete_limit) {
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct StoragePhase {
|
|
|
|
td::RefInt256 fees_collected;
|
|
|
|
td::RefInt256 fees_due;
|
|
|
|
ton::UnixTime last_paid_updated;
|
|
|
|
bool frozen{false};
|
|
|
|
bool deleted{false};
|
|
|
|
bool is_special{false};
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ComputePhaseConfig {
|
|
|
|
td::uint64 gas_price;
|
|
|
|
td::uint64 gas_limit;
|
2019-09-16 08:06:04 +00:00
|
|
|
td::uint64 special_gas_limit;
|
2019-09-07 10:03:22 +00:00
|
|
|
td::uint64 gas_credit;
|
2019-10-03 13:04:52 +00:00
|
|
|
td::uint64 flat_gas_limit = 0;
|
|
|
|
td::uint64 flat_gas_price = 0;
|
2024-01-12 09:34:28 +00:00
|
|
|
bool special_gas_full = false;
|
2024-01-15 20:43:11 +00:00
|
|
|
block::GasLimitsPrices mc_gas_prices;
|
2019-09-07 10:03:22 +00:00
|
|
|
static constexpr td::uint64 gas_infty = (1ULL << 63) - 1;
|
|
|
|
td::RefInt256 gas_price256;
|
|
|
|
td::RefInt256 max_gas_threshold;
|
|
|
|
std::unique_ptr<vm::Dictionary> libraries;
|
|
|
|
Ref<vm::Cell> global_config;
|
|
|
|
td::BitArray<256> block_rand_seed;
|
2023-02-02 07:03:45 +00:00
|
|
|
bool ignore_chksig{false};
|
2022-05-24 18:21:58 +00:00
|
|
|
bool with_vm_log{false};
|
2022-10-10 14:13:21 +00:00
|
|
|
td::uint16 max_vm_data_depth = 512;
|
TVM Upgrade (#686)
* New TVM instructions
* Remove PREVBLOCKS
* Separate target ton_crypto into TVM-related and -unrelared code
* Add fine for failed "send message"; rework SENDMSG
* Fix include
* Fix bugs, improve action fines
* Disable fines for special accounts
* Handle msg_balance_remaining.grams == null in transaction.cpp
* Bugfixes in SENDMSG
* Fix fee calculation in SENDMSG
* Fix CellStorageStat and transaction.cpp after merge
* SETBOUNCEONACTIONPHASEFAIL instruction
* ADDDIVMOD instructions
* RUNVM, RUNVMX instructions
* Changes in RUNVM
* Tests for adddiv and runvm
* HASHEXT instruction
* Improve opcode-timing
More iterations
Don't measure preliminary run
Remove logs and other excessive operations
Add "error" to output
* Increase RUNVM gas price
* Optimize HASHEXT, adjust gas price
* Add "bounce of action fail" flag to actions
* Stack operations with unlimited arguments
* Ristretto255 instructions
* Adjust gas consumption
* Optional fixed number of return values in RUNVM, fix exception handling
* Adjust gas consumption
* Simplify gas consumption logic
* Support of secp256k1 and sodium libraries in builds (#11)
* add support of secp256k1 library to the builds (linux, win)
* add support of secp256k1 library to the builds (linux, win)
* install secp256k1 via brew
* install libsodium via brew;
change sodium to upper case in FindSodium.cmake
* install libsodium via brew;
change sodium to upper case in FindSodium.cmake
* simplify FindSodium.cmake
* bug fixing
* bug fixing
* bug fixing
* add macro SODIUM_STATIC
* adjust build command for windows
* put back original FindSodium.cmake
* put back original FindSodium.cmake
* fix sodium unzipped path for windows;
add ninja
* fix sodium unzipped path for windows;
add ninja
* fix sodium unzipped path for windows;
add ninja
* Win32 github build for secp256k1
* x64 architecture github build for secp256k1
* fix sodium linking on linux
* enable docker buildx arm64 builds from forked repos
* enable docker buildx arm64 builds from forked repos
* enable docker buildx arm64 builds from forked repos
* adjust mac builds for secp2561k and sodium
* fix tonlib jni generation
* minor fix
* sync fixes across platforms
* add libsodium build script for android and precompiled static libraries
* build tonlib for android (fails)
* FindSodium uppercase
* remove system libsodium for android, use precompiled instead;
specify SECP256K1_INCLUDE_DIR fir mac 12.6
* uppercase sodium
* simplify FindSodium
* fix windows build sodium path;
use ninja for windows
* simplify sodium 2
* adjust windows sodium paths;
add paths to android jni
* add ninja build windows
* add ninja build windows
* add ninja build windows 2
* remove win ninja
* fix 1
* fix 2
* fix win 3
* fix linux compile 3
* fix jni 1
* fix jni 2 and mac
* fix jni 3
* fix jni 4
* fix jni 5
* fix mac 6
* fix mac 7 and jni paths
* fix jni 8
* rework sodium for android
* rework sodium for android
* rework sodium for android 2
* fixed sodium for android 2
* fixed sodium for android 3
* static secp256k1 for android
* add precompiled arm secp256k1
* add precompiled arm secp256k1
* build native-lib with secp256k1 x86-64 (non arm)
* update precompiled with NDK libsecp256k1.a
* update precompiled with NDK libsecp256k1.a
* update precompiled with NDK libsecp256k1.a
* refactor llvm-strip location
* refactor llvm-strip location
* add native-lib.so for armv7a, armv8a
* add native-lib.so for armv7a, armv8a
* test armv7a, armv8a
* armv7a - fails linking on sodium, test -> armv8a
* works x86-64, armv7a - fails linking on sodium, armv8a - fails linking secp256k1 (incompatible with aarch64linux)
* update libpsec256k1, sodium static libs
* test x86 android native-lib
* test armv7 android native-lib
* test armv8 android native-lib
* x86_64 and arm64 android native-lib works
* x86_64 and arm64 android native-lib works
* x86_64 and arm64 android native-lib works
* test armv7 android native-lib
* test all android native-libs
* test all android native-libs
* test all android native-libs
* test all android native-libs - without SodiumAndroid
* test all android native-libs - with FindSodiumAndroid.cmake
* win, with Sodium via SODIUM_DIR
* win, with Sodium via SODIUM_DIR env
* win, with Sodium via SODIUM_DIR env
* win, with Sodium via SODIUM_DIR env and SODIUM_USE_STATIC_LIBS
* win, with Sodium via SODIUM_DIR, SODIUM_USE_STATIC_LIBS and SODIUM_INCLUDE_DIR
* android, with FindSodium
* android, with FindSodium with SODIUM_USE_STATIC_LIBS
* remove if not apple
* target_link_libraries(ton_crypto_core PUBLIC secp256k1)
* android SECP256K1_INCLUDE_DIRS
* android SECP256K1_INCLUDE_DIR
* add libsecp256k1.a/so pre-compiled with ubuntu 22 x86-64
* add libsecp256k1.a/so pre-compiled with ubuntu 22 x86-64
* sodium dirs
* sodium dirs
* sodium dirs
* remove NOT APPLE and SodiumAndroid
* add NOT APPLE and remove SodiumAndroid
* add NOT APPLE and remove SodiumAndroid
* remove build scripts for 18.04, reduce CMakeLists.txt
* remove build scripts for 18.04, reduce CMakeLists.txt
* Fix cas consumption during library load
* Fix fetch_config_params after merge
* Add all ADDDIVMOD ops to Asm.fif
* Save unpaid storage fee to due_payment
* Add "set prev blocks info" to emulator
* Adjusted builds (#13)
* Update flake.nix
Add libsodium
* add libsecp256k1-dev and libsodium-dev into wasm build
* make back emulator a shared library;
put emulator to artifacts;
compile wasm artifacts with sodium and secp256k1.
* add secp256k1 to nix
* compile emulator statically with nix
* compile emulator statically with nix
* compile emulator lib statically with nix
* compile emulator lib statically with nix
* add libemulator to artifacts
* add shared libemulator library to artifacts
* minor release fix
* update set-output commands;
add recent_changelog.md
* releases fixes
* releases fixes, multiline
* releases fixes, multiline
* releases fixes, multiline
* put back multiline changelog
* put back multiline changelog
* ConfigParam 19 (global-id) and GLOBALID instruction
* Fix gas consumption in HASHEXT
* Add blst library
* Add bls instructions
* Allow passing long code to opcode-timing
* Add bls testcase
* More BLS instructions
* Fix tests, add bls tests
* Add more bls tests
* Improve some bls operations
* Adjust some BLS gas prices
* Adjust BLS gas prices
* Enable __BLST_PORTABLE__ flag only if PORTABLE flag is set
* Add tests for BLS_PAIRING
* GASCONSUMED instruction
* Fix compilation against docker with blst library; (#14)
* fix compilation against docker with blst library;
add precompiled libblst.a to android builds
* minor fix
* Adjust BLKSWX gas
* Fix comparison with NAN
* Allow arbitrary integers for scalars in ristretto multiplication, fix test
* Adjust nix builds according to PR 694 (#15)
* integrate and test PR-694
* integrate and test PR-694, test 2
* Add P256_CHKSIGN (secp256r1)
---------
Co-authored-by: SpyCheese <mikle98@yandex.ru>
Co-authored-by: neodiX42 <namlem@gmail.com>
2023-05-24 18:14:13 +00:00
|
|
|
int global_version = 0;
|
|
|
|
Ref<vm::Tuple> prev_blocks_info;
|
2023-01-09 17:37:58 +00:00
|
|
|
std::unique_ptr<vm::Dictionary> suspended_addresses;
|
2023-11-23 15:17:44 +00:00
|
|
|
SizeLimitsConfig size_limits;
|
2023-02-02 07:03:45 +00:00
|
|
|
int vm_log_verbosity = 0;
|
2024-01-22 09:34:49 +00:00
|
|
|
bool stop_on_accept_message = false;
|
TVM Upgrade (#686)
* New TVM instructions
* Remove PREVBLOCKS
* Separate target ton_crypto into TVM-related and -unrelared code
* Add fine for failed "send message"; rework SENDMSG
* Fix include
* Fix bugs, improve action fines
* Disable fines for special accounts
* Handle msg_balance_remaining.grams == null in transaction.cpp
* Bugfixes in SENDMSG
* Fix fee calculation in SENDMSG
* Fix CellStorageStat and transaction.cpp after merge
* SETBOUNCEONACTIONPHASEFAIL instruction
* ADDDIVMOD instructions
* RUNVM, RUNVMX instructions
* Changes in RUNVM
* Tests for adddiv and runvm
* HASHEXT instruction
* Improve opcode-timing
More iterations
Don't measure preliminary run
Remove logs and other excessive operations
Add "error" to output
* Increase RUNVM gas price
* Optimize HASHEXT, adjust gas price
* Add "bounce of action fail" flag to actions
* Stack operations with unlimited arguments
* Ristretto255 instructions
* Adjust gas consumption
* Optional fixed number of return values in RUNVM, fix exception handling
* Adjust gas consumption
* Simplify gas consumption logic
* Support of secp256k1 and sodium libraries in builds (#11)
* add support of secp256k1 library to the builds (linux, win)
* add support of secp256k1 library to the builds (linux, win)
* install secp256k1 via brew
* install libsodium via brew;
change sodium to upper case in FindSodium.cmake
* install libsodium via brew;
change sodium to upper case in FindSodium.cmake
* simplify FindSodium.cmake
* bug fixing
* bug fixing
* bug fixing
* add macro SODIUM_STATIC
* adjust build command for windows
* put back original FindSodium.cmake
* put back original FindSodium.cmake
* fix sodium unzipped path for windows;
add ninja
* fix sodium unzipped path for windows;
add ninja
* fix sodium unzipped path for windows;
add ninja
* Win32 github build for secp256k1
* x64 architecture github build for secp256k1
* fix sodium linking on linux
* enable docker buildx arm64 builds from forked repos
* enable docker buildx arm64 builds from forked repos
* enable docker buildx arm64 builds from forked repos
* adjust mac builds for secp2561k and sodium
* fix tonlib jni generation
* minor fix
* sync fixes across platforms
* add libsodium build script for android and precompiled static libraries
* build tonlib for android (fails)
* FindSodium uppercase
* remove system libsodium for android, use precompiled instead;
specify SECP256K1_INCLUDE_DIR fir mac 12.6
* uppercase sodium
* simplify FindSodium
* fix windows build sodium path;
use ninja for windows
* simplify sodium 2
* adjust windows sodium paths;
add paths to android jni
* add ninja build windows
* add ninja build windows
* add ninja build windows 2
* remove win ninja
* fix 1
* fix 2
* fix win 3
* fix linux compile 3
* fix jni 1
* fix jni 2 and mac
* fix jni 3
* fix jni 4
* fix jni 5
* fix mac 6
* fix mac 7 and jni paths
* fix jni 8
* rework sodium for android
* rework sodium for android
* rework sodium for android 2
* fixed sodium for android 2
* fixed sodium for android 3
* static secp256k1 for android
* add precompiled arm secp256k1
* add precompiled arm secp256k1
* build native-lib with secp256k1 x86-64 (non arm)
* update precompiled with NDK libsecp256k1.a
* update precompiled with NDK libsecp256k1.a
* update precompiled with NDK libsecp256k1.a
* refactor llvm-strip location
* refactor llvm-strip location
* add native-lib.so for armv7a, armv8a
* add native-lib.so for armv7a, armv8a
* test armv7a, armv8a
* armv7a - fails linking on sodium, test -> armv8a
* works x86-64, armv7a - fails linking on sodium, armv8a - fails linking secp256k1 (incompatible with aarch64linux)
* update libpsec256k1, sodium static libs
* test x86 android native-lib
* test armv7 android native-lib
* test armv8 android native-lib
* x86_64 and arm64 android native-lib works
* x86_64 and arm64 android native-lib works
* x86_64 and arm64 android native-lib works
* test armv7 android native-lib
* test all android native-libs
* test all android native-libs
* test all android native-libs
* test all android native-libs - without SodiumAndroid
* test all android native-libs - with FindSodiumAndroid.cmake
* win, with Sodium via SODIUM_DIR
* win, with Sodium via SODIUM_DIR env
* win, with Sodium via SODIUM_DIR env
* win, with Sodium via SODIUM_DIR env and SODIUM_USE_STATIC_LIBS
* win, with Sodium via SODIUM_DIR, SODIUM_USE_STATIC_LIBS and SODIUM_INCLUDE_DIR
* android, with FindSodium
* android, with FindSodium with SODIUM_USE_STATIC_LIBS
* remove if not apple
* target_link_libraries(ton_crypto_core PUBLIC secp256k1)
* android SECP256K1_INCLUDE_DIRS
* android SECP256K1_INCLUDE_DIR
* add libsecp256k1.a/so pre-compiled with ubuntu 22 x86-64
* add libsecp256k1.a/so pre-compiled with ubuntu 22 x86-64
* sodium dirs
* sodium dirs
* sodium dirs
* remove NOT APPLE and SodiumAndroid
* add NOT APPLE and remove SodiumAndroid
* add NOT APPLE and remove SodiumAndroid
* remove build scripts for 18.04, reduce CMakeLists.txt
* remove build scripts for 18.04, reduce CMakeLists.txt
* Fix cas consumption during library load
* Fix fetch_config_params after merge
* Add all ADDDIVMOD ops to Asm.fif
* Save unpaid storage fee to due_payment
* Add "set prev blocks info" to emulator
* Adjusted builds (#13)
* Update flake.nix
Add libsodium
* add libsecp256k1-dev and libsodium-dev into wasm build
* make back emulator a shared library;
put emulator to artifacts;
compile wasm artifacts with sodium and secp256k1.
* add secp256k1 to nix
* compile emulator statically with nix
* compile emulator statically with nix
* compile emulator lib statically with nix
* compile emulator lib statically with nix
* add libemulator to artifacts
* add shared libemulator library to artifacts
* minor release fix
* update set-output commands;
add recent_changelog.md
* releases fixes
* releases fixes, multiline
* releases fixes, multiline
* releases fixes, multiline
* put back multiline changelog
* put back multiline changelog
* ConfigParam 19 (global-id) and GLOBALID instruction
* Fix gas consumption in HASHEXT
* Add blst library
* Add bls instructions
* Allow passing long code to opcode-timing
* Add bls testcase
* More BLS instructions
* Fix tests, add bls tests
* Add more bls tests
* Improve some bls operations
* Adjust some BLS gas prices
* Adjust BLS gas prices
* Enable __BLST_PORTABLE__ flag only if PORTABLE flag is set
* Add tests for BLS_PAIRING
* GASCONSUMED instruction
* Fix compilation against docker with blst library; (#14)
* fix compilation against docker with blst library;
add precompiled libblst.a to android builds
* minor fix
* Adjust BLKSWX gas
* Fix comparison with NAN
* Allow arbitrary integers for scalars in ristretto multiplication, fix test
* Adjust nix builds according to PR 694 (#15)
* integrate and test PR-694
* integrate and test PR-694, test 2
* Add P256_CHKSIGN (secp256r1)
---------
Co-authored-by: SpyCheese <mikle98@yandex.ru>
Co-authored-by: neodiX42 <namlem@gmail.com>
2023-05-24 18:14:13 +00:00
|
|
|
|
2024-01-12 09:34:28 +00:00
|
|
|
ComputePhaseConfig() : gas_price(0), gas_limit(0), special_gas_limit(0), gas_credit(0) {
|
2019-09-07 10:03:22 +00:00
|
|
|
compute_threshold();
|
|
|
|
}
|
|
|
|
void compute_threshold();
|
|
|
|
td::uint64 gas_bought_for(td::RefInt256 nanograms) const;
|
|
|
|
td::RefInt256 compute_gas_price(td::uint64 gas_used) const;
|
|
|
|
void set_gas_price(td::uint64 _gas_price) {
|
|
|
|
gas_price = _gas_price;
|
|
|
|
compute_threshold();
|
|
|
|
}
|
|
|
|
Ref<vm::Cell> lookup_library(td::ConstBitPtr key) const;
|
|
|
|
Ref<vm::Cell> lookup_library(const td::Bits256& key) const {
|
|
|
|
return lookup_library(key.bits());
|
|
|
|
}
|
|
|
|
Ref<vm::Cell> get_lib_root() const {
|
|
|
|
return libraries ? libraries->get_root_cell() : Ref<vm::Cell>{};
|
|
|
|
}
|
2019-10-03 13:04:52 +00:00
|
|
|
bool parse_GasLimitsPrices(Ref<vm::CellSlice> cs, td::RefInt256& freeze_due_limit, td::RefInt256& delete_due_limit);
|
|
|
|
bool parse_GasLimitsPrices(Ref<vm::Cell> cell, td::RefInt256& freeze_due_limit, td::RefInt256& delete_due_limit);
|
2023-01-09 17:37:58 +00:00
|
|
|
bool is_address_suspended(ton::WorkchainId wc, td::Bits256 addr) const;
|
2020-02-06 17:56:46 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool parse_GasLimitsPrices_internal(Ref<vm::CellSlice> cs, td::RefInt256& freeze_due_limit,
|
|
|
|
td::RefInt256& delete_due_limit, td::uint64 flat_gas_limit = 0,
|
|
|
|
td::uint64 flat_gas_price = 0);
|
2019-09-07 10:03:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ActionPhaseConfig {
|
|
|
|
int max_actions{255};
|
2020-03-23 23:32:16 +00:00
|
|
|
int bounce_msg_body{0}; // usually 0 or 256 bits
|
2019-09-07 10:03:22 +00:00
|
|
|
MsgPrices fwd_std;
|
|
|
|
MsgPrices fwd_mc; // from/to masterchain
|
2022-10-10 14:13:21 +00:00
|
|
|
SizeLimitsConfig size_limits;
|
2019-09-07 10:03:22 +00:00
|
|
|
const WorkchainSet* workchains{nullptr};
|
TVM Upgrade (#686)
* New TVM instructions
* Remove PREVBLOCKS
* Separate target ton_crypto into TVM-related and -unrelared code
* Add fine for failed "send message"; rework SENDMSG
* Fix include
* Fix bugs, improve action fines
* Disable fines for special accounts
* Handle msg_balance_remaining.grams == null in transaction.cpp
* Bugfixes in SENDMSG
* Fix fee calculation in SENDMSG
* Fix CellStorageStat and transaction.cpp after merge
* SETBOUNCEONACTIONPHASEFAIL instruction
* ADDDIVMOD instructions
* RUNVM, RUNVMX instructions
* Changes in RUNVM
* Tests for adddiv and runvm
* HASHEXT instruction
* Improve opcode-timing
More iterations
Don't measure preliminary run
Remove logs and other excessive operations
Add "error" to output
* Increase RUNVM gas price
* Optimize HASHEXT, adjust gas price
* Add "bounce of action fail" flag to actions
* Stack operations with unlimited arguments
* Ristretto255 instructions
* Adjust gas consumption
* Optional fixed number of return values in RUNVM, fix exception handling
* Adjust gas consumption
* Simplify gas consumption logic
* Support of secp256k1 and sodium libraries in builds (#11)
* add support of secp256k1 library to the builds (linux, win)
* add support of secp256k1 library to the builds (linux, win)
* install secp256k1 via brew
* install libsodium via brew;
change sodium to upper case in FindSodium.cmake
* install libsodium via brew;
change sodium to upper case in FindSodium.cmake
* simplify FindSodium.cmake
* bug fixing
* bug fixing
* bug fixing
* add macro SODIUM_STATIC
* adjust build command for windows
* put back original FindSodium.cmake
* put back original FindSodium.cmake
* fix sodium unzipped path for windows;
add ninja
* fix sodium unzipped path for windows;
add ninja
* fix sodium unzipped path for windows;
add ninja
* Win32 github build for secp256k1
* x64 architecture github build for secp256k1
* fix sodium linking on linux
* enable docker buildx arm64 builds from forked repos
* enable docker buildx arm64 builds from forked repos
* enable docker buildx arm64 builds from forked repos
* adjust mac builds for secp2561k and sodium
* fix tonlib jni generation
* minor fix
* sync fixes across platforms
* add libsodium build script for android and precompiled static libraries
* build tonlib for android (fails)
* FindSodium uppercase
* remove system libsodium for android, use precompiled instead;
specify SECP256K1_INCLUDE_DIR fir mac 12.6
* uppercase sodium
* simplify FindSodium
* fix windows build sodium path;
use ninja for windows
* simplify sodium 2
* adjust windows sodium paths;
add paths to android jni
* add ninja build windows
* add ninja build windows
* add ninja build windows 2
* remove win ninja
* fix 1
* fix 2
* fix win 3
* fix linux compile 3
* fix jni 1
* fix jni 2 and mac
* fix jni 3
* fix jni 4
* fix jni 5
* fix mac 6
* fix mac 7 and jni paths
* fix jni 8
* rework sodium for android
* rework sodium for android
* rework sodium for android 2
* fixed sodium for android 2
* fixed sodium for android 3
* static secp256k1 for android
* add precompiled arm secp256k1
* add precompiled arm secp256k1
* build native-lib with secp256k1 x86-64 (non arm)
* update precompiled with NDK libsecp256k1.a
* update precompiled with NDK libsecp256k1.a
* update precompiled with NDK libsecp256k1.a
* refactor llvm-strip location
* refactor llvm-strip location
* add native-lib.so for armv7a, armv8a
* add native-lib.so for armv7a, armv8a
* test armv7a, armv8a
* armv7a - fails linking on sodium, test -> armv8a
* works x86-64, armv7a - fails linking on sodium, armv8a - fails linking secp256k1 (incompatible with aarch64linux)
* update libpsec256k1, sodium static libs
* test x86 android native-lib
* test armv7 android native-lib
* test armv8 android native-lib
* x86_64 and arm64 android native-lib works
* x86_64 and arm64 android native-lib works
* x86_64 and arm64 android native-lib works
* test armv7 android native-lib
* test all android native-libs
* test all android native-libs
* test all android native-libs
* test all android native-libs - without SodiumAndroid
* test all android native-libs - with FindSodiumAndroid.cmake
* win, with Sodium via SODIUM_DIR
* win, with Sodium via SODIUM_DIR env
* win, with Sodium via SODIUM_DIR env
* win, with Sodium via SODIUM_DIR env and SODIUM_USE_STATIC_LIBS
* win, with Sodium via SODIUM_DIR, SODIUM_USE_STATIC_LIBS and SODIUM_INCLUDE_DIR
* android, with FindSodium
* android, with FindSodium with SODIUM_USE_STATIC_LIBS
* remove if not apple
* target_link_libraries(ton_crypto_core PUBLIC secp256k1)
* android SECP256K1_INCLUDE_DIRS
* android SECP256K1_INCLUDE_DIR
* add libsecp256k1.a/so pre-compiled with ubuntu 22 x86-64
* add libsecp256k1.a/so pre-compiled with ubuntu 22 x86-64
* sodium dirs
* sodium dirs
* sodium dirs
* remove NOT APPLE and SodiumAndroid
* add NOT APPLE and remove SodiumAndroid
* add NOT APPLE and remove SodiumAndroid
* remove build scripts for 18.04, reduce CMakeLists.txt
* remove build scripts for 18.04, reduce CMakeLists.txt
* Fix cas consumption during library load
* Fix fetch_config_params after merge
* Add all ADDDIVMOD ops to Asm.fif
* Save unpaid storage fee to due_payment
* Add "set prev blocks info" to emulator
* Adjusted builds (#13)
* Update flake.nix
Add libsodium
* add libsecp256k1-dev and libsodium-dev into wasm build
* make back emulator a shared library;
put emulator to artifacts;
compile wasm artifacts with sodium and secp256k1.
* add secp256k1 to nix
* compile emulator statically with nix
* compile emulator statically with nix
* compile emulator lib statically with nix
* compile emulator lib statically with nix
* add libemulator to artifacts
* add shared libemulator library to artifacts
* minor release fix
* update set-output commands;
add recent_changelog.md
* releases fixes
* releases fixes, multiline
* releases fixes, multiline
* releases fixes, multiline
* put back multiline changelog
* put back multiline changelog
* ConfigParam 19 (global-id) and GLOBALID instruction
* Fix gas consumption in HASHEXT
* Add blst library
* Add bls instructions
* Allow passing long code to opcode-timing
* Add bls testcase
* More BLS instructions
* Fix tests, add bls tests
* Add more bls tests
* Improve some bls operations
* Adjust some BLS gas prices
* Adjust BLS gas prices
* Enable __BLST_PORTABLE__ flag only if PORTABLE flag is set
* Add tests for BLS_PAIRING
* GASCONSUMED instruction
* Fix compilation against docker with blst library; (#14)
* fix compilation against docker with blst library;
add precompiled libblst.a to android builds
* minor fix
* Adjust BLKSWX gas
* Fix comparison with NAN
* Allow arbitrary integers for scalars in ristretto multiplication, fix test
* Adjust nix builds according to PR 694 (#15)
* integrate and test PR-694
* integrate and test PR-694, test 2
* Add P256_CHKSIGN (secp256r1)
---------
Co-authored-by: SpyCheese <mikle98@yandex.ru>
Co-authored-by: neodiX42 <namlem@gmail.com>
2023-05-24 18:14:13 +00:00
|
|
|
bool action_fine_enabled{false};
|
|
|
|
bool bounce_on_fail_enabled{false};
|
2023-05-18 08:26:02 +00:00
|
|
|
td::optional<td::Bits256> mc_blackhole_addr;
|
2019-09-07 10:03:22 +00:00
|
|
|
const MsgPrices& fetch_msg_prices(bool is_masterchain) const {
|
|
|
|
return is_masterchain ? fwd_mc : fwd_std;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CreditPhase {
|
|
|
|
td::RefInt256 due_fees_collected;
|
|
|
|
block::CurrencyCollection credit;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ComputePhase {
|
2023-01-09 17:37:58 +00:00
|
|
|
enum { sk_none, sk_no_state, sk_bad_state, sk_no_gas, sk_suspended };
|
2019-09-07 10:03:22 +00:00
|
|
|
int skip_reason{sk_none};
|
|
|
|
bool success{false};
|
|
|
|
bool msg_state_used{false};
|
|
|
|
bool account_activated{false};
|
|
|
|
bool out_of_gas{false};
|
|
|
|
bool accepted{false};
|
|
|
|
td::RefInt256 gas_fees;
|
|
|
|
td::uint64 gas_used, gas_max, gas_limit, gas_credit;
|
|
|
|
int mode;
|
|
|
|
int exit_code;
|
|
|
|
int exit_arg;
|
|
|
|
int vm_steps;
|
|
|
|
ton::Bits256 vm_init_state_hash, vm_final_state_hash;
|
|
|
|
Ref<vm::Cell> in_msg;
|
|
|
|
Ref<vm::Cell> new_data;
|
|
|
|
Ref<vm::Cell> actions;
|
2022-05-24 18:21:58 +00:00
|
|
|
std::string vm_log;
|
2019-09-07 10:03:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ActionPhase {
|
|
|
|
bool success{false};
|
|
|
|
bool valid{false};
|
|
|
|
bool no_funds{false};
|
|
|
|
bool code_changed{false};
|
|
|
|
bool action_list_invalid{false};
|
|
|
|
bool acc_delete_req{false};
|
2023-02-28 09:06:57 +00:00
|
|
|
bool state_exceeds_limits{false};
|
2019-09-07 10:03:22 +00:00
|
|
|
enum { acst_unchanged = 0, acst_frozen = 2, acst_deleted = 3 };
|
|
|
|
int acc_status_change{acst_unchanged};
|
|
|
|
td::RefInt256 total_fwd_fees; // all fees debited from the account
|
|
|
|
td::RefInt256 total_action_fees; // fees credited to validators in this action phase
|
|
|
|
int result_code;
|
|
|
|
int result_arg;
|
|
|
|
int tot_actions;
|
|
|
|
int spec_actions;
|
|
|
|
int skipped_actions;
|
|
|
|
int msgs_created;
|
|
|
|
Ref<vm::Cell> new_code;
|
|
|
|
td::BitArray<256> action_list_hash;
|
|
|
|
block::CurrencyCollection remaining_balance, reserved_balance;
|
|
|
|
std::vector<Ref<vm::Cell>> action_list; // processed in reverse order
|
|
|
|
std::vector<Ref<vm::Cell>> out_msgs;
|
|
|
|
ton::LogicalTime end_lt;
|
|
|
|
unsigned long long tot_msg_bits{0}, tot_msg_cells{0};
|
TVM Upgrade (#686)
* New TVM instructions
* Remove PREVBLOCKS
* Separate target ton_crypto into TVM-related and -unrelared code
* Add fine for failed "send message"; rework SENDMSG
* Fix include
* Fix bugs, improve action fines
* Disable fines for special accounts
* Handle msg_balance_remaining.grams == null in transaction.cpp
* Bugfixes in SENDMSG
* Fix fee calculation in SENDMSG
* Fix CellStorageStat and transaction.cpp after merge
* SETBOUNCEONACTIONPHASEFAIL instruction
* ADDDIVMOD instructions
* RUNVM, RUNVMX instructions
* Changes in RUNVM
* Tests for adddiv and runvm
* HASHEXT instruction
* Improve opcode-timing
More iterations
Don't measure preliminary run
Remove logs and other excessive operations
Add "error" to output
* Increase RUNVM gas price
* Optimize HASHEXT, adjust gas price
* Add "bounce of action fail" flag to actions
* Stack operations with unlimited arguments
* Ristretto255 instructions
* Adjust gas consumption
* Optional fixed number of return values in RUNVM, fix exception handling
* Adjust gas consumption
* Simplify gas consumption logic
* Support of secp256k1 and sodium libraries in builds (#11)
* add support of secp256k1 library to the builds (linux, win)
* add support of secp256k1 library to the builds (linux, win)
* install secp256k1 via brew
* install libsodium via brew;
change sodium to upper case in FindSodium.cmake
* install libsodium via brew;
change sodium to upper case in FindSodium.cmake
* simplify FindSodium.cmake
* bug fixing
* bug fixing
* bug fixing
* add macro SODIUM_STATIC
* adjust build command for windows
* put back original FindSodium.cmake
* put back original FindSodium.cmake
* fix sodium unzipped path for windows;
add ninja
* fix sodium unzipped path for windows;
add ninja
* fix sodium unzipped path for windows;
add ninja
* Win32 github build for secp256k1
* x64 architecture github build for secp256k1
* fix sodium linking on linux
* enable docker buildx arm64 builds from forked repos
* enable docker buildx arm64 builds from forked repos
* enable docker buildx arm64 builds from forked repos
* adjust mac builds for secp2561k and sodium
* fix tonlib jni generation
* minor fix
* sync fixes across platforms
* add libsodium build script for android and precompiled static libraries
* build tonlib for android (fails)
* FindSodium uppercase
* remove system libsodium for android, use precompiled instead;
specify SECP256K1_INCLUDE_DIR fir mac 12.6
* uppercase sodium
* simplify FindSodium
* fix windows build sodium path;
use ninja for windows
* simplify sodium 2
* adjust windows sodium paths;
add paths to android jni
* add ninja build windows
* add ninja build windows
* add ninja build windows 2
* remove win ninja
* fix 1
* fix 2
* fix win 3
* fix linux compile 3
* fix jni 1
* fix jni 2 and mac
* fix jni 3
* fix jni 4
* fix jni 5
* fix mac 6
* fix mac 7 and jni paths
* fix jni 8
* rework sodium for android
* rework sodium for android
* rework sodium for android 2
* fixed sodium for android 2
* fixed sodium for android 3
* static secp256k1 for android
* add precompiled arm secp256k1
* add precompiled arm secp256k1
* build native-lib with secp256k1 x86-64 (non arm)
* update precompiled with NDK libsecp256k1.a
* update precompiled with NDK libsecp256k1.a
* update precompiled with NDK libsecp256k1.a
* refactor llvm-strip location
* refactor llvm-strip location
* add native-lib.so for armv7a, armv8a
* add native-lib.so for armv7a, armv8a
* test armv7a, armv8a
* armv7a - fails linking on sodium, test -> armv8a
* works x86-64, armv7a - fails linking on sodium, armv8a - fails linking secp256k1 (incompatible with aarch64linux)
* update libpsec256k1, sodium static libs
* test x86 android native-lib
* test armv7 android native-lib
* test armv8 android native-lib
* x86_64 and arm64 android native-lib works
* x86_64 and arm64 android native-lib works
* x86_64 and arm64 android native-lib works
* test armv7 android native-lib
* test all android native-libs
* test all android native-libs
* test all android native-libs
* test all android native-libs - without SodiumAndroid
* test all android native-libs - with FindSodiumAndroid.cmake
* win, with Sodium via SODIUM_DIR
* win, with Sodium via SODIUM_DIR env
* win, with Sodium via SODIUM_DIR env
* win, with Sodium via SODIUM_DIR env and SODIUM_USE_STATIC_LIBS
* win, with Sodium via SODIUM_DIR, SODIUM_USE_STATIC_LIBS and SODIUM_INCLUDE_DIR
* android, with FindSodium
* android, with FindSodium with SODIUM_USE_STATIC_LIBS
* remove if not apple
* target_link_libraries(ton_crypto_core PUBLIC secp256k1)
* android SECP256K1_INCLUDE_DIRS
* android SECP256K1_INCLUDE_DIR
* add libsecp256k1.a/so pre-compiled with ubuntu 22 x86-64
* add libsecp256k1.a/so pre-compiled with ubuntu 22 x86-64
* sodium dirs
* sodium dirs
* sodium dirs
* remove NOT APPLE and SodiumAndroid
* add NOT APPLE and remove SodiumAndroid
* add NOT APPLE and remove SodiumAndroid
* remove build scripts for 18.04, reduce CMakeLists.txt
* remove build scripts for 18.04, reduce CMakeLists.txt
* Fix cas consumption during library load
* Fix fetch_config_params after merge
* Add all ADDDIVMOD ops to Asm.fif
* Save unpaid storage fee to due_payment
* Add "set prev blocks info" to emulator
* Adjusted builds (#13)
* Update flake.nix
Add libsodium
* add libsecp256k1-dev and libsodium-dev into wasm build
* make back emulator a shared library;
put emulator to artifacts;
compile wasm artifacts with sodium and secp256k1.
* add secp256k1 to nix
* compile emulator statically with nix
* compile emulator statically with nix
* compile emulator lib statically with nix
* compile emulator lib statically with nix
* add libemulator to artifacts
* add shared libemulator library to artifacts
* minor release fix
* update set-output commands;
add recent_changelog.md
* releases fixes
* releases fixes, multiline
* releases fixes, multiline
* releases fixes, multiline
* put back multiline changelog
* put back multiline changelog
* ConfigParam 19 (global-id) and GLOBALID instruction
* Fix gas consumption in HASHEXT
* Add blst library
* Add bls instructions
* Allow passing long code to opcode-timing
* Add bls testcase
* More BLS instructions
* Fix tests, add bls tests
* Add more bls tests
* Improve some bls operations
* Adjust some BLS gas prices
* Adjust BLS gas prices
* Enable __BLST_PORTABLE__ flag only if PORTABLE flag is set
* Add tests for BLS_PAIRING
* GASCONSUMED instruction
* Fix compilation against docker with blst library; (#14)
* fix compilation against docker with blst library;
add precompiled libblst.a to android builds
* minor fix
* Adjust BLKSWX gas
* Fix comparison with NAN
* Allow arbitrary integers for scalars in ristretto multiplication, fix test
* Adjust nix builds according to PR 694 (#15)
* integrate and test PR-694
* integrate and test PR-694, test 2
* Add P256_CHKSIGN (secp256r1)
---------
Co-authored-by: SpyCheese <mikle98@yandex.ru>
Co-authored-by: neodiX42 <namlem@gmail.com>
2023-05-24 18:14:13 +00:00
|
|
|
td::RefInt256 action_fine;
|
|
|
|
bool need_bounce_on_fail = false;
|
|
|
|
bool bounce = false;
|
2019-09-07 10:03:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct BouncePhase {
|
|
|
|
bool ok{false};
|
|
|
|
bool nofunds{false};
|
|
|
|
unsigned long long msg_bits, msg_cells;
|
|
|
|
unsigned long long fwd_fees, fwd_fees_collected;
|
|
|
|
Ref<vm::Cell> out_msg;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Account {
|
|
|
|
enum { acc_nonexist = 0, acc_uninit = 1, acc_frozen = 2, acc_active = 3, acc_deleted = 4 };
|
|
|
|
int status{acc_nonexist}, orig_status{acc_nonexist};
|
|
|
|
bool is_special{false};
|
|
|
|
bool tick{false};
|
|
|
|
bool tock{false};
|
|
|
|
bool split_depth_set_{false};
|
|
|
|
unsigned char split_depth_{0};
|
|
|
|
int verbosity{3 * 0};
|
|
|
|
ton::UnixTime now_{0};
|
|
|
|
ton::WorkchainId workchain{ton::workchainInvalid};
|
|
|
|
td::BitArray<32> addr_rewrite; // rewrite (anycast) data, split_depth bits
|
2021-12-31 15:48:51 +00:00
|
|
|
ton::StdSmcAddress addr; // rewritten address (by replacing a prefix of `addr_orig` with `addr_rewrite`); it is the key in ShardAccounts
|
|
|
|
ton::StdSmcAddress addr_orig; // address indicated in smart-contract data (must coincide with hash of StateInit)
|
|
|
|
Ref<vm::CellSlice> my_addr; // address as stored in the smart contract (MsgAddressInt); corresponds to `addr_orig` + anycast info
|
|
|
|
Ref<vm::CellSlice> my_addr_exact; // exact address without anycast info; corresponds to `addr` and has no anycast (rewrite) info
|
2019-09-07 10:03:22 +00:00
|
|
|
ton::LogicalTime last_trans_end_lt_;
|
|
|
|
ton::LogicalTime last_trans_lt_;
|
|
|
|
ton::Bits256 last_trans_hash_;
|
|
|
|
ton::LogicalTime block_lt;
|
|
|
|
ton::UnixTime last_paid;
|
|
|
|
vm::CellStorageStat storage_stat;
|
|
|
|
block::CurrencyCollection balance;
|
|
|
|
td::RefInt256 due_payment;
|
|
|
|
Ref<vm::Cell> orig_total_state; // ^Account
|
|
|
|
Ref<vm::Cell> total_state; // ^Account
|
2022-11-24 16:16:55 +00:00
|
|
|
Ref<vm::CellSlice> storage; // AccountStorage
|
2019-09-07 10:03:22 +00:00
|
|
|
Ref<vm::CellSlice> inner_state; // StateInit
|
|
|
|
ton::Bits256 state_hash; // hash of StateInit for frozen accounts
|
|
|
|
Ref<vm::Cell> code, data, library, orig_library;
|
|
|
|
std::vector<LtCellRef> transactions;
|
|
|
|
Account() = default;
|
|
|
|
Account(ton::WorkchainId wc, td::ConstBitPtr _addr) : workchain(wc), addr(_addr) {
|
|
|
|
}
|
|
|
|
Account(ton::WorkchainId wc, td::ConstBitPtr _addr, int depth)
|
|
|
|
: split_depth_set_(true), split_depth_((unsigned char)depth), workchain(wc), addr(_addr) {
|
|
|
|
}
|
|
|
|
block::CurrencyCollection get_balance() const {
|
|
|
|
return balance;
|
|
|
|
}
|
|
|
|
bool set_address(ton::WorkchainId wc, td::ConstBitPtr new_addr);
|
2023-11-03 11:43:34 +00:00
|
|
|
bool unpack(Ref<vm::CellSlice> account, ton::UnixTime now, bool special);
|
2019-09-07 10:03:22 +00:00
|
|
|
bool init_new(ton::UnixTime now);
|
2021-12-31 15:48:51 +00:00
|
|
|
bool deactivate();
|
2019-09-07 10:03:22 +00:00
|
|
|
bool recompute_tmp_addr(Ref<vm::CellSlice>& tmp_addr, int split_depth, td::ConstBitPtr orig_addr_rewrite) const;
|
|
|
|
td::RefInt256 compute_storage_fees(ton::UnixTime now, const std::vector<block::StoragePrices>& pricing) const;
|
|
|
|
bool is_masterchain() const {
|
|
|
|
return workchain == ton::masterchainId;
|
|
|
|
}
|
|
|
|
bool belongs_to_shard(ton::ShardIdFull shard) const;
|
|
|
|
bool store_acc_status(vm::CellBuilder& cb, int status) const;
|
|
|
|
bool store_acc_status(vm::CellBuilder& cb) const {
|
|
|
|
return store_acc_status(cb, status);
|
|
|
|
}
|
|
|
|
void push_transaction(Ref<vm::Cell> trans_root, ton::LogicalTime trans_lt);
|
|
|
|
bool libraries_changed() const;
|
|
|
|
bool create_account_block(vm::CellBuilder& cb); // stores an AccountBlock with all transactions
|
|
|
|
|
|
|
|
protected:
|
2023-02-02 07:03:45 +00:00
|
|
|
friend struct transaction::Transaction;
|
2019-09-07 10:03:22 +00:00
|
|
|
bool set_split_depth(int split_depth);
|
|
|
|
bool check_split_depth(int split_depth) const;
|
2021-12-31 15:48:51 +00:00
|
|
|
bool forget_split_depth();
|
2019-09-07 10:03:22 +00:00
|
|
|
bool init_rewrite_addr(int split_depth, td::ConstBitPtr orig_addr_rewrite);
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool unpack_address(vm::CellSlice& addr_cs);
|
|
|
|
bool unpack_storage_info(vm::CellSlice& cs);
|
|
|
|
bool unpack_state(vm::CellSlice& cs);
|
|
|
|
bool parse_maybe_anycast(vm::CellSlice& cs);
|
|
|
|
bool store_maybe_anycast(vm::CellBuilder& cb) const;
|
|
|
|
bool compute_my_addr(bool force = false);
|
|
|
|
};
|
|
|
|
|
2023-02-02 07:03:45 +00:00
|
|
|
namespace transaction {
|
2019-09-07 10:03:22 +00:00
|
|
|
struct Transaction {
|
2023-02-28 09:06:57 +00:00
|
|
|
static constexpr unsigned max_allowed_merkle_depth = 2;
|
2019-09-07 10:03:22 +00:00
|
|
|
enum {
|
|
|
|
tr_none,
|
|
|
|
tr_ord,
|
|
|
|
tr_storage,
|
|
|
|
tr_tick,
|
|
|
|
tr_tock,
|
|
|
|
tr_split_prepare,
|
|
|
|
tr_split_install,
|
|
|
|
tr_merge_prepare,
|
|
|
|
tr_merge_install
|
|
|
|
};
|
|
|
|
int trans_type{tr_none};
|
|
|
|
bool was_deleted{false};
|
|
|
|
bool was_frozen{false};
|
|
|
|
bool was_activated{false};
|
|
|
|
bool was_created{false};
|
|
|
|
bool bounce_enabled{false};
|
|
|
|
bool in_msg_extern{false};
|
|
|
|
bool use_msg_state{false};
|
|
|
|
bool is_first{false};
|
|
|
|
bool orig_addr_rewrite_set{false};
|
|
|
|
bool new_tick;
|
|
|
|
bool new_tock;
|
|
|
|
signed char new_split_depth{-1};
|
|
|
|
ton::UnixTime now;
|
|
|
|
int acc_status;
|
|
|
|
int verbosity{3 * 0};
|
|
|
|
int in_msg_type{0};
|
|
|
|
const Account& account; // only `commit` method modifies the account
|
|
|
|
Ref<vm::CellSlice> my_addr, my_addr_exact; // almost the same as in account.*
|
|
|
|
ton::LogicalTime start_lt, end_lt;
|
2020-02-15 16:03:17 +00:00
|
|
|
block::CurrencyCollection balance, original_balance;
|
2019-09-07 10:03:22 +00:00
|
|
|
block::CurrencyCollection msg_balance_remaining;
|
|
|
|
td::RefInt256 due_payment;
|
|
|
|
td::RefInt256 in_fwd_fee, msg_fwd_fees;
|
|
|
|
block::CurrencyCollection total_fees{0};
|
2023-05-18 08:26:02 +00:00
|
|
|
block::CurrencyCollection blackhole_burned{0};
|
2019-09-07 10:03:22 +00:00
|
|
|
ton::UnixTime last_paid;
|
|
|
|
Ref<vm::Cell> root;
|
|
|
|
Ref<vm::Cell> new_total_state;
|
2022-11-24 16:16:55 +00:00
|
|
|
Ref<vm::CellSlice> new_storage;
|
2019-09-07 10:03:22 +00:00
|
|
|
Ref<vm::CellSlice> new_inner_state;
|
|
|
|
Ref<vm::Cell> new_code, new_data, new_library;
|
|
|
|
Ref<vm::Cell> in_msg, in_msg_state;
|
|
|
|
Ref<vm::CellSlice> in_msg_body;
|
|
|
|
Ref<vm::Cell> in_msg_library;
|
|
|
|
td::BitArray<256> frozen_hash;
|
|
|
|
td::BitArray<32> orig_addr_rewrite;
|
|
|
|
std::vector<Ref<vm::Cell>> out_msgs;
|
|
|
|
std::unique_ptr<StoragePhase> storage_phase;
|
|
|
|
std::unique_ptr<CreditPhase> credit_phase;
|
|
|
|
std::unique_ptr<ComputePhase> compute_phase;
|
|
|
|
std::unique_ptr<ActionPhase> action_phase;
|
|
|
|
std::unique_ptr<BouncePhase> bounce_phase;
|
|
|
|
vm::CellStorageStat new_storage_stat;
|
2024-01-15 20:43:11 +00:00
|
|
|
bool gas_limit_overridden{false};
|
2019-09-07 10:03:22 +00:00
|
|
|
Transaction(const Account& _account, int ttype, ton::LogicalTime req_start_lt, ton::UnixTime _now,
|
|
|
|
Ref<vm::Cell> _inmsg = {});
|
|
|
|
bool unpack_input_msg(bool ihr_delivered, const ActionPhaseConfig* cfg);
|
|
|
|
bool check_in_msg_state_hash();
|
2020-04-10 19:06:01 +00:00
|
|
|
bool prepare_storage_phase(const StoragePhaseConfig& cfg, bool force_collect = true, bool adjust_msg_value = false);
|
2019-09-07 10:03:22 +00:00
|
|
|
bool prepare_credit_phase();
|
2024-01-15 20:43:11 +00:00
|
|
|
td::uint64 gas_bought_for(const ComputePhaseConfig& cfg, td::RefInt256 nanograms);
|
2019-09-07 10:03:22 +00:00
|
|
|
bool compute_gas_limits(ComputePhase& cp, const ComputePhaseConfig& cfg);
|
|
|
|
Ref<vm::Stack> prepare_vm_stack(ComputePhase& cp);
|
|
|
|
std::vector<Ref<vm::Cell>> compute_vm_libraries(const ComputePhaseConfig& cfg);
|
|
|
|
bool prepare_compute_phase(const ComputePhaseConfig& cfg);
|
|
|
|
bool prepare_action_phase(const ActionPhaseConfig& cfg);
|
2023-11-23 15:17:44 +00:00
|
|
|
td::Status check_state_limits(const SizeLimitsConfig& size_limits, bool update_storage_stat = true);
|
2019-09-07 10:03:22 +00:00
|
|
|
bool prepare_bounce_phase(const ActionPhaseConfig& cfg);
|
|
|
|
bool compute_state();
|
|
|
|
bool serialize();
|
|
|
|
td::uint64 gas_used() const {
|
|
|
|
return compute_phase ? compute_phase->gas_used : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
td::Result<vm::NewCellStorageStat::Stat> estimate_block_storage_profile_incr(
|
|
|
|
const vm::NewCellStorageStat& store_stat, const vm::CellUsageTree* usage_tree) const;
|
2024-01-12 09:34:28 +00:00
|
|
|
bool update_limits(block::BlockLimitStatus& blk_lim_st, bool with_gas = true, bool with_size = true) const;
|
2019-09-07 10:03:22 +00:00
|
|
|
|
|
|
|
Ref<vm::Cell> commit(Account& _account); // _account should point to the same account
|
|
|
|
LtCellRef extract_out_msg(unsigned i);
|
|
|
|
NewOutMsg extract_out_msg_ext(unsigned i);
|
|
|
|
void extract_out_msgs(std::vector<LtCellRef>& list);
|
|
|
|
|
|
|
|
private:
|
|
|
|
Ref<vm::Tuple> prepare_vm_c7(const ComputePhaseConfig& cfg) const;
|
|
|
|
bool prepare_rand_seed(td::BitArray<256>& rand_seed, const ComputePhaseConfig& cfg) const;
|
|
|
|
int try_action_set_code(vm::CellSlice& cs, ActionPhase& ap, const ActionPhaseConfig& cfg);
|
2019-11-28 14:44:14 +00:00
|
|
|
int try_action_change_library(vm::CellSlice& cs, ActionPhase& ap, const ActionPhaseConfig& cfg);
|
2019-09-28 07:44:38 +00:00
|
|
|
int try_action_send_msg(const vm::CellSlice& cs, ActionPhase& ap, const ActionPhaseConfig& cfg, int redoing = 0);
|
2019-09-07 10:03:22 +00:00
|
|
|
int try_action_reserve_currency(vm::CellSlice& cs, ActionPhase& ap, const ActionPhaseConfig& cfg);
|
|
|
|
bool check_replace_src_addr(Ref<vm::CellSlice>& src_addr) const;
|
|
|
|
bool check_rewrite_dest_addr(Ref<vm::CellSlice>& dest_addr, const ActionPhaseConfig& cfg,
|
|
|
|
bool* is_mc = nullptr) const;
|
|
|
|
bool serialize_storage_phase(vm::CellBuilder& cb);
|
|
|
|
bool serialize_credit_phase(vm::CellBuilder& cb);
|
|
|
|
bool serialize_compute_phase(vm::CellBuilder& cb);
|
|
|
|
bool serialize_action_phase(vm::CellBuilder& cb);
|
|
|
|
bool serialize_bounce_phase(vm::CellBuilder& cb);
|
2023-11-23 15:17:44 +00:00
|
|
|
bool unpack_msg_state(const ComputePhaseConfig& cfg, bool lib_only = false, bool forbid_public_libs = false);
|
2019-09-07 10:03:22 +00:00
|
|
|
};
|
2023-02-02 07:03:45 +00:00
|
|
|
} // namespace transaction
|
|
|
|
|
|
|
|
struct FetchConfigParams {
|
TVM Upgrade (#686)
* New TVM instructions
* Remove PREVBLOCKS
* Separate target ton_crypto into TVM-related and -unrelared code
* Add fine for failed "send message"; rework SENDMSG
* Fix include
* Fix bugs, improve action fines
* Disable fines for special accounts
* Handle msg_balance_remaining.grams == null in transaction.cpp
* Bugfixes in SENDMSG
* Fix fee calculation in SENDMSG
* Fix CellStorageStat and transaction.cpp after merge
* SETBOUNCEONACTIONPHASEFAIL instruction
* ADDDIVMOD instructions
* RUNVM, RUNVMX instructions
* Changes in RUNVM
* Tests for adddiv and runvm
* HASHEXT instruction
* Improve opcode-timing
More iterations
Don't measure preliminary run
Remove logs and other excessive operations
Add "error" to output
* Increase RUNVM gas price
* Optimize HASHEXT, adjust gas price
* Add "bounce of action fail" flag to actions
* Stack operations with unlimited arguments
* Ristretto255 instructions
* Adjust gas consumption
* Optional fixed number of return values in RUNVM, fix exception handling
* Adjust gas consumption
* Simplify gas consumption logic
* Support of secp256k1 and sodium libraries in builds (#11)
* add support of secp256k1 library to the builds (linux, win)
* add support of secp256k1 library to the builds (linux, win)
* install secp256k1 via brew
* install libsodium via brew;
change sodium to upper case in FindSodium.cmake
* install libsodium via brew;
change sodium to upper case in FindSodium.cmake
* simplify FindSodium.cmake
* bug fixing
* bug fixing
* bug fixing
* add macro SODIUM_STATIC
* adjust build command for windows
* put back original FindSodium.cmake
* put back original FindSodium.cmake
* fix sodium unzipped path for windows;
add ninja
* fix sodium unzipped path for windows;
add ninja
* fix sodium unzipped path for windows;
add ninja
* Win32 github build for secp256k1
* x64 architecture github build for secp256k1
* fix sodium linking on linux
* enable docker buildx arm64 builds from forked repos
* enable docker buildx arm64 builds from forked repos
* enable docker buildx arm64 builds from forked repos
* adjust mac builds for secp2561k and sodium
* fix tonlib jni generation
* minor fix
* sync fixes across platforms
* add libsodium build script for android and precompiled static libraries
* build tonlib for android (fails)
* FindSodium uppercase
* remove system libsodium for android, use precompiled instead;
specify SECP256K1_INCLUDE_DIR fir mac 12.6
* uppercase sodium
* simplify FindSodium
* fix windows build sodium path;
use ninja for windows
* simplify sodium 2
* adjust windows sodium paths;
add paths to android jni
* add ninja build windows
* add ninja build windows
* add ninja build windows 2
* remove win ninja
* fix 1
* fix 2
* fix win 3
* fix linux compile 3
* fix jni 1
* fix jni 2 and mac
* fix jni 3
* fix jni 4
* fix jni 5
* fix mac 6
* fix mac 7 and jni paths
* fix jni 8
* rework sodium for android
* rework sodium for android
* rework sodium for android 2
* fixed sodium for android 2
* fixed sodium for android 3
* static secp256k1 for android
* add precompiled arm secp256k1
* add precompiled arm secp256k1
* build native-lib with secp256k1 x86-64 (non arm)
* update precompiled with NDK libsecp256k1.a
* update precompiled with NDK libsecp256k1.a
* update precompiled with NDK libsecp256k1.a
* refactor llvm-strip location
* refactor llvm-strip location
* add native-lib.so for armv7a, armv8a
* add native-lib.so for armv7a, armv8a
* test armv7a, armv8a
* armv7a - fails linking on sodium, test -> armv8a
* works x86-64, armv7a - fails linking on sodium, armv8a - fails linking secp256k1 (incompatible with aarch64linux)
* update libpsec256k1, sodium static libs
* test x86 android native-lib
* test armv7 android native-lib
* test armv8 android native-lib
* x86_64 and arm64 android native-lib works
* x86_64 and arm64 android native-lib works
* x86_64 and arm64 android native-lib works
* test armv7 android native-lib
* test all android native-libs
* test all android native-libs
* test all android native-libs
* test all android native-libs - without SodiumAndroid
* test all android native-libs - with FindSodiumAndroid.cmake
* win, with Sodium via SODIUM_DIR
* win, with Sodium via SODIUM_DIR env
* win, with Sodium via SODIUM_DIR env
* win, with Sodium via SODIUM_DIR env and SODIUM_USE_STATIC_LIBS
* win, with Sodium via SODIUM_DIR, SODIUM_USE_STATIC_LIBS and SODIUM_INCLUDE_DIR
* android, with FindSodium
* android, with FindSodium with SODIUM_USE_STATIC_LIBS
* remove if not apple
* target_link_libraries(ton_crypto_core PUBLIC secp256k1)
* android SECP256K1_INCLUDE_DIRS
* android SECP256K1_INCLUDE_DIR
* add libsecp256k1.a/so pre-compiled with ubuntu 22 x86-64
* add libsecp256k1.a/so pre-compiled with ubuntu 22 x86-64
* sodium dirs
* sodium dirs
* sodium dirs
* remove NOT APPLE and SodiumAndroid
* add NOT APPLE and remove SodiumAndroid
* add NOT APPLE and remove SodiumAndroid
* remove build scripts for 18.04, reduce CMakeLists.txt
* remove build scripts for 18.04, reduce CMakeLists.txt
* Fix cas consumption during library load
* Fix fetch_config_params after merge
* Add all ADDDIVMOD ops to Asm.fif
* Save unpaid storage fee to due_payment
* Add "set prev blocks info" to emulator
* Adjusted builds (#13)
* Update flake.nix
Add libsodium
* add libsecp256k1-dev and libsodium-dev into wasm build
* make back emulator a shared library;
put emulator to artifacts;
compile wasm artifacts with sodium and secp256k1.
* add secp256k1 to nix
* compile emulator statically with nix
* compile emulator statically with nix
* compile emulator lib statically with nix
* compile emulator lib statically with nix
* add libemulator to artifacts
* add shared libemulator library to artifacts
* minor release fix
* update set-output commands;
add recent_changelog.md
* releases fixes
* releases fixes, multiline
* releases fixes, multiline
* releases fixes, multiline
* put back multiline changelog
* put back multiline changelog
* ConfigParam 19 (global-id) and GLOBALID instruction
* Fix gas consumption in HASHEXT
* Add blst library
* Add bls instructions
* Allow passing long code to opcode-timing
* Add bls testcase
* More BLS instructions
* Fix tests, add bls tests
* Add more bls tests
* Improve some bls operations
* Adjust some BLS gas prices
* Adjust BLS gas prices
* Enable __BLST_PORTABLE__ flag only if PORTABLE flag is set
* Add tests for BLS_PAIRING
* GASCONSUMED instruction
* Fix compilation against docker with blst library; (#14)
* fix compilation against docker with blst library;
add precompiled libblst.a to android builds
* minor fix
* Adjust BLKSWX gas
* Fix comparison with NAN
* Allow arbitrary integers for scalars in ristretto multiplication, fix test
* Adjust nix builds according to PR 694 (#15)
* integrate and test PR-694
* integrate and test PR-694, test 2
* Add P256_CHKSIGN (secp256r1)
---------
Co-authored-by: SpyCheese <mikle98@yandex.ru>
Co-authored-by: neodiX42 <namlem@gmail.com>
2023-05-24 18:14:13 +00:00
|
|
|
static td::Status fetch_config_params(const block::ConfigInfo& config, Ref<vm::Cell>* old_mparams,
|
|
|
|
std::vector<block::StoragePrices>* storage_prices,
|
|
|
|
StoragePhaseConfig* storage_phase_cfg, td::BitArray<256>* rand_seed,
|
|
|
|
ComputePhaseConfig* compute_phase_cfg, ActionPhaseConfig* action_phase_cfg,
|
|
|
|
td::RefInt256* masterchain_create_fee, td::RefInt256* basechain_create_fee,
|
|
|
|
ton::WorkchainId wc, ton::UnixTime now);
|
|
|
|
static td::Status fetch_config_params(const block::Config& config, Ref<vm::Tuple> prev_blocks_info,
|
|
|
|
Ref<vm::Cell>* old_mparams, std::vector<block::StoragePrices>* storage_prices,
|
|
|
|
StoragePhaseConfig* storage_phase_cfg, td::BitArray<256>* rand_seed,
|
|
|
|
ComputePhaseConfig* compute_phase_cfg, ActionPhaseConfig* action_phase_cfg,
|
|
|
|
td::RefInt256* masterchain_create_fee, td::RefInt256* basechain_create_fee,
|
|
|
|
ton::WorkchainId wc, ton::UnixTime now);
|
2023-02-02 07:03:45 +00:00
|
|
|
};
|
2019-09-07 10:03:22 +00:00
|
|
|
|
|
|
|
} // namespace block
|