Skip to content

Commit a969178

Browse files
committed
BTOS opcode; decrease gas usage for HASHSU
1 parent a89cafb commit a969178

File tree

5 files changed

+29
-5
lines changed

5 files changed

+29
-5
lines changed

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 = 11;
22+
constexpr int SUPPORTED_VERSION = 12;
2323

2424
}

crypto/fift/lib/Asm.fif

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,7 @@ x{CF3F} @Defop BCHKBITREFSQ
697697
x{CF40} @Defop STZEROES
698698
x{CF41} @Defop STONES
699699
x{CF42} @Defop STSAME
700+
x{CF50} @Defop BTOS
700701
{ tuck sbitrefs swap 22 + swap @havebitrefs not
701702
{ swap PUSHSLICE STSLICER }
702703
{ over sbitrefs 2dup 57 3 2x<=

crypto/vm/cellops.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,15 @@ int exec_store_same(VmState* st, const char* name, int val) {
764764
return 0;
765765
}
766766

767+
int exec_builder_to_slice(VmState* st) {
768+
Stack& stack = st->get_stack();
769+
VM_LOG(st) << "execute BTOS";
770+
stack.check_underflow(1);
771+
Ref<Cell> cell = stack.pop_builder().write().finalize_novm();
772+
stack.push_cellslice(Ref<CellSlice>{true, NoVm(), cell});
773+
return 0;
774+
}
775+
767776
int exec_store_const_slice(VmState* st, CellSlice& cs, unsigned args, int pfx_bits) {
768777
unsigned refs = (args >> 3) & 3;
769778
unsigned data_bits = (args & 7) * 8 + 2;
@@ -866,6 +875,7 @@ void register_cell_serialize_ops(OpcodeTable& cp0) {
866875
.insert(OpcodeInstr::mksimple(0xcf40, 16, "STZEROES", std::bind(exec_store_same, _1, "STZEROES", 0)))
867876
.insert(OpcodeInstr::mksimple(0xcf41, 16, "STONES", std::bind(exec_store_same, _1, "STONES", 1)))
868877
.insert(OpcodeInstr::mksimple(0xcf42, 16, "STSAME", std::bind(exec_store_same, _1, "STSAME", -1)))
878+
.insert(OpcodeInstr::mksimple(0xcf50, 16, "BTOS", exec_builder_to_slice)->require_version(12))
869879
.insert(OpcodeInstr::mkext(0xcf80 >> 7, 9, 5, dump_store_const_slice, exec_store_const_slice,
870880
compute_len_store_const_slice));
871881
}

crypto/vm/tonops.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -618,10 +618,13 @@ int exec_compute_hash(VmState* st, int mode) {
618618
hash = cell->get_hash().as_array();
619619
} else {
620620
auto cs = stack.pop_cellslice();
621-
vm::CellBuilder cb;
621+
CellBuilder cb;
622622
CHECK(cb.append_cellslice_bool(std::move(cs)));
623-
// TODO: use cb.get_hash() instead
624-
hash = cb.finalize()->get_hash().as_array();
623+
if (st->get_global_version() >= 12) {
624+
hash = cb.finalize_novm()->get_hash().as_array();
625+
} else {
626+
hash = cb.finalize()->get_hash().as_array();
627+
}
625628
}
626629
td::RefInt256 res{true};
627630
CHECK(res.write().import_bytes(hash.data(), hash.size(), false));

doc/GlobalVersions.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ Example: if the last masterchain block seqno is `19071` then the list contains b
144144
- Fix recursive jump to continuations with non-null control data.
145145

146146
## Version 10
147+
__Enabled in mainnet on 2025-05-07__
147148

148149
### Extra currencies
149150
- Internal messages cannot carry more than 2 different extra currencies. The limit can be changed in size limits config (`ConfigParam 43`).
@@ -194,6 +195,7 @@ Reserve modes `+1`, `+4` and `+8` ("reserve all except", "add original balance"
194195
- Exceeding state limits in transaction now reverts `end_lt` back to `start_lt + 1` and collects action fines.
195196

196197
## Version 11
198+
__Enabled in mainnet on 2025-07-05__
197199

198200
### c7 tuple
199201
**c7** tuple extended from 17 to 18 elements:
@@ -225,4 +227,12 @@ This is required to help computing storage stats in the future, after collator-v
225227

226228
### Other changes
227229
- Fix returning `null` as `c4` and `c5` (when VM state is not committed) in `RUNVM`.
228-
- In new internal messages `ihr_disabled` is automatically set to `1`, `ihr_fee` is always zero.
230+
- In new internal messages `ihr_disabled` is automatically set to `1`, `ihr_fee` is always zero.
231+
232+
## Version 12
233+
234+
### New TVM instructions
235+
- `BTOS` (`b - s`) - same as `ENDC CTOS`, but without gas cost for cell creation and loading. Gas cost: `26`.
236+
237+
### Other TVM changes
238+
- `HASHSU` (`s - hash`) now does not spend gas for cell creation. Gas cost: `26`.

0 commit comments

Comments
 (0)