1
0
Fork 0
mirror of https://github.com/ton-blockchain/ton synced 2025-03-09 15:40:10 +00:00

vm: bugfixes

This commit is contained in:
ton 2020-03-02 17:52:55 +04:00
parent 27aaa11524
commit ba76f1404e
30 changed files with 396 additions and 178 deletions

View file

@ -344,11 +344,11 @@ unsigned long long VarUIntegerPos::as_uint(const vm::CellSlice& cs) const {
bool VarUIntegerPos::store_integer_value(vm::CellBuilder& cb, const td::BigInt256& value) const {
int k = value.bit_size(false);
return k <= (n - 1) * 8 && value.sgn() > 0 && cb.store_long_bool((k + 7) >> 3, ln) &&
return k <= (n - 1) * 8 && value.sgn() >= (int)store_pos_only && cb.store_long_bool((k + 7) >> 3, ln) &&
cb.store_int256_bool(value, (k + 7) & -8, false);
}
const VarUIntegerPos t_VarUIntegerPos_16{16}, t_VarUIntegerPos_32{32};
const VarUIntegerPos t_VarUIntegerPos_16{16}, t_VarUIntegerPos_32{32}, t_VarUIntegerPosRelaxed_32{32, true};
static inline bool redundant_int(const vm::CellSlice& cs) {
int t = (int)cs.prefetch_long(9);

View file

@ -77,7 +77,8 @@ extern const VarUInteger t_VarUInteger_3, t_VarUInteger_7, t_VarUInteger_16, t_V
struct VarUIntegerPos final : TLB_Complex {
int n, ln;
VarUIntegerPos(int _n) : n(_n) {
bool store_pos_only;
VarUIntegerPos(int _n, bool relaxed = false) : n(_n), store_pos_only(!relaxed) {
ln = 32 - td::count_leading_zeroes32(n - 1);
}
bool skip(vm::CellSlice& cs) const override;
@ -90,7 +91,7 @@ struct VarUIntegerPos final : TLB_Complex {
}
};
extern const VarUIntegerPos t_VarUIntegerPos_16, t_VarUIntegerPos_32;
extern const VarUIntegerPos t_VarUIntegerPos_16, t_VarUIntegerPos_32, t_VarUIntegerPosRelaxed_32;
struct VarInteger final : TLB_Complex {
int n, ln;
@ -325,7 +326,7 @@ extern const MsgAddress t_MsgAddress;
struct ExtraCurrencyCollection final : TLB {
HashmapE dict_type, dict_type2;
ExtraCurrencyCollection() : dict_type(32, t_VarUIntegerPos_32), dict_type2(32, t_VarUInteger_32) {
ExtraCurrencyCollection() : dict_type(32, t_VarUIntegerPos_32), dict_type2(32, t_VarUIntegerPosRelaxed_32) {
}
int get_size(const vm::CellSlice& cs) const override {
return dict_type.get_size(cs);

View file

@ -724,7 +724,12 @@ void interpret_tlb_validate_skip(vm::Stack& stack) {
stack.push_bool(ok);
}
void interpret_tlb_type_const(vm::Stack& stack, const tlb::TLB* ptr) {
stack.push_make_object<tlb::TlbTypeHolder>(ptr);
}
void init_words_tlb(fift::Dictionary& d) {
using namespace std::placeholders;
tlb_dict.register_types(block::gen::register_simple_types);
d.def_stack_word("tlb-type-lookup ", interpret_tlb_type_lookup);
d.def_stack_word("tlb-type-name ", interpret_tlb_type_name);
@ -733,6 +738,7 @@ void init_words_tlb(fift::Dictionary& d) {
d.def_stack_word("(tlb-dump-str?) ", interpret_tlb_dump_to_str);
d.def_stack_word("tlb-skip ", interpret_tlb_skip);
d.def_stack_word("tlb-validate-skip ", interpret_tlb_validate_skip);
d.def_stack_word("ExtraCurrencyCollection", std::bind(interpret_tlb_type_const, _1, &block::tlb::t_ExtraCurrencyCollection));
}
void usage(const char* progname) {