mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
validator: multiple bugfixes
This commit is contained in:
parent
7efb345e3d
commit
dfc040cb00
17 changed files with 255 additions and 65 deletions
|
@ -151,6 +151,9 @@ message$_ {X:Type} info:CommonMsgInfo
|
|||
message$_ {X:Type} info:CommonMsgInfoRelaxed
|
||||
init:(Maybe (Either StateInit ^StateInit))
|
||||
body:(Either X ^X) = MessageRelaxed X;
|
||||
|
||||
_ (Message Any) = MessageAny;
|
||||
|
||||
//
|
||||
interm_addr_regular$0 use_dest_bits:(#<= 96)
|
||||
= IntermediateAddress;
|
||||
|
|
112
crypto/smartcont/highload-wallet-v2-one.fif
Normal file
112
crypto/smartcont/highload-wallet-v2-one.fif
Normal file
|
@ -0,0 +1,112 @@
|
|||
#!/usr/bin/fift -s
|
||||
"TonUtil.fif" include
|
||||
"GetOpt.fif" include
|
||||
|
||||
{ show-options-help 1 halt } : usage
|
||||
|
||||
"" =: comment // comment for simple transfers
|
||||
true =: allow-bounce
|
||||
false =: force-bounce
|
||||
3 =: send-mode // mode for SENDRAWMSG: +1 - sender pays fees, +2 - ignore errors
|
||||
60 =: timeout // external message expires in 60 seconds
|
||||
variable extra-currencies
|
||||
{ extra-currencies @ cc+ extra-currencies ! } : extra-cc+!
|
||||
|
||||
begin-options
|
||||
" <filename-base> <dest-addr> <subwallet-id> <amount> [-x <extra-amount>*<extra-currency-id>] [-n|-b] [-t<timeout>] [-B <body-boc>] [-C <comment>] [<savefile>]" +cr +tab
|
||||
+"Creates one request to highload wallet created by new-highload-wallet-v2.fif, with private key loaded from file <filename-base>.pk "
|
||||
+"and address from <filename-base><subwallet-id>.addr, and saves it into <savefile>.boc ('wallet-query.boc' by default)"
|
||||
disable-digit-options generic-help-setopt
|
||||
"n" "--no-bounce" { false =: allow-bounce } short-long-option
|
||||
"Clears bounce flag" option-help
|
||||
"b" "--force-bounce" { true =: force-bounce } short-long-option
|
||||
"Forces bounce flag" option-help
|
||||
"x" "--extra" { $>xcc extra-cc+! } short-long-option-arg
|
||||
"Indicates the amount of extra currencies to be transfered" option-help
|
||||
"t" "--timeout" { parse-int =: timeout } short-long-option-arg
|
||||
"Sets expiration timeout in seconds (" timeout (.) $+ +" by default)" option-help
|
||||
"B" "--body" { =: body-boc-file } short-long-option-arg
|
||||
"Sets the payload of the transfer message" option-help
|
||||
"C" "--comment" { =: comment } short-long-option-arg
|
||||
"Sets the comment to be sent in the transfer message" option-help
|
||||
"m" "--mode" { parse-int =: send-mode } short-long-option-arg
|
||||
"Sets transfer mode (0..255) for SENDRAWMSG (" send-mode (.) $+ +" by default)"
|
||||
option-help
|
||||
"h" "--help" { usage } short-long-option
|
||||
"Shows a help message" option-help
|
||||
parse-options
|
||||
|
||||
$# dup 4 < swap 5 > or ' usage if
|
||||
5 :$1..n
|
||||
|
||||
true constant bounce
|
||||
$1 =: file-base
|
||||
$2 bounce parse-load-address force-bounce or allow-bounce and =: bounce 2=: dest_addr
|
||||
$3 parse-int =: subwallet-id
|
||||
$4 $>cc extra-cc+! extra-currencies @ 2=: amount
|
||||
$5 "wallet-query" replace-if-null =: savefile
|
||||
{ subwallet-id (.) $+ } : +subwallet
|
||||
|
||||
file-base +subwallet +".addr" load-address
|
||||
2dup 2constant wallet_addr
|
||||
."Source wallet address = " 2dup .addr cr 6 .Addr cr
|
||||
file-base +".pk" load-keypair nip constant wallet_pk
|
||||
|
||||
def? body-boc-file { @' body-boc-file file>B B>boc } { comment simple-transfer-body } cond
|
||||
constant body-cell
|
||||
|
||||
."Transferring " amount .GR+cc ."to account "
|
||||
dest_addr 2dup bounce 7 + .Addr ." = " .addr
|
||||
."subwallet-id=0x" subwallet-id x.
|
||||
."timeout=" timeout . ."bounce=" bounce . cr
|
||||
."Body of transfer message is " body-cell <s csr. cr
|
||||
|
||||
variable orders dictnew orders !
|
||||
variable order# order# 0!
|
||||
// c --
|
||||
{ <s order# @ dup 254 >= abort"more than 254 orders"
|
||||
orders @ 16 udict!+ not abort"cannot add order to dictionary"
|
||||
orders ! order# 1+!
|
||||
} : add-order
|
||||
// b body -- b'
|
||||
{ tuck <s 2dup 1 s-fits-with? not rot over 1 i, -rot
|
||||
{ drop swap ref, } { s, nip } cond
|
||||
} : append-msg-body
|
||||
// ng wc addr bounce body -- c
|
||||
{ <b b{01} s, rot 1 i, b{000100} s, 2swap addr, rot Gram,
|
||||
0 9 64 32 + + 1+ u, swap append-msg-body b>
|
||||
} : create-int-msg
|
||||
// ng wc addr bnc --
|
||||
{ ."Transferring " 3 roll .GR ."to account "
|
||||
-rot 2dup 4 pick 7 + .Addr ." = " .addr ." bounce=" . cr
|
||||
} : .transfer
|
||||
// addr$ ng -- c
|
||||
{ swap parse-smc-addr force-bounce or allow-bounce and // ng wc addr bnc
|
||||
2over 2over .transfer
|
||||
<b 0 32 u, b> create-int-msg
|
||||
} : create-simple-transfer
|
||||
// c m -- c'
|
||||
{ <b swap 8 u, swap ref, b> } : create-order
|
||||
|
||||
// addr$ ng --
|
||||
{ create-simple-transfer send-mode create-order add-order } : send
|
||||
{ bl word bl word $>GR send } : SEND
|
||||
|
||||
// create internal message
|
||||
<b b{01} s, bounce 1 i, b{000} s, dest_addr Addr, amount Gram+cc, 0 9 64 32 + + u,
|
||||
body-cell <s 2dup 1 s-fits-with? not rot over 1 i, -rot { drop body-cell ref, } { s, } cond
|
||||
b>
|
||||
send-mode create-order add-order
|
||||
|
||||
// create external message
|
||||
now timeout + 32 << <b orders @ dict, b> hashu 32 1<<1- and + =: query_id
|
||||
<b subwallet-id 32 i, query_id 64 u, orders @ dict, b>
|
||||
dup ."signing message: " <s csr. cr
|
||||
dup hashu wallet_pk ed25519_sign_uint
|
||||
<b b{1000100} s, wallet_addr addr, 0 Gram, b{00} s,
|
||||
swap B, swap <s s, b>
|
||||
dup ."resulting external message: " <s csr. cr
|
||||
2 boc+>B dup Bx. cr
|
||||
."Query_id is " query_id dup . ."= 0x" X. cr
|
||||
savefile +".boc" tuck B>file
|
||||
."(Saved to file " type .")" cr
|
|
@ -26,6 +26,8 @@ begin-options
|
|||
"Sets the payload of the transfer message" option-help
|
||||
"C" "--comment" { =: comment } short-long-option-arg
|
||||
"Sets the comment to be sent in the transfer message" option-help
|
||||
"I" "--with-init" { =: init-file } short-long-option-arg
|
||||
"Indicates filename with BoC containing StateInit for internal message" option-help
|
||||
"m" "--mode" { parse-int =: send-mode } short-long-option-arg
|
||||
"Sets transfer mode (0..255) for SENDRAWMSG (" send-mode (.) $+ +" by default)"
|
||||
option-help
|
||||
|
@ -52,13 +54,17 @@ file-base +".pk" load-keypair nip constant wallet_pk
|
|||
def? body-boc-file { @' body-boc-file file>B B>boc } { comment simple-transfer-body } cond
|
||||
constant body-cell
|
||||
|
||||
def? init-file { @' init-file file>B B>boc <s b{11} swap |_ } { b{0} } cond
|
||||
=: state-init
|
||||
|
||||
."Transferring " amount .GR+cc ."to account "
|
||||
dest_addr 2dup bounce 7 + .Addr ." = " .addr
|
||||
."seqno=0x" seqno x. ."bounce=" bounce . cr
|
||||
."Body of transfer message is " body-cell <s csr. cr
|
||||
."StateInit is " state-init csr. cr
|
||||
|
||||
// create a message
|
||||
<b b{01} s, bounce 1 i, b{000} s, dest_addr Addr, amount Gram+cc, 0 9 64 32 + + u,
|
||||
<b b{01} s, bounce 1 i, b{000} s, dest_addr Addr, amount Gram+cc, 0 8 64 32 + + u, state-init s,
|
||||
body-cell <s 2dup 1 s-fits-with? not rot over 1 i, -rot { drop body-cell ref, } { s, } cond
|
||||
b>
|
||||
<b seqno 32 u, send-mode 8 u, swap ref, b>
|
||||
|
|
|
@ -1670,13 +1670,18 @@ Ref<vm::Cell> DictionaryFixed::extract_prefix_subdict_root(td::ConstBitPtr prefi
|
|||
}
|
||||
|
||||
std::pair<Ref<Cell>, int> DictionaryFixed::dict_filter(Ref<Cell> dict, td::BitPtr key, int n,
|
||||
const DictionaryFixed::filter_func_t& check_leaf) const {
|
||||
const DictionaryFixed::filter_func_t& check_leaf,
|
||||
int& skip_rest) const {
|
||||
// std::cerr << "dictionary filter for " << n << "-bit key = " << (key + n - key_bits).to_hex(key_bits - n)
|
||||
// << std::endl;
|
||||
if (dict.is_null()) {
|
||||
// empty dictionary, return unchanged
|
||||
return {{}, 0};
|
||||
}
|
||||
if (skip_rest >= 0) {
|
||||
// either drop subtree completely (if skip_rest>0), or retain it completely (if skip_rest=0)
|
||||
return {{}, skip_rest};
|
||||
}
|
||||
LabelParser label{std::move(dict), n, label_mode()};
|
||||
assert(label.l_bits >= 0 && label.l_bits <= n);
|
||||
label.extract_label_to(key);
|
||||
|
@ -1684,6 +1689,11 @@ std::pair<Ref<Cell>, int> DictionaryFixed::dict_filter(Ref<Cell> dict, td::BitPt
|
|||
if (label.l_bits == n) {
|
||||
// leaf
|
||||
int res = check_leaf(label.remainder.write(), key - key_bits, key_bits);
|
||||
if (res >= (1 << 30)) {
|
||||
// skip all, or retain all
|
||||
res &= (1 << 30) - 1;
|
||||
skip_rest = (res ? 0 : (1 << 30));
|
||||
}
|
||||
return {{}, res < 0 ? res : !res};
|
||||
}
|
||||
// fork, process left and right subtrees
|
||||
|
@ -1691,19 +1701,20 @@ std::pair<Ref<Cell>, int> DictionaryFixed::dict_filter(Ref<Cell> dict, td::BitPt
|
|||
key[-1] = false;
|
||||
int delta = label.l_bits + 1;
|
||||
n -= delta;
|
||||
auto left_res = dict_filter(label.remainder->prefetch_ref(0), key, n, check_leaf);
|
||||
auto left_res = dict_filter(label.remainder->prefetch_ref(0), key, n, check_leaf, skip_rest);
|
||||
if (left_res.second < 0) {
|
||||
return left_res;
|
||||
}
|
||||
key[-1] = true;
|
||||
auto right_res = dict_filter(label.remainder->prefetch_ref(1), key, n, check_leaf);
|
||||
auto right_res = dict_filter(label.remainder->prefetch_ref(1), key, n, check_leaf, skip_rest);
|
||||
if ((left_res.second | right_res.second) <= 0) {
|
||||
// error in right, or both left and right unchanged
|
||||
return right_res;
|
||||
}
|
||||
auto left = left_res.second ? std::move(left_res.first) : label.remainder->prefetch_ref(0);
|
||||
auto right = right_res.second ? std::move(right_res.first) : label.remainder->prefetch_ref(1);
|
||||
auto changes = left_res.second + right_res.second;
|
||||
// 2^30 is effectively infinity, meaning that we dropped whole branches with unknown # of nodes
|
||||
auto changes = ((left_res.second | right_res.second) & (1 << 30)) ? (1 << 30) : left_res.second + right_res.second;
|
||||
label.clear();
|
||||
if (left.is_null()) {
|
||||
if (right.is_null()) {
|
||||
|
@ -1735,8 +1746,9 @@ std::pair<Ref<Cell>, int> DictionaryFixed::dict_filter(Ref<Cell> dict, td::BitPt
|
|||
|
||||
int DictionaryFixed::filter(DictionaryFixed::filter_func_t check_leaf) {
|
||||
force_validate();
|
||||
int skip_rest = -1;
|
||||
unsigned char buffer[DictionaryFixed::max_key_bytes];
|
||||
auto res = dict_filter(get_root_cell(), td::BitPtr{buffer}, key_bits, check_leaf);
|
||||
auto res = dict_filter(get_root_cell(), td::BitPtr{buffer}, key_bits, check_leaf, skip_rest);
|
||||
if (res.second > 0) {
|
||||
// std::cerr << "after filter (" << res.second << " changes): new augmented dictionary root is:\n";
|
||||
// vm::load_cell_slice(res.first).print_rec(std::cerr);
|
||||
|
|
|
@ -293,7 +293,8 @@ class DictionaryFixed : public DictionaryBase {
|
|||
bool remove_prefix = false) const;
|
||||
bool dict_check_for_each(Ref<Cell> dict, td::BitPtr key_buffer, int n, int total_key_len,
|
||||
const foreach_func_t& foreach_func, bool invert_first = false) const;
|
||||
std::pair<Ref<Cell>, int> dict_filter(Ref<Cell> dict, td::BitPtr key, int n, const filter_func_t& check_leaf) const;
|
||||
std::pair<Ref<Cell>, int> dict_filter(Ref<Cell> dict, td::BitPtr key, int n, const filter_func_t& check_leaf,
|
||||
int& skip_rest) const;
|
||||
Ref<Cell> dict_combine_with(Ref<Cell> dict1, Ref<Cell> dict2, td::BitPtr key_buffer, int n, int total_key_len,
|
||||
const combine_func_t& combine_func, int mode = 0, int skip1 = 0, int skip2 = 0) const;
|
||||
bool dict_scan_diff(Ref<Cell> dict1, Ref<Cell> dict2, td::BitPtr key_buffer, int n, int total_key_len,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue