Skip to content

Commit 07f2565

Browse files
committed
HASHBU opcode
1 parent a969178 commit 07f2565

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

crypto/fift/lib/Asm.fif

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,6 +1391,7 @@ x{F912} @Defop ECRECOVER
13911391
x{F913} @Defop SECP256K1_XONLY_PUBKEY_TWEAK_ADD
13921392
x{F914} @Defop P256_CHKSIGNU
13931393
x{F915} @Defop P256_CHKSIGNS
1394+
x{F916} @Defop HASHBU
13941395

13951396
x{F920} @Defop RIST255_FROMHASH
13961397
x{F921} @Defop RIST255_VALIDATE

crypto/vm/tonops.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -610,13 +610,13 @@ void register_prng_ops(OpcodeTable& cp0) {
610610
}
611611

612612
int exec_compute_hash(VmState* st, int mode) {
613-
VM_LOG(st) << "execute HASH" << (mode & 1 ? 'S' : 'C') << 'U';
613+
VM_LOG(st) << "execute HASH" << "CSB"[mode] << 'U';
614614
Stack& stack = st->get_stack();
615615
std::array<unsigned char, 32> hash;
616-
if (!(mode & 1)) {
616+
if (mode == 0) { // cell
617617
auto cell = stack.pop_cell();
618618
hash = cell->get_hash().as_array();
619-
} else {
619+
} else if (mode == 1) { // slice
620620
auto cs = stack.pop_cellslice();
621621
CellBuilder cb;
622622
CHECK(cb.append_cellslice_bool(std::move(cs)));
@@ -625,6 +625,9 @@ int exec_compute_hash(VmState* st, int mode) {
625625
} else {
626626
hash = cb.finalize()->get_hash().as_array();
627627
}
628+
} else { // builder
629+
auto cb = stack.pop_builder();
630+
hash = cb.write().finalize_novm()->get_hash().as_array();
628631
}
629632
td::RefInt256 res{true};
630633
CHECK(res.write().import_bytes(hash.data(), hash.size(), false));
@@ -1368,6 +1371,7 @@ void register_ton_crypto_ops(OpcodeTable& cp0) {
13681371
.insert(OpcodeInstr::mksimple(0xf913, 16, "SECP256K1_XONLY_PUBKEY_TWEAK_ADD", exec_secp256k1_xonly_pubkey_tweak_add)->require_version(9))
13691372
.insert(OpcodeInstr::mksimple(0xf914, 16, "P256_CHKSIGNU", std::bind(exec_p256_chksign, _1, false))->require_version(4))
13701373
.insert(OpcodeInstr::mksimple(0xf915, 16, "P256_CHKSIGNS", std::bind(exec_p256_chksign, _1, true))->require_version(4))
1374+
.insert(OpcodeInstr::mksimple(0xf916, 16, "HASHBU", std::bind(exec_compute_hash, _1, 2))->require_version(12))
13711375

13721376
.insert(OpcodeInstr::mksimple(0xf920, 16, "RIST255_FROMHASH", exec_ristretto255_from_hash)->require_version(4))
13731377
.insert(OpcodeInstr::mksimple(0xf921, 16, "RIST255_VALIDATE", std::bind(exec_ristretto255_validate, _1, false))->require_version(4))

doc/GlobalVersions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ This is required to help computing storage stats in the future, after collator-v
233233

234234
### New TVM instructions
235235
- `BTOS` (`b - s`) - same as `ENDC CTOS`, but without gas cost for cell creation and loading. Gas cost: `26`.
236+
- `HASHBU` (`b - hash`) - same as `ENDC HASHCU`, but without gas cost for cell creation. Gas cost: `26`.
236237

237238
### Other TVM changes
238239
- `HASHSU` (`s - hash`) now does not spend gas for cell creation. Gas cost: `26`.

0 commit comments

Comments
 (0)