From 0f6cf13d45ce45a6ee011caa81020d542ff1b833 Mon Sep 17 00:00:00 2001 From: Ivan Kalinin Date: Fri, 24 Jan 2025 15:41:43 +0100 Subject: [PATCH 1/2] fix(vm): fix saving `ret` on deep jump (#1487) --- crypto/vm/vm.cpp | 9 +++++++-- crypto/vm/vm.h | 9 +++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/crypto/vm/vm.cpp b/crypto/vm/vm.cpp index 77d5d8f80..3c1118c60 100644 --- a/crypto/vm/vm.cpp +++ b/crypto/vm/vm.cpp @@ -247,6 +247,11 @@ int VmState::jump(Ref cont) { // general jump to continuation cont int VmState::jump(Ref cont, int pass_args) { + cont = adjust_jump_cont(std::move(cont), pass_args); + return jump_to(std::move(cont)); +} + +Ref VmState::adjust_jump_cont(Ref cont, int pass_args) { const ControlData* cont_data = cont->get_cdata(); if (cont_data) { // first do the checks @@ -287,7 +292,7 @@ int VmState::jump(Ref cont, int pass_args) { consume_stack_gas(copy); } } - return jump_to(std::move(cont)); + return cont; } else { // have no continuation data, situation is somewhat simpler if (pass_args >= 0) { @@ -299,7 +304,7 @@ int VmState::jump(Ref cont, int pass_args) { consume_stack_gas(pass_args); } } - return jump_to(std::move(cont)); + return cont; } } diff --git a/crypto/vm/vm.h b/crypto/vm/vm.h index 04c5e576c..7aaf1e911 100644 --- a/crypto/vm/vm.h +++ b/crypto/vm/vm.h @@ -347,6 +347,7 @@ class VmState final : public VmStateInterface { int call(Ref cont, int pass_args, int ret_args = -1); int jump(Ref cont); int jump(Ref cont, int pass_args); + Ref adjust_jump_cont(Ref cont, int pass_args); int ret(); int ret(int ret_args); int ret_alt(); @@ -374,6 +375,14 @@ class VmState final : public VmStateInterface { if (cnt > free_nested_cont_jump && global_version >= 9) { consume_gas(1); } + + if (cont.not_null()) { + const ControlData* cont_data = cont->get_cdata(); + if (cont_data && (cont_data->stack.not_null() || cont_data->nargs >= 0)) { + // if cont has non-empty stack or expects fixed number of arguments, jump is not simple + cont = adjust_jump_cont(std::move(cont), -1); + } + } } return res; } From da5644e758ff5f0bff504636dd20e1f8f6e257d6 Mon Sep 17 00:00:00 2001 From: SpyCheese Date: Fri, 24 Jan 2025 14:48:05 +0000 Subject: [PATCH 2/2] Enable VmState::jump_to bugfix in version 9 (#1491) --- crypto/block/transaction.cpp | 2 +- crypto/vm/vm.h | 3 +-- doc/GlobalVersions.md | 3 ++- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crypto/block/transaction.cpp b/crypto/block/transaction.cpp index 92e20fb0b..63e9065b6 100644 --- a/crypto/block/transaction.cpp +++ b/crypto/block/transaction.cpp @@ -1156,7 +1156,7 @@ namespace transaction { * It is activated by setting global version to 5 in ConfigParam 8. * This config change also activates new behavior for special accounts in masterchain. * - * In Augost 2024 it was decided to unlock other old highload wallets that got into the same situation. + * In August 2024 it was decided to unlock other old highload wallets that got into the same situation. * See https://t.me/tondev_news/129 * It is activated by setting global version to 9. * diff --git a/crypto/vm/vm.h b/crypto/vm/vm.h index 7aaf1e911..a171ef27e 100644 --- a/crypto/vm/vm.h +++ b/crypto/vm/vm.h @@ -375,8 +375,7 @@ class VmState final : public VmStateInterface { if (cnt > free_nested_cont_jump && global_version >= 9) { consume_gas(1); } - - if (cont.not_null()) { + if (cont.not_null() && global_version >= 9) { const ControlData* cont_data = cont->get_cdata(); if (cont_data && (cont_data->stack.not_null() || cont_data->nargs >= 0)) { // if cont has non-empty stack or expects fixed number of arguments, jump is not simple diff --git a/doc/GlobalVersions.md b/doc/GlobalVersions.md index 3849072f4..f4156ca07 100644 --- a/doc/GlobalVersions.md +++ b/doc/GlobalVersions.md @@ -133,4 +133,5 @@ Example: if the last masterchain block seqno is `19071` then the list contains b - Fix exception code in some TVM instructions: now `stk_und` has priority over other error codes. - `PFXDICTADD`, `PFXDICTSET`, `PFXDICTREPLACE`, `PFXDICTDEL`, `GETGASFEE`, `GETSTORAGEFEE`, `GETFORWARDFEE`, `GETORIGINALFWDFEE`, `GETGASFEESIMPLE`, `GETFORWARDFEESIMPLE`, `HASHEXT` - Now setting the contract code to a library cell does not consume additional gas on execution of the code. -- Temporary increase gas limit for some accounts (see [this post](https://t.me/tondev_news/129) for details, `override_gas_limit` in `transaction.cpp` for the list of accounts). \ No newline at end of file +- Temporary increase gas limit for some accounts (see [this post](https://t.me/tondev_news/129) for details, `override_gas_limit` in `transaction.cpp` for the list of accounts). +- Fix recursive jump to continuations with non-null control data. \ No newline at end of file