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

liteserver: bugfix

liteserver/liteclient: fixed bug in proof
validator: added stats
smartcontracts: updates
This commit is contained in:
ton 2019-09-30 16:49:45 +04:00
parent ecb3e06a06
commit 2845f9a2cc
30 changed files with 280 additions and 124 deletions

View file

@ -25,7 +25,7 @@
{ bl word 1 { -rot 2 'nop does swap 0 (create) }
} :: 2=:
{ <b swap s, b> } : s>c
{ s>c hash } : shash
{ s>c hashB } : shash
// to be more efficiently re-implemented in C++ in the future
{ dup 0< ' negate if } : abs
{ 2dup > ' swap if } : minmax

View file

@ -764,13 +764,17 @@ void interpret_string_to_bytes(vm::Stack& stack) {
stack.push_bytes(stack.pop_string());
}
void interpret_bytes_hash(vm::Stack& stack) {
void interpret_bytes_hash(vm::Stack& stack, bool as_uint) {
std::string str = stack.pop_bytes();
unsigned char buffer[32];
digest::hash_str<digest::SHA256>(buffer, str.c_str(), str.size());
td::RefInt256 x{true};
x.write().import_bytes(buffer, 32, false);
stack.push_int(std::move(x));
if (as_uint) {
td::RefInt256 x{true};
x.write().import_bytes(buffer, 32, false);
stack.push_int(std::move(x));
} else {
stack.push_bytes(std::string{(char*)buffer, 32});
}
}
void interpret_empty(vm::Stack& stack) {
@ -892,11 +896,15 @@ void interpret_builder_remaining_bitrefs(vm::Stack& stack, int mode) {
}
}
void interpret_cell_hash(vm::Stack& stack) {
void interpret_cell_hash(vm::Stack& stack, bool as_uint) {
auto cell = stack.pop_cell();
td::RefInt256 hash{true};
hash.write().import_bytes(cell->get_hash().as_slice().ubegin(), 32, false);
stack.push_int(std::move(hash));
if (as_uint) {
td::RefInt256 hash{true};
hash.write().import_bytes(cell->get_hash().as_slice().ubegin(), 32, false);
stack.push_int(std::move(hash));
} else {
stack.push_bytes(cell->get_hash().as_slice().str());
}
}
void interpret_store_ref(vm::Stack& stack) {
@ -959,7 +967,9 @@ void interpret_fetch_bytes(vm::Stack& stack, int mode) {
unsigned n = stack.pop_smallint_range(127);
auto cs = stack.pop_cellslice();
if (!cs->have(n * 8)) {
stack.push(std::move(cs));
if (mode & 2) {
stack.push(std::move(cs));
}
stack.push_bool(false);
if (!(mode & 4)) {
throw IntError{"end of data while reading byte string from cell"};
@ -970,7 +980,7 @@ void interpret_fetch_bytes(vm::Stack& stack, int mode) {
if (mode & 2) {
cs.write().fetch_bytes(tmp, n);
} else {
cs.write().prefetch_bytes(tmp, n);
cs->prefetch_bytes(tmp, n);
}
std::string s{tmp, tmp + n};
if (mode & 1) {
@ -978,7 +988,9 @@ void interpret_fetch_bytes(vm::Stack& stack, int mode) {
} else {
stack.push_string(std::move(s));
}
stack.push(std::move(cs));
if (mode & 2) {
stack.push(std::move(cs));
}
if (mode & 4) {
stack.push_bool(true);
}
@ -1009,13 +1021,15 @@ void interpret_cell_remaining(vm::Stack& stack) {
void interpret_fetch_ref(vm::Stack& stack, int mode) {
auto cs = stack.pop_cellslice();
if (!cs->have_refs(1)) {
stack.push(std::move(cs));
if (mode & 2) {
stack.push(std::move(cs));
}
stack.push_bool(false);
if (!(mode & 4)) {
throw IntError{"end of data while reading reference from cell"};
}
} else {
auto cell = (mode & 2) ? cs.write().fetch_ref() : cs.write().prefetch_ref();
auto cell = (mode & 2) ? cs.write().fetch_ref() : cs->prefetch_ref();
if (mode & 2) {
stack.push(std::move(cs));
}
@ -2474,7 +2488,9 @@ void init_words_common(Dictionary& d) {
d.def_stack_word("B>Lu@+ ", std::bind(interpret_bytes_fetch_int, _1, 0x12));
d.def_stack_word("B>Li@+ ", std::bind(interpret_bytes_fetch_int, _1, 0x13));
d.def_stack_word("$>B ", interpret_string_to_bytes);
d.def_stack_word("Bhash ", interpret_bytes_hash);
d.def_stack_word("Bhash ", std::bind(interpret_bytes_hash, _1, true));
d.def_stack_word("Bhashu ", std::bind(interpret_bytes_hash, _1, true));
d.def_stack_word("BhashB ", std::bind(interpret_bytes_hash, _1, false));
// cell manipulation (create, write and modify cells)
d.def_stack_word("<b ", interpret_empty);
d.def_stack_word("i, ", std::bind(interpret_store, _1, true));
@ -2496,7 +2512,9 @@ void init_words_common(Dictionary& d) {
d.def_stack_word("brembits ", std::bind(interpret_builder_remaining_bitrefs, _1, 1));
d.def_stack_word("bremrefs ", std::bind(interpret_builder_remaining_bitrefs, _1, 2));
d.def_stack_word("brembitrefs ", std::bind(interpret_builder_remaining_bitrefs, _1, 3));
d.def_stack_word("hash ", interpret_cell_hash);
d.def_stack_word("hash ", std::bind(interpret_cell_hash, _1, true));
d.def_stack_word("hashu ", std::bind(interpret_cell_hash, _1, true));
d.def_stack_word("hashB ", std::bind(interpret_cell_hash, _1, false));
// cellslice manipulation (read from cells)
d.def_stack_word("<s ", interpret_from_cell);
d.def_stack_word("i@ ", std::bind(interpret_fetch, _1, 1));

View file

@ -15,10 +15,10 @@ cr ."initial basechain state is:" cr dup <s csr. cr
dup dup 31 boc+>B dup Bx. cr
dup "basestate0" +suffix +".boc" tuck B>file
."(Initial basechain state saved to file " type .")" cr
Bhash dup =: basestate0_fhash
Bhashu dup =: basestate0_fhash
."file hash=" dup x. space 256 u>B dup B>base64url type cr
"basestate0" +suffix +".fhash" B>file
hash dup =: basestate0_rhash
hashu dup =: basestate0_rhash
."root hash=" dup x. space 256 u>B dup B>base64url type cr
"basestate0" +suffix +".rhash" B>file
@ -227,10 +227,10 @@ cr cr ."new state is:" cr dup <s csr. cr
dup 31 boc+>B dup Bx. cr
dup "zerostate" +suffix +".boc" tuck B>file
."(Initial masterchain state saved to file " type .")" cr
Bhash dup =: zerostate_fhash
Bhashu dup =: zerostate_fhash
."file hash=" dup x. space 256 u>B dup B>base64url type cr
"zerostate" +suffix +".fhash" B>file
hash dup =: zerostate_rhash ."root hash=" dup x. space 256 u>B dup B>base64url type cr
hashu dup =: zerostate_rhash ."root hash=" dup x. space 256 u>B dup B>base64url type cr
"zerostate" +suffix +".rhash" B>file
basestate0_rhash ."Basestate0 root hash=" dup x. space 256 u>B B>base64url type cr
basestate0_fhash ."Basestate0 file hash=" dup x. space 256 u>B B>base64url type cr

View file

@ -15,10 +15,10 @@ cr ."initial basechain state is:" cr dup <s csr. cr
dup dup 31 boc+>B dup Bx. cr
dup "basestate0" +suffix +".boc" tuck B>file
."(Initial basechain state saved to file " type .")" cr
Bhash dup =: basestate0_fhash
Bhashu dup =: basestate0_fhash
."file hash=" dup x. space 256 u>B dup B>base64url type cr
"basestate0" +suffix +".fhash" B>file
hash dup =: basestate0_rhash
hashu dup =: basestate0_rhash
."root hash=" dup x. space 256 u>B dup B>base64url type cr
"basestate0" +suffix +".rhash" B>file
@ -231,10 +231,10 @@ cr cr ."new state is:" cr dup <s csr. cr
dup 31 boc+>B dup Bx. cr
dup "zerostate" +suffix +".boc" tuck B>file
."(Initial masterchain state saved to file " type .")" cr
Bhash dup =: zerostate_fhash
Bhashu dup =: zerostate_fhash
."file hash= " dup X. space 256 u>B dup B>base64url type cr
"zerostate" +suffix +".fhash" B>file
hash dup =: zerostate_rhash ."root hash= " dup X. space 256 u>B dup B>base64url type cr
hashu dup =: zerostate_rhash ."root hash= " dup X. space 256 u>B dup B>base64url type cr
"zerostate" +suffix +".rhash" B>file
basestate0_rhash ."Basestate0 root hash= " dup X. space 256 u>B B>base64url type cr
basestate0_fhash ."Basestate0 file hash= " dup X. space 256 u>B B>base64url type cr

View file

@ -59,7 +59,7 @@ order-file include
// create external message
<b subwallet-id 32 i, now timeout + 32 u, seqno 32 u, orders @ dict, b>
dup ."signing message: " <s csr. cr
dup hash wallet_pk ed25519_sign_uint
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

View file

@ -29,14 +29,14 @@ b> // data
null // no libraries
<b b{0011} s, 3 roll ref, rot ref, swap dict, b> // create StateInit
dup ."StateInit: " <s csr. cr
dup hash wc swap 2dup 2constant wallet_addr
dup hashu wc swap 2dup 2constant wallet_addr
."new wallet address = " 2dup .addr cr
2dup file-base +subwallet +".addr" save-address-verbose
."Non-bounceable address (for init): " 2dup 7 .Addr cr
."Bounceable address (for later access): " 6 .Addr cr
<b subwallet-id 32 i, -1 32 i, 0 32 u, false 1 i, b>
dup ."signing message: " <s csr. cr
dup hash wallet_pk ed25519_sign_uint rot
dup hashu wallet_pk ed25519_sign_uint rot
<b b{1000100} s, wallet_addr addr, b{000010} s, swap <s s, b{0} s, swap B, swap <s s, b>
dup ."External message for initialization is " <s csr. cr
2 boc+>B dup Bx. cr

View file

@ -41,7 +41,7 @@ def? $3 { @' $3 } { "new-pinger" } cond constant file-base
// no libraries
<b b{00110} s, rot ref, swap ref, b> // create StateInit
dup ."StateInit: " <s csr. cr
dup hash wc swap 2dup 2constant pinger_addr
dup hashu wc swap 2dup 2constant pinger_addr
."new pinger address = " 2dup .addr cr
2dup file-base +".addr" save-address-verbose
."Non-bounceable address (for init): " 2dup 7 .Addr cr

View file

@ -37,7 +37,7 @@ def? $2 { @' $2 } { "new-testgiver" } cond constant file-base
null // no libraries
<b b{0011} s, 3 roll ref, rot ref, swap dict, b> // create StateInit
dup ."StateInit: " <s csr. cr
dup hash wc swap 2dup 2constant wallet_addr
dup hashu wc swap 2dup 2constant wallet_addr
."new money giver address = " 2dup .addr cr
2dup file-base +".addr" save-address-verbose
."Non-bounceable address (for init): " 2dup 7 .Addr cr

View file

@ -47,14 +47,14 @@ b> // data
null // no libraries
<b b{0011} s, 3 roll ref, rot ref, swap dict, b> // create StateInit
dup ."StateInit: " <s csr. cr
dup hash wc swap 2dup 2constant wallet_addr
dup hashu wc swap 2dup 2constant wallet_addr
."new wallet address = " 2dup .addr cr
2dup file-base +".addr" save-address-verbose
."Non-bounceable address (for init): " 2dup 7 .Addr cr
."Bounceable address (for later access): " 6 .Addr cr
<b 0 32 u, -1 32 i, b>
dup ."signing message: " <s csr. cr
dup hash wallet_pk ed25519_sign_uint rot
dup hashu wallet_pk ed25519_sign_uint rot
<b b{1000100} s, wallet_addr addr, b{000010} s, swap <s s, b{0} s, swap B, swap <s s, b>
dup ."External message for initialization is " <s csr. cr
2 boc+>B dup Bx. cr

View file

@ -47,14 +47,14 @@ null // no libraries
// Libs{ x{ABACABADABACABA} drop x{AAAA} s>c public_lib x{1234} x{5678} |_ s>c public_lib }Libs
<b b{0011} s, 3 roll ref, rot ref, swap dict, b> // create StateInit
dup ."StateInit: " <s csr. cr
dup hash wc swap 2dup 2constant wallet_addr
dup hashu wc swap 2dup 2constant wallet_addr
."new wallet address = " 2dup .addr cr
2dup file-base +".addr" save-address-verbose
."Non-bounceable address (for init): " 2dup 7 .Addr cr
."Bounceable address (for later access): " 6 .Addr cr
<b 0 32 u, b>
dup ."signing message: " <s csr. cr
dup hash wallet_pk ed25519_sign_uint rot
dup hashu wallet_pk ed25519_sign_uint rot
<b b{1000100} s, wallet_addr addr, b{000010} s, swap <s s, b{0} s, swap B, swap <s s, b>
dup ."External message for initialization is " <s csr. cr
2 boc+>B dup Bx. cr

View file

@ -6,7 +6,7 @@
."with private key loaded from file <filename-base>.pk, "
."and saves it into <savefile>.boc ('config-query.boc' by default)" cr 1 halt
} : usage
def? $# { @' $# dup 2 < swap 3 > or ' usage if } if
$# dup 2 < swap 3 > or ' usage if
"config-master" constant file-base
0 constant seqno
@ -15,18 +15,16 @@ true constant bounce
"config-code.fif" constant config-source
100 constant interval // valid for 100 seconds
def? $2 {
@' $1 =: file-base
@' $2 parse-int =: seqno
} if
def? $5 { @' $5 } { "config-query" } cond constant savefile
$1 =: file-base
$2 parse-int =: seqno
def? $3 { @' $3 } { "config-query" } cond constant savefile
file-base +".addr" load-address
2dup 2constant config_addr
."Configuration smart contract address = " 2dup .addr cr 6 .Addr cr
file-base +".pk" load-keypair nip constant config_pk
."Loading new configuration smart contract code from file file " config-source type cr
."Loading new configuration smart contract code from file " config-source type cr
"Asm.fif" include
config-source include
dup <s csr. cr
@ -34,7 +32,7 @@ dup <s csr. cr
// create a message
<b x{4e436f64} s, seqno 32 u, now interval + 32 u, swap ref, b>
dup ."signing message: " <s csr. cr
dup hash config_pk ed25519_sign_uint
dup hashu config_pk ed25519_sign_uint
<b b{1000100} s, config_addr addr, 0 Gram, b{00} s,
swap B, swap <s s, b>
dup ."resulting external message: " <s csr. cr

View file

@ -6,7 +6,7 @@
."with private key loaded from file <filename-base>.pk, "
."and saves it into <savefile>.boc ('config-query.boc' by default)" cr 1 halt
} : usage
def? $# { @' $# dup 4 < swap 5 > or ' usage if } if
$# dup 4 < swap 5 > or ' usage if
"config-master" constant file-base
0 constant seqno
@ -15,12 +15,10 @@ true constant bounce
"new-value.boc" constant boc-filename
100 constant interval // valid for 100 seconds
def? $4 {
@' $1 =: file-base
@' $2 parse-int =: seqno
@' $3 parse-int =: idx
@' $4 =: boc-filename
} if
$1 =: file-base
$2 parse-int =: seqno
$3 parse-int =: idx
$4 =: boc-filename
def? $5 { @' $5 } { "config-query" } cond constant savefile
file-base +".addr" load-address
@ -39,7 +37,7 @@ dup idx is-valid-config? not abort"not a valid value for chosen configuration pa
// create a message
<b x{43665021} s, seqno 32 u, now interval + 32 u, idx 32 i, swap ref, b>
dup ."signing message: " <s csr. cr
dup hash config_pk ed25519_sign_uint
dup hashu config_pk ed25519_sign_uint
<b b{1000100} s, config_addr addr, 0 Gram, b{00} s,
swap B, swap <s s, b>
dup ."resulting external message: " <s csr. cr

View file

@ -6,7 +6,7 @@
."with private key loaded from file <filename-base>.pk, "
."and saves it into <savefile>.boc ('config-query.boc' by default)" cr 1 halt
} : usage
def? $# { @' $# dup 2 < swap 3 > or ' usage if } if
$# dup 2 < swap 3 > or ' usage if
"config-master" constant file-base
0 constant seqno
@ -15,18 +15,16 @@ true constant bounce
"elector-code.fif" constant elector-source
100 constant interval // valid for 100 seconds
def? $2 {
@' $1 =: file-base
@' $2 parse-int =: seqno
} if
def? $5 { @' $5 } { "config-query" } cond constant savefile
$1 =: file-base
$2 parse-int =: seqno
def? $3 { @' $3 } { "config-query" } cond constant savefile
file-base +".addr" load-address
2dup 2constant config_addr
."Configuration smart contract address = " 2dup .addr cr 6 .Addr cr
file-base +".pk" load-keypair nip constant config_pk
."Loading new elector smart contract code from file file " elector-source type cr
."Loading new elector smart contract code from file " elector-source type cr
"Asm.fif" include
elector-source include
dup <s csr. cr
@ -34,7 +32,7 @@ dup <s csr. cr
// create a message
<b x{4e43ef05} s, seqno 32 u, now interval + 32 u, swap ref, b>
dup ."signing message: " <s csr. cr
dup hash config_pk ed25519_sign_uint
dup hashu config_pk ed25519_sign_uint
<b b{1000100} s, config_addr addr, 0 Gram, b{00} s,
swap B, swap <s s, b>
dup ."resulting external message: " <s csr. cr

View file

@ -38,7 +38,7 @@ dest_addr 2dup bounce 7 + .Addr ." = " .addr
b>
<b seqno 32 u, now timeout + 32 u, send-mode 8 u, swap ref, b>
dup ."signing message: " <s csr. cr
dup hash wallet_pk ed25519_sign_uint
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

View file

@ -37,7 +37,7 @@ dest_addr 2dup bounce 7 + .Addr ." = " .addr
b>
<b seqno 32 u, send-mode 8 u, swap ref, b>
dup ."signing message: " <s csr. cr
dup hash wallet_pk ed25519_sign_uint
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

View file

@ -267,16 +267,18 @@ MerkleProofBuilder::MerkleProofBuilder(Ref<Cell> root)
usage_root = UsageCell::create(orig_root, usage_tree->root_ptr());
}
void MerkleProofBuilder::reset(Ref<Cell> root) {
Ref<Cell> MerkleProofBuilder::init(Ref<Cell> root) {
usage_tree = std::make_shared<CellUsageTree>();
orig_root = std::move(root);
usage_root = UsageCell::create(orig_root, usage_tree->root_ptr());
return usage_root;
}
void MerkleProofBuilder::clear() {
bool MerkleProofBuilder::clear() {
usage_tree.reset();
orig_root.clear();
usage_root.clear();
return true;
}
Ref<Cell> MerkleProofBuilder::extract_proof() const {

View file

@ -51,9 +51,10 @@ class MerkleProofBuilder {
Ref<vm::Cell> orig_root, usage_root;
public:
MerkleProofBuilder() = default;
MerkleProofBuilder(Ref<Cell> root);
void reset(Ref<Cell> root);
void clear();
Ref<Cell> init(Ref<Cell> root);
bool clear();
Ref<Cell> root() const {
return usage_root;
}