Skip to content

Commit a2bd695

Browse files
Fix prepare_vm_c7 (ton-blockchain#958)
Co-authored-by: SpyCheese <mikle98@yandex.ru>
1 parent b8111d8 commit a2bd695

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

crypto/block/transaction.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -1321,7 +1321,7 @@ Ref<vm::Tuple> Transaction::prepare_vm_c7(const ComputePhaseConfig& cfg) const {
13211321
vm::StackEntry::maybe(cfg.global_config) // global_config:(Maybe Cell) ] = SmartContractInfo;
13221322
};
13231323
if (cfg.global_version >= 4) {
1324-
tuple.push_back(new_code); // code:Cell
1324+
tuple.push_back(vm::StackEntry::maybe(new_code)); // code:Cell
13251325
if (msg_balance_remaining.is_valid()) {
13261326
tuple.push_back(msg_balance_remaining.as_vm_tuple()); // in_msg_value:[Integer (Maybe Cell)]
13271327
} else {
@@ -1338,11 +1338,10 @@ Ref<vm::Tuple> Transaction::prepare_vm_c7(const ComputePhaseConfig& cfg) const {
13381338
// Inside validator, collator and liteserver checking external message contexts
13391339
// prev_blocks_info is always not null, since get_prev_blocks_info()
13401340
// may only return tuple or raise Error (See crypto/block/mc-config.cpp#2223)
1341-
tuple.push_back(cfg.prev_blocks_info.not_null() ? vm::StackEntry(cfg.prev_blocks_info) : vm::StackEntry());
1341+
tuple.push_back(vm::StackEntry::maybe(cfg.prev_blocks_info));
13421342
}
13431343
if (cfg.global_version >= 6) {
1344-
tuple.push_back(cfg.unpacked_config_tuple.not_null() ? vm::StackEntry(cfg.unpacked_config_tuple)
1345-
: vm::StackEntry()); // unpacked_config_tuple:[...]
1344+
tuple.push_back(vm::StackEntry::maybe(cfg.unpacked_config_tuple)); // unpacked_config_tuple:[...]
13461345
tuple.push_back(due_payment.not_null() ? due_payment : td::zero_refint()); // due_payment:Integer
13471346
tuple.push_back(compute_phase->precompiled_gas_usage
13481347
? vm::StackEntry(td::make_refint(compute_phase->precompiled_gas_usage.value()))

crypto/smc-envelope/SmartContract.cpp

+7-4
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,11 @@ td::Ref<vm::Tuple> prepare_vm_c7(SmartContract::Args args, td::Ref<vm::Cell> cod
157157
td::make_refint(0), //TODO: // trans_lt:Integer
158158
std::move(rand_seed_int), // rand_seed:Integer
159159
block::CurrencyCollection(args.balance).as_vm_tuple(), // balance_remaining:[Integer (Maybe Cell)]
160-
vm::load_cell_slice_ref(address), // myself:MsgAddressInt
161-
vm::StackEntry::maybe(config) //vm::StackEntry::maybe(td::Ref<vm::Cell>())
160+
vm::load_cell_slice_ref(address), // myself:MsgAddressInt
161+
vm::StackEntry::maybe(config) // vm::StackEntry::maybe(td::Ref<vm::Cell>())
162162
};
163163
if (args.config && args.config.value()->get_global_version() >= 4) {
164-
tuple.push_back(code.not_null() ? code : vm::StackEntry{}); // code:Cell
164+
tuple.push_back(vm::StackEntry::maybe(code)); // code:Cell
165165
tuple.push_back(block::CurrencyCollection::zero().as_vm_tuple()); // in_msg_value:[Integer (Maybe Cell)]
166166
tuple.push_back(td::zero_refint()); // storage_fees:Integer
167167

@@ -175,7 +175,10 @@ td::Ref<vm::Tuple> prepare_vm_c7(SmartContract::Args args, td::Ref<vm::Cell> cod
175175
tuple.push_back(args.config.value()->get_unpacked_config_tuple(now)); // unpacked_config_tuple
176176
tuple.push_back(td::zero_refint()); // due_payment
177177
// precomiled_gas_usage:(Maybe Integer)
178-
auto precompiled = args.config.value()->get_precompiled_contracts_config().get_contract(code->get_hash().bits());
178+
td::optional<block::PrecompiledContractsConfig::Contract> precompiled;
179+
if (code.not_null()) {
180+
precompiled = args.config.value()->get_precompiled_contracts_config().get_contract(code->get_hash().bits());
181+
}
179182
tuple.push_back(precompiled ? td::make_refint(precompiled.value().gas_usage) : vm::StackEntry());
180183
}
181184
auto tuple_ref = td::make_cnt_ref<std::vector<vm::StackEntry>>(std::move(tuple));

validator/impl/liteserver.cpp

+7-4
Original file line numberDiff line numberDiff line change
@@ -1419,7 +1419,7 @@ static td::Ref<vm::Tuple> prepare_vm_c7(ton::UnixTime now, ton::LogicalTime lt,
14191419
config ? config->get_root_cell() : vm::StackEntry() // global_config:(Maybe Cell) ] = SmartContractInfo;
14201420
};
14211421
if (config && config->get_global_version() >= 4) {
1422-
tuple.push_back(my_code); // code:Cell
1422+
tuple.push_back(vm::StackEntry::maybe(my_code)); // code:Cell
14231423
tuple.push_back(block::CurrencyCollection::zero().as_vm_tuple()); // in_msg_value:[Integer (Maybe Cell)]
14241424
tuple.push_back(td::zero_refint()); // storage_fees:Integer
14251425

@@ -1430,10 +1430,13 @@ static td::Ref<vm::Tuple> prepare_vm_c7(ton::UnixTime now, ton::LogicalTime lt,
14301430
tuple.push_back(info.is_ok() ? info.move_as_ok() : vm::StackEntry());
14311431
}
14321432
if (config && config->get_global_version() >= 6) {
1433-
tuple.push_back(config->get_unpacked_config_tuple(now)); // unpacked_config_tuple:[...]
1434-
tuple.push_back(due_payment); // due_payment:Integer
1433+
tuple.push_back(vm::StackEntry::maybe(config->get_unpacked_config_tuple(now))); // unpacked_config_tuple:[...]
1434+
tuple.push_back(due_payment); // due_payment:Integer
14351435
// precomiled_gas_usage:(Maybe Integer)
1436-
auto precompiled = config->get_precompiled_contracts_config().get_contract(my_code->get_hash().bits());
1436+
td::optional<block::PrecompiledContractsConfig::Contract> precompiled;
1437+
if (my_code.not_null()) {
1438+
precompiled = config->get_precompiled_contracts_config().get_contract(my_code->get_hash().bits());
1439+
}
14371440
tuple.push_back(precompiled ? td::make_refint(precompiled.value().gas_usage) : vm::StackEntry());
14381441
}
14391442
auto tuple_ref = td::make_cnt_ref<std::vector<vm::StackEntry>>(std::move(tuple));

0 commit comments

Comments
 (0)