Skip to content

Commit e99f5e8

Browse files
authored
Merge pull request #1881 from ton-blockchain/node-patch
Various changes in node
2 parents b67dc6e + 5f84e9c commit e99f5e8

28 files changed

+479
-898
lines changed

adnl/adnl.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,11 @@ class Adnl : public AdnlSenderInterface {
6666
public:
6767
class Callback {
6868
public:
69-
virtual void receive_message(AdnlNodeIdShort src, AdnlNodeIdShort dst, td::BufferSlice data) = 0;
69+
virtual void receive_message(AdnlNodeIdShort src, AdnlNodeIdShort dst, td::BufferSlice data) {
70+
}
7071
virtual void receive_query(AdnlNodeIdShort src, AdnlNodeIdShort dst, td::BufferSlice data,
71-
td::Promise<td::BufferSlice> promise) = 0;
72+
td::Promise<td::BufferSlice> promise) {
73+
}
7274
virtual ~Callback() = default;
7375
};
7476

catchain/catchain-receiver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ void CatChainReceiverImpl::synchronize_with(CatChainReceiverSource *S) {
825825
if (SS->blamed()) {
826826
rt[i] = -1;
827827
} else {
828-
rt[i] = static_cast<td::int32>(S->delivered_height());
828+
rt[i] = static_cast<td::int32>(SS->delivered_height());
829829
}
830830
}
831831

common/global-version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@
1919
namespace ton {
2020

2121
// See doc/GlobalVersions.md
22-
constexpr int SUPPORTED_VERSION = 12;
22+
constexpr int SUPPORTED_VERSION = 13;
2323

2424
} // namespace ton

create-hardfork/create-hardfork.cpp

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -234,49 +234,6 @@ class HardforkCreator : public td::actor::Actor {
234234
td::actor::send_closure(id_, &ton::validator::ValidatorManager::sync_complete,
235235
td::PromiseCreator::lambda([](td::Unit) {}));
236236
}
237-
void on_new_masterchain_block(td::Ref<ton::validator::MasterchainState> state,
238-
std::set<ton::ShardIdFull> shards_to_monitor) override {
239-
}
240-
void send_ihr_message(ton::AccountIdPrefixFull dst, td::BufferSlice data) override {
241-
}
242-
void send_ext_message(ton::AccountIdPrefixFull dst, td::BufferSlice data) override {
243-
}
244-
void send_shard_block_info(ton::BlockIdExt block_id, ton::CatchainSeqno cc_seqno, td::BufferSlice data) override {
245-
}
246-
void send_block_candidate(ton::BlockIdExt block_id, ton::CatchainSeqno cc_seqno, td::uint32 validator_set_hash,
247-
td::BufferSlice data, int mode) override {
248-
}
249-
void send_broadcast(ton::BlockBroadcast broadcast, int mode) override {
250-
}
251-
void download_block(ton::BlockIdExt block_id, td::uint32 priority, td::Timestamp timeout,
252-
td::Promise<ton::ReceivedBlock> promise) override {
253-
}
254-
void download_zero_state(ton::BlockIdExt block_id, td::uint32 priority, td::Timestamp timeout,
255-
td::Promise<td::BufferSlice> promise) override {
256-
}
257-
void download_persistent_state(ton::BlockIdExt block_id, ton::BlockIdExt masterchain_block_id,
258-
ton::validator::PersistentStateType type, td::uint32 priority,
259-
td::Timestamp timeout, td::Promise<td::BufferSlice> promise) override {
260-
}
261-
void download_block_proof(ton::BlockIdExt block_id, td::uint32 priority, td::Timestamp timeout,
262-
td::Promise<td::BufferSlice> promise) override {
263-
}
264-
void download_block_proof_link(ton::BlockIdExt block_id, td::uint32 priority, td::Timestamp timeout,
265-
td::Promise<td::BufferSlice> promise) override {
266-
}
267-
void get_next_key_blocks(ton::BlockIdExt block_id, td::Timestamp timeout,
268-
td::Promise<std::vector<ton::BlockIdExt>> promise) override {
269-
}
270-
void download_archive(ton::BlockSeqno masterchain_seqno, ton::ShardIdFull shard_prefix, std::string tmp_dir,
271-
td::Timestamp timeout, td::Promise<std::string> promise) override {
272-
}
273-
void download_out_msg_queue_proof(
274-
ton::ShardIdFull dst_shard, std::vector<ton::BlockIdExt> blocks, block::ImportedMsgQueueLimits limits,
275-
td::Timestamp timeout, td::Promise<std::vector<td::Ref<ton::validator::OutMsgQueueProof>>> promise) override {
276-
}
277-
278-
void new_key_block(ton::validator::BlockHandle handle) override {
279-
}
280237
};
281238

282239
td::actor::send_closure(validator_manager_, &ton::validator::ValidatorManagerInterface::install_callback,

crypto/block/transaction.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3496,6 +3496,9 @@ bool Transaction::compute_state(const SerializeConfig& cfg) {
34963496
if (frozen_hash == account.addr_orig) {
34973497
// if frozen_hash equals account's "original" address (before rewriting), do not need storing hash
34983498
CHECK(cb.store_long_bool(0, 2)); // account_uninit$00 = AccountState
3499+
if (cfg.global_version >= 13) {
3500+
acc_status = Account::acc_uninit;
3501+
}
34993502
} else {
35003503
CHECK(cb.store_long_bool(1, 2) // account_frozen$01
35013504
&& cb.store_bits_bool(frozen_hash)); // state_hash:bits256
@@ -4238,6 +4241,7 @@ td::Status FetchConfigParams::fetch_config_params(
42384241
action_phase_cfg->global_version = config.get_global_version();
42394242
}
42404243
{
4244+
serialize_cfg->global_version = config.get_global_version();
42414245
serialize_cfg->extra_currency_v2 = config.get_global_version() >= 10;
42424246
serialize_cfg->disable_anycast = config.get_global_version() >= 10;
42434247
serialize_cfg->store_storage_dict_hash = config.get_global_version() >= 11;

crypto/block/transaction.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ struct ActionPhaseConfig {
186186
};
187187

188188
struct SerializeConfig {
189+
int global_version = 0;
189190
bool extra_currency_v2{false};
190191
bool disable_anycast{false};
191192
bool store_storage_dict_hash{false};

crypto/common/refint.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,12 @@ RefInt256 zero_refint() {
267267
return td::RefInt256{true, 0};
268268
}
269269

270+
RefInt256 nan_refint() {
271+
RefInt256 x{true};
272+
x.unique_write().invalidate();
273+
return x;
274+
}
275+
270276
RefInt256 bits_to_refint(td::ConstBitPtr bits, int n, bool sgnd) {
271277
td::RefInt256 x{true};
272278
x.unique_write().import_bits(bits, n, sgnd);

crypto/common/refint.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ RefInt256 make_refint(Args&&... args) {
115115
}
116116

117117
extern RefInt256 zero_refint();
118+
extern RefInt256 nan_refint();
118119
extern RefInt256 bits_to_refint(td::ConstBitPtr bits, int n, bool sgnd = false);
119120

120121
extern std::string dec_string(RefInt256 x);

crypto/vm/arithops.cpp

Lines changed: 97 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ int exec_divmod(VmState* st, unsigned args, int quiet) {
283283
auto x = stack.pop_int();
284284
if (add) {
285285
CHECK(d == 3);
286-
typename td::BigInt256::DoubleInt tmp{*x}, quot;
286+
td::BigInt256::DoubleInt tmp{*x}, quot;
287287
tmp += *w;
288288
tmp.mod_div(*y, quot, round_mode);
289289
auto q = td::make_refint(quot), r = td::make_refint(tmp);
@@ -365,9 +365,9 @@ int exec_shrmod(VmState* st, unsigned args, int mode) {
365365
auto x = stack.pop_int();
366366
if (add) {
367367
CHECK(d == 3);
368-
typename td::BigInt256::DoubleInt tmp{*x}, quot;
368+
td::BigInt256::DoubleInt tmp{*x};
369369
tmp += *w;
370-
typename td::BigInt256::DoubleInt tmp2{tmp};
370+
td::BigInt256::DoubleInt tmp2{tmp};
371371
tmp2.rshift(y, round_mode).normalize();
372372
stack.push_int_quiet(td::make_refint(tmp2), mode & 1);
373373
tmp.normalize().mod_pow2(y, round_mode).normalize();
@@ -450,7 +450,7 @@ int exec_muldivmod(VmState* st, unsigned args, int quiet) {
450450
auto w = add ? stack.pop_int() : td::RefInt256{};
451451
auto y = stack.pop_int();
452452
auto x = stack.pop_int();
453-
typename td::BigInt256::DoubleInt tmp{0}, quot;
453+
td::BigInt256::DoubleInt tmp{0}, quot;
454454
if (add) {
455455
tmp = *w;
456456
}
@@ -496,8 +496,9 @@ std::string dump_muldivmod(CellSlice&, unsigned args, bool quiet) {
496496
}
497497

498498
int exec_mulshrmod(VmState* st, unsigned args, int mode) {
499-
int z = -1;
500-
if (mode & 2) {
499+
bool quiet = mode & 1, z_in_args = mode & 2;
500+
long long z = -1;
501+
if (z_in_args) {
501502
z = (args & 0xff) + 1;
502503
args >>= 8;
503504
}
@@ -513,9 +514,12 @@ int exec_mulshrmod(VmState* st, unsigned args, int mode) {
513514
}
514515
Stack& stack = st->get_stack();
515516
VM_LOG(st) << "execute MULSHR/MOD " << (args & 15) << ',' << z;
516-
if (!(mode & 2)) {
517+
if (!z_in_args) {
517518
stack.check_underflow(add ? 4 : 3);
518-
z = stack.pop_smallint_range(256);
519+
z = stack.pop_long();
520+
if ((st->get_global_version() < 13 || !quiet) && (z < 0 || z > 256)) {
521+
throw VmError{Excno::range_chk};
522+
}
519523
} else {
520524
stack.check_underflow(add ? 3 : 2);
521525
}
@@ -525,26 +529,37 @@ int exec_mulshrmod(VmState* st, unsigned args, int mode) {
525529
auto w = add ? stack.pop_int() : td::RefInt256{};
526530
auto y = stack.pop_int();
527531
auto x = stack.pop_int();
528-
typename td::BigInt256::DoubleInt tmp{0};
532+
if (st->get_global_version() >= 13) {
533+
if (!x->is_valid() || !y->is_valid() || (w.not_null() && !w->is_valid()) || z < 0 || z > 256) {
534+
stack.push_int_quiet(td::nan_refint(), quiet);
535+
if (d == 3) {
536+
stack.push_int_quiet(td::nan_refint(), quiet);
537+
}
538+
return 0;
539+
}
540+
}
541+
td::BigInt256::DoubleInt tmp{0};
529542
if (add) {
530543
tmp = *w;
531544
}
532545
tmp.add_mul(*x, *y).normalize();
533546
switch (d) {
534547
case 1:
535-
tmp.rshift(z, round_mode).normalize();
536-
stack.push_int_quiet(td::make_refint(tmp), mode & 1);
548+
tmp.rshift((int)z, round_mode).normalize();
549+
stack.push_int_quiet(td::make_refint(tmp), quiet);
537550
break;
538551
case 3: {
539-
typename td::BigInt256::DoubleInt tmp2{tmp};
540-
tmp2.rshift(z, round_mode).normalize();
541-
stack.push_int_quiet(td::make_refint(tmp2), mode & 1);
552+
td::BigInt256::DoubleInt tmp2{tmp};
553+
tmp2.rshift((int)z, round_mode).normalize();
554+
stack.push_int_quiet(td::make_refint(tmp2), quiet);
542555
}
543556
// fallthrough
544557
case 2:
545-
tmp.normalize().mod_pow2(z, round_mode).normalize();
546-
stack.push_int_quiet(td::make_refint(tmp), mode & 1);
558+
tmp.normalize().mod_pow2((int)z, round_mode).normalize();
559+
stack.push_int_quiet(td::make_refint(tmp), quiet);
547560
break;
561+
default:
562+
UNREACHABLE();
548563
}
549564
return 0;
550565
}
@@ -594,8 +609,9 @@ std::string dump_mulshrmod(CellSlice&, unsigned args, int mode) {
594609
}
595610

596611
int exec_shldivmod(VmState* st, unsigned args, int mode) {
597-
int y = -1;
598-
if (mode & 2) {
612+
bool quiet = mode & 1, y_in_args = mode & 2;
613+
long y = -1;
614+
if (y_in_args) {
599615
y = (args & 0xff) + 1;
600616
args >>= 8;
601617
}
@@ -611,38 +627,52 @@ int exec_shldivmod(VmState* st, unsigned args, int mode) {
611627
}
612628
Stack& stack = st->get_stack();
613629
VM_LOG(st) << "execute SHLDIV/MOD " << (args & 15) << ',' << y;
614-
if (!(mode & 2)) {
630+
if (!y_in_args) {
615631
stack.check_underflow(add ? 4 : 3);
616-
y = stack.pop_smallint_range(256);
632+
y = stack.pop_long();
633+
if ((st->get_global_version() < 13 || !quiet) && (y < 0 || y > 256)) {
634+
throw VmError{Excno::range_chk};
635+
}
617636
} else {
618637
stack.check_underflow(add ? 3 : 2);
619638
}
620639
auto z = stack.pop_int();
621640
auto w = add ? stack.pop_int() : td::RefInt256{};
622641
auto x = stack.pop_int();
623-
typename td::BigInt256::DoubleInt tmp{*x}, quot;
624-
tmp <<= y;
642+
if (st->get_global_version() >= 13) {
643+
if (!z->is_valid() || !x->is_valid() || (w.not_null() && !w->is_valid()) || y < 0 || y > 256) {
644+
stack.push_int_quiet(td::nan_refint(), quiet);
645+
if (d == 3) {
646+
stack.push_int_quiet(td::nan_refint(), quiet);
647+
}
648+
return 0;
649+
}
650+
}
651+
td::BigInt256::DoubleInt tmp{*x}, quot;
652+
tmp <<= (int)y;
625653
if (add) {
626654
tmp += *w;
627655
}
628656
switch (d) {
629657
case 1: {
630658
tmp.mod_div(*z, quot, round_mode);
631-
stack.push_int_quiet(td::make_refint(quot.normalize()), mode & 1);
659+
stack.push_int_quiet(td::make_refint(quot.normalize()), quiet);
632660
break;
633661
}
634662
case 3: {
635663
tmp.mod_div(*z, quot, round_mode);
636-
stack.push_int_quiet(td::make_refint(quot.normalize()), mode & 1);
637-
stack.push_int_quiet(td::make_refint(tmp), mode & 1);
664+
stack.push_int_quiet(td::make_refint(quot.normalize()), quiet);
665+
stack.push_int_quiet(td::make_refint(tmp), quiet);
638666
break;
639667
}
640668
case 2: {
641-
typename td::BigInt256::DoubleInt tmp2;
669+
td::BigInt256::DoubleInt tmp2;
642670
tmp.mod_div(*z, tmp2, round_mode);
643-
stack.push_int_quiet(td::make_refint(tmp), mode & 1);
671+
stack.push_int_quiet(td::make_refint(tmp), quiet);
644672
break;
645673
}
674+
default:
675+
UNREACHABLE();
646676
}
647677
return 0;
648678
}
@@ -742,17 +772,37 @@ int exec_lshift(VmState* st, bool quiet) {
742772
Stack& stack = st->get_stack();
743773
VM_LOG(st) << "execute LSHIFT";
744774
stack.check_underflow(2);
745-
int x = stack.pop_smallint_range(1023);
746-
stack.push_int_quiet(stack.pop_int() << x, quiet);
775+
long long shift = stack.pop_long();
776+
if ((st->get_global_version() < 13 || !quiet) && (shift < 0 || shift > 1023)) {
777+
throw VmError{Excno::range_chk};
778+
}
779+
auto a = stack.pop_int();
780+
td::RefInt256 result;
781+
if (st->get_global_version() >= 13 && (shift < 0 || shift > 1023 || !a->is_valid())) {
782+
result = td::nan_refint();
783+
} else {
784+
result = std::move(a) << (int)shift;
785+
}
786+
stack.push_int_quiet(std::move(result), quiet);
747787
return 0;
748788
}
749789

750790
int exec_rshift(VmState* st, bool quiet) {
751791
Stack& stack = st->get_stack();
752792
VM_LOG(st) << "execute RSHIFT";
753793
stack.check_underflow(2);
754-
int x = stack.pop_smallint_range(1023);
755-
stack.push_int_quiet(stack.pop_int() >> x, quiet);
794+
long long shift = stack.pop_long();
795+
if ((st->get_global_version() < 13 || !quiet) && (shift < 0 || shift > 1023)) {
796+
throw VmError{Excno::range_chk};
797+
}
798+
auto a = stack.pop_int();
799+
td::RefInt256 result;
800+
if (st->get_global_version() >= 13 && (shift < 0 || shift > 1023 || !a->is_valid())) {
801+
result = td::nan_refint();
802+
} else {
803+
result = std::move(a) >> (int)shift;
804+
}
805+
stack.push_int_quiet(std::move(result), quiet);
756806
return 0;
757807
}
758808

@@ -772,7 +822,14 @@ int exec_and(VmState* st, bool quiet) {
772822
VM_LOG(st) << "execute AND";
773823
stack.check_underflow(2);
774824
auto y = stack.pop_int();
775-
stack.push_int_quiet(stack.pop_int() & std::move(y), quiet);
825+
auto x = stack.pop_int();
826+
td::RefInt256 result;
827+
if (st->get_global_version() >= 13 && (!x->is_valid() || !y->is_valid())) {
828+
result = td::nan_refint();
829+
} else {
830+
result = std::move(x) & std::move(y);
831+
}
832+
stack.push_int_quiet(std::move(result), quiet);
776833
return 0;
777834
}
778835

@@ -781,7 +838,14 @@ int exec_or(VmState* st, bool quiet) {
781838
VM_LOG(st) << "execute OR";
782839
stack.check_underflow(2);
783840
auto y = stack.pop_int();
784-
stack.push_int_quiet(stack.pop_int() | std::move(y), quiet);
841+
auto x = stack.pop_int();
842+
td::RefInt256 result;
843+
if (st->get_global_version() >= 13 && (!x->is_valid() || !y->is_valid())) {
844+
result = td::nan_refint();
845+
} else {
846+
result = std::move(x) | std::move(y);
847+
}
848+
stack.push_int_quiet(std::move(result), quiet);
785849
return 0;
786850
}
787851

doc/GlobalVersions.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,4 +285,12 @@ The bounced message has the same 0th and 1st bits in `extra_flags` as the origin
285285

286286
### Other changes
287287
- Account size in masterchain is now limited to `2048` cells. This can be configured in size limits config (`ConfigParam 43`).
288-
- The previous limit was the same as in basechain (`65536`).
288+
- The previous limit was the same as in basechain (`65536`).
289+
290+
## Version 13
291+
292+
### TVM changes
293+
- Instructions `LSHIFT`, `RSHIFT`, `LSHIFTDIV`, `MULRSHIFT`, `AND`, `OR` now correctly return an error (or `NaN`, if quiet) when one of the arguments is `NaN` (or out of bounds for shifts).
294+
295+
### Transaction changes
296+
- `end_status` of a transaction is now correctly set to `uninit` when the account is frozen with `frozen_hash` equal to its address.

0 commit comments

Comments
 (0)