1
0
Fork 0
mirror of https://github.com/ton-blockchain/ton synced 2025-03-09 15:40:10 +00:00

Add infrastructure for precompiled smartcontracts (#927)

* Utils for writing precompiled contracts

* Precompiled contracts in config, override gas_usage for them

* Add base class for precompiled contracts

* Improve utils for precompiled smc

* Implement GETPRECOMPILEDGAS

* Enable precompiles by flag

* Process null data in PrecompiledSmartContract

* Fix ton_block wasm build

* Fix vm::util::store_(u)long

---------

Co-authored-by: SpyCheese <mikle98@yandex.ru>
This commit is contained in:
EmelyanenkoK 2024-03-05 16:54:49 +03:00 committed by GitHub
parent b09f910bf2
commit 9d05696452
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
21 changed files with 991 additions and 95 deletions

View file

@ -29,6 +29,7 @@
#include "ton/ton-types.h"
#include "block/block.h"
#include "block/mc-config.h"
#include "precompiled-smc/PrecompiledSmartContract.h"
namespace block {
using td::Ref;
@ -122,6 +123,8 @@ struct ComputePhaseConfig {
SizeLimitsConfig size_limits;
int vm_log_verbosity = 0;
bool stop_on_accept_message = false;
PrecompiledContractsConfig precompiled_contracts;
bool dont_run_precompiled_ = false;
ComputePhaseConfig() : gas_price(0), gas_limit(0), special_gas_limit(0), gas_credit(0) {
compute_threshold();
@ -189,6 +192,7 @@ struct ComputePhase {
Ref<vm::Cell> new_data;
Ref<vm::Cell> actions;
std::string vm_log;
td::optional<td::uint64> precompiled_gas_usage;
};
struct ActionPhase {
@ -372,6 +376,7 @@ struct Transaction {
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 run_precompiled_contract(const ComputePhaseConfig& cfg, precompiled::PrecompiledSmartContract& precompiled);
bool prepare_compute_phase(const ComputePhaseConfig& cfg);
bool prepare_action_phase(const ActionPhaseConfig& cfg);
td::Status check_state_limits(const SizeLimitsConfig& size_limits, bool update_storage_stat = true);