mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
Various changes in TVM, github builds and tests (#793)
* Bugfixes in TVM and node * Upgrade to C++17 * Improve GitHub builds * Fix existing tests and partially integrate them into builds --------- Co-authored-by: neodiX42 <namlem@gmail.com> Co-authored-by: EmelyanenkoK <emelyanenko.kirill@gmail.com>
This commit is contained in:
parent
89700cb2aa
commit
5847897b37
122 changed files with 2889 additions and 4100 deletions
|
@ -1,4 +1,4 @@
|
|||
cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)
|
||||
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
|
||||
|
||||
if (NOT OPENSSL_FOUND)
|
||||
find_package(OpenSSL REQUIRED)
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -270,7 +270,7 @@ struct Account {
|
|||
return balance;
|
||||
}
|
||||
bool set_address(ton::WorkchainId wc, td::ConstBitPtr new_addr);
|
||||
bool unpack(Ref<vm::CellSlice> account, Ref<vm::CellSlice> extra, ton::UnixTime now, bool special = false);
|
||||
bool unpack(Ref<vm::CellSlice> account, ton::UnixTime now, bool special);
|
||||
bool init_new(ton::UnixTime now);
|
||||
bool deactivate();
|
||||
bool recompute_tmp_addr(Ref<vm::CellSlice>& tmp_addr, int split_depth, td::ConstBitPtr orig_addr_rewrite) const;
|
||||
|
@ -382,8 +382,6 @@ struct Transaction {
|
|||
|
||||
td::Result<vm::NewCellStorageStat::Stat> estimate_block_storage_profile_incr(
|
||||
const vm::NewCellStorageStat& store_stat, const vm::CellUsageTree* usage_tree) const;
|
||||
bool update_block_storage_profile(vm::NewCellStorageStat& store_stat, const vm::CellUsageTree* usage_tree) const;
|
||||
bool would_fit(unsigned cls, const block::BlockLimitStatus& blk_lim_st) const;
|
||||
bool update_limits(block::BlockLimitStatus& blk_lim_st, bool with_size = true) const;
|
||||
|
||||
Ref<vm::Cell> commit(Account& _account); // _account should point to the same account
|
||||
|
|
|
@ -130,7 +130,7 @@ void bits_memcpy(unsigned char* to, int to_offs, const unsigned char* from, int
|
|||
from_offs &= 7;
|
||||
to_offs &= 7;
|
||||
//fprintf(stderr, "bits_memcpy: from=%p (%02x) to=%p (%02x) from_offs=%d to_offs=%d count=%lu\n", from, *from, to, *to, from_offs, to_offs, bit_count);
|
||||
int sz = (int)bit_count;
|
||||
int sz = static_cast<int>(bit_count);
|
||||
bit_count += from_offs;
|
||||
if (from_offs == to_offs) {
|
||||
if (bit_count < 8) {
|
||||
|
@ -206,7 +206,7 @@ void bits_memset(unsigned char* to, int to_offs, bool val, std::size_t bit_count
|
|||
}
|
||||
to += (to_offs >> 3);
|
||||
to_offs &= 7;
|
||||
int sz = (int)bit_count;
|
||||
int sz = static_cast<int>(bit_count);
|
||||
bit_count += to_offs;
|
||||
int c = *to;
|
||||
if (bit_count <= 8) {
|
||||
|
|
|
@ -461,19 +461,109 @@ x{B7A3} @Defop QNEGATE
|
|||
x{B7A4} @Defop QINC
|
||||
x{B7A5} @Defop QDEC
|
||||
x{B7A8} @Defop QMUL
|
||||
|
||||
x{B7A904} @Defop QDIV
|
||||
x{B7A905} @Defop QDIVR
|
||||
x{B7A906} @Defop QDIVC
|
||||
x{B7A908} @Defop QMOD
|
||||
x{B7A909} @Defop QMODR
|
||||
x{B7A90A} @Defop QMODC
|
||||
x{B7A90C} @Defop QDIVMOD
|
||||
x{B7A90D} @Defop QDIVMODR
|
||||
x{B7A90E} @Defop QDIVMODC
|
||||
x{B7A900} @Defop QADDDIVMOD
|
||||
x{B7A901} @Defop QADDDIVMODR
|
||||
x{B7A902} @Defop QADDDIVMODC
|
||||
|
||||
x{B7A925} @Defop QRSHIFTR
|
||||
x{B7A926} @Defop QRSHIFTC
|
||||
x{B7A928} @Defop QMODPOW2
|
||||
x{B7A929} @Defop QMODPOW2R
|
||||
x{B7A92A} @Defop QMODPOW2C
|
||||
x{B7A92C} @Defop QRSHIFTMOD
|
||||
x{B7A92D} @Defop QRSHIFTMODR
|
||||
x{B7A92E} @Defop QRSHIFTMODC
|
||||
x{B7A920} @Defop QADDRSHIFTMOD
|
||||
x{B7A921} @Defop QADDRSHIFTMODR
|
||||
x{B7A922} @Defop QADDRSHIFTMODC
|
||||
|
||||
x{B7A935} @Defop(8u+1) QRSHIFTR#
|
||||
x{B7A936} @Defop(8u+1) QRSHIFTC#
|
||||
x{B7A938} @Defop(8u+1) QMODPOW2#
|
||||
x{B7A939} @Defop(8u+1) QMODPOW2R#
|
||||
x{B7A93A} @Defop(8u+1) QMODPOW2C#
|
||||
x{B7A93C} @Defop(8u+1) QRSHIFT#MOD
|
||||
x{B7A93D} @Defop(8u+1) QRSHIFTR#MOD
|
||||
x{B7A93E} @Defop(8u+1) QRSHIFTC#MOD
|
||||
x{B7A930} @Defop(8u+1) QADDRSHIFT#MOD
|
||||
x{B7A931} @Defop(8u+1) QADDRSHIFTR#MOD
|
||||
x{B7A932} @Defop(8u+1) QADDRSHIFTC#MOD
|
||||
|
||||
x{B7A984} @Defop QMULDIV
|
||||
x{B7A985} @Defop QMULDIVR
|
||||
x{B7A986} @Defop QMULDIVC
|
||||
x{B7A988} @Defop QMULMOD
|
||||
x{B7A989} @Defop QMULMODR
|
||||
x{B7A98A} @Defop QMULMODC
|
||||
x{B7A98C} @Defop QMULDIVMOD
|
||||
x{B7A980} @Defop QADDMULDIVMOD
|
||||
x{B7A98D} @Defop QMULDIVMODR
|
||||
x{B7A98E} @Defop QMULDIVMODC
|
||||
x{B7A980} @Defop QMULADDDIVMOD
|
||||
x{B7A981} @Defop QMULADDDIVMODR
|
||||
x{B7A982} @Defop QMULADDDIVMODC
|
||||
|
||||
x{B7A9A4} @Defop QMULRSHIFT
|
||||
x{B7A9A5} @Defop QMULRSHIFTR
|
||||
x{B7A9A6} @Defop QMULRSHIFTC
|
||||
x{B7A9A8} @Defop QMULMODPOW2
|
||||
x{B7A9A9} @Defop QMULMODPOW2R
|
||||
x{B7A9AA} @Defop QMULMODPOW2C
|
||||
x{B7A9AC} @Defop QMULRSHIFTMOD
|
||||
x{B7A9AD} @Defop QMULRSHIFTRMOD
|
||||
x{B7A9AE} @Defop QMULRSHIFTCMOD
|
||||
x{B7A9A0} @Defop QMULADDRSHIFTMOD
|
||||
x{B7A9A1} @Defop QMULADDRSHIFTRMOD
|
||||
x{B7A9A2} @Defop QMULADDRSHIFTCMOD
|
||||
|
||||
x{B7A9B4} @Defop(8u+1) QMULRSHIFT#
|
||||
x{B7A9B5} @Defop(8u+1) QMULRSHIFTR#
|
||||
x{B7A9B6} @Defop(8u+1) QMULRSHIFTC#
|
||||
x{B7A9B8} @Defop(8u+1) QMULMODPOW2#
|
||||
x{B7A9B9} @Defop(8u+1) QMULMODPOW2R#
|
||||
x{B7A9BA} @Defop(8u+1) QMULMODPOW2C#
|
||||
x{B7A9BC} @Defop(8u+1) QMULRSHIFT#MOD
|
||||
x{B7A9BD} @Defop(8u+1) QMULRSHIFTR#MOD
|
||||
x{B7A9BE} @Defop(8u+1) QMULRSHIFTC#MOD
|
||||
x{B7A9B0} @Defop(8u+1) QMULADDRSHIFT#MOD
|
||||
x{B7A9B1} @Defop(8u+1) QMULADDRSHIFTR#MOD
|
||||
x{B7A9B2} @Defop(8u+1) QMULADDRSHIFTC#MOD
|
||||
|
||||
x{B7A9C4} @Defop QLSHIFTDIV
|
||||
x{B7A9C5} @Defop QLSHIFTDIVR
|
||||
x{B7A9C6} @Defop QLSHIFTDIVC
|
||||
x{B7A9C8} @Defop QLSHIFTMOD
|
||||
x{B7A9C9} @Defop QLSHIFTMODR
|
||||
x{B7A9CA} @Defop QLSHIFTMODC
|
||||
x{B7A9CC} @Defop QLSHIFTDIVMOD
|
||||
x{B7A9CD} @Defop QLSHIFTDIVMODR
|
||||
x{B7A9CE} @Defop QLSHIFTDIVMODC
|
||||
x{B7A9C0} @Defop QLSHIFTADDDIVMOD
|
||||
x{B7A9C1} @Defop QLSHIFTADDDIVMODR
|
||||
x{B7A9C2} @Defop QLSHIFTADDDIVMODC
|
||||
|
||||
x{B7A9D4} @Defop(8u+1) QLSHIFT#DIV
|
||||
x{B7A9D5} @Defop(8u+1) QLSHIFT#DIVR
|
||||
x{B7A9D6} @Defop(8u+1) QLSHIFT#DIVC
|
||||
x{B7A9D8} @Defop(8u+1) QLSHIFT#MOD
|
||||
x{B7A9D9} @Defop(8u+1) QLSHIFT#MODR
|
||||
x{B7A9DA} @Defop(8u+1) QLSHIFT#MODC
|
||||
x{B7A9DC} @Defop(8u+1) QLSHIFT#DIVMOD
|
||||
x{B7A9DD} @Defop(8u+1) QLSHIFT#DIVMODR
|
||||
x{B7A9DE} @Defop(8u+1) QLSHIFT#DIVMODC
|
||||
x{B7A9D0} @Defop(8u+1) QLSHIFT#ADDDIVMOD
|
||||
x{B7A9D1} @Defop(8u+1) QLSHIFT#ADDDIVMODR
|
||||
x{B7A9D2} @Defop(8u+1) QLSHIFT#ADDDIVMODC
|
||||
|
||||
x{B7AC} @Defop QLSHIFT
|
||||
x{B7AD} @Defop QRSHIFT
|
||||
x{B7AE} @Defop QPOW2
|
||||
|
@ -1185,7 +1275,7 @@ x{F4BF} @Defop DICTUGETEXECZ
|
|||
|
||||
x{F800} @Defop ACCEPT
|
||||
x{F801} @Defop SETGASLIMIT
|
||||
x{F802} @Defop GASCONSUMED
|
||||
x{F806} @Defop GASCONSUMED
|
||||
x{F80F} @Defop COMMIT
|
||||
|
||||
x{F810} @Defop RANDU256
|
||||
|
|
|
@ -3512,7 +3512,7 @@ void init_words_ton(Dictionary& d) {
|
|||
|
||||
void init_words_vm(Dictionary& d, bool enable_debug) {
|
||||
using namespace std::placeholders;
|
||||
vm::init_op_cp0(enable_debug);
|
||||
vm::init_vm(enable_debug).ensure();
|
||||
// vm run
|
||||
d.def_word("vmlibs ", LitCont::literal(vm_libraries));
|
||||
// d.def_ctx_word("runvmcode ", std::bind(interpret_run_vm, _1, 0x40));
|
||||
|
|
|
@ -8,37 +8,37 @@ import shutil
|
|||
add_pragmas = [] #["allow-post-modification", "compute-asm-ltr"];
|
||||
|
||||
tests = [
|
||||
# note, that deployed version of elector,config and multisig differ since it is compilled with func-0.1.0.
|
||||
# Newer compillators optimize arithmetic and logic expression that can be calculated at the compile time
|
||||
["elector/elector-code.fc", 115226404411715505328583639896096915745686314074575650766750648324043316883483],
|
||||
["config/config-code.fc", 10913070768607625342121305745084703121685937915388357634624451844356456145601],
|
||||
["eth-bridge-multisig/multisig-code.fc", 101509909129354488841890823627011033360100627957439967918234053299675481277954],
|
||||
# note, that deployed version of elector,config and multisig differ since it is compilled with func-0.1.0.
|
||||
# Newer compillators optimize arithmetic and logic expression that can be calculated at the compile time
|
||||
["elector/elector-code.fc", 115226404411715505328583639896096915745686314074575650766750648324043316883483],
|
||||
["config/config-code.fc", 10913070768607625342121305745084703121685937915388357634624451844356456145601],
|
||||
["eth-bridge-multisig/multisig-code.fc", 101509909129354488841890823627011033360100627957439967918234053299675481277954],
|
||||
|
||||
["bsc-bridge-collector/votes-collector.fc", 62190447221288642706570413295807615918589884489514159926097051017036969900417],
|
||||
["uni-lock-wallet/uni-lockup-wallet.fc", 61959738324779104851267145467044677651344601417998258530238254441977103654381],
|
||||
["nft-collection/nft-collection-editable.fc", 45561997735512210616567774035540357815786262097548276229169737015839077731274],
|
||||
["dns-collection/nft-collection.fc", 107999822699841936063083742021519765435859194241091312445235370766165379261859],
|
||||
["bsc-bridge-collector/votes-collector.fc", 62190447221288642706570413295807615918589884489514159926097051017036969900417],
|
||||
["uni-lock-wallet/uni-lockup-wallet.fc", 61959738324779104851267145467044677651344601417998258530238254441977103654381],
|
||||
["nft-collection/nft-collection-editable.fc", 45561997735512210616567774035540357815786262097548276229169737015839077731274],
|
||||
["dns-collection/nft-collection.fc", 107999822699841936063083742021519765435859194241091312445235370766165379261859],
|
||||
|
||||
|
||||
# note, that deployed version of tele-nft-item differs since it is compilled with func-0.3.0.
|
||||
# After introducing of try/catch construction, c2 register is not always the default one.
|
||||
# Thus it is necessary to save it upon jumps, differences of deployed and below compilled is that
|
||||
# "c2 SAVE" is added to the beginning of recv_internal. It does not change behavior.
|
||||
["tele-nft-item/nft-item.fc", 69777543125381987786450436977742010705076866061362104025338034583422166453344],
|
||||
# note, that deployed version of tele-nft-item differs since it is compilled with func-0.3.0.
|
||||
# After introducing of try/catch construction, c2 register is not always the default one.
|
||||
# Thus it is necessary to save it upon jumps, differences of deployed and below compilled is that
|
||||
# "c2 SAVE" is added to the beginning of recv_internal. It does not change behavior.
|
||||
["tele-nft-item/nft-item.fc", 69777543125381987786450436977742010705076866061362104025338034583422166453344],
|
||||
|
||||
["storage/storage-contract.fc", 91377830060355733016937375216020277778264560226873154627574229667513068328151],
|
||||
["storage/storage-provider.fc", 13618336676213331164384407184540461509022654507176709588621016553953760588122],
|
||||
["nominator-pool/pool.fc", 69767057279163099864792356875696330339149706521019810113334238732928422055375],
|
||||
["jetton-minter/jetton-minter.fc", 9028309926287301331466371999814928201427184114165428257502393474125007156494],
|
||||
["gg-marketplace/nft-marketplace-v2.fc", 92199806964112524639740773542356508485601908152150843819273107618799016205930],
|
||||
["jetton-wallet/jetton-wallet.fc", 86251125787443633057458168028617933212663498001665054651523310772884328206542],
|
||||
["whales-nominators/nominators.fc", 8941364499854379927692172316865293429893094891593442801401542636695127885153],
|
||||
["storage/storage-contract.fc", 91377830060355733016937375216020277778264560226873154627574229667513068328151],
|
||||
["storage/storage-provider.fc", 13618336676213331164384407184540461509022654507176709588621016553953760588122],
|
||||
["nominator-pool/pool.fc", 69767057279163099864792356875696330339149706521019810113334238732928422055375],
|
||||
["jetton-minter/jetton-minter.fc", 9028309926287301331466371999814928201427184114165428257502393474125007156494],
|
||||
["gg-marketplace/nft-marketplace-v2.fc", 92199806964112524639740773542356508485601908152150843819273107618799016205930],
|
||||
["jetton-wallet/jetton-wallet.fc", 86251125787443633057458168028617933212663498001665054651523310772884328206542],
|
||||
["whales-nominators/nominators.fc", 8941364499854379927692172316865293429893094891593442801401542636695127885153],
|
||||
|
||||
|
||||
["tact-examples/treasure_Treasure.code.fc", 13962538639825790677138656603323869918938565499584297120566680287245364723897],
|
||||
["tact-examples/jetton_SampleJetton.code.fc", 94076762218493729104783735200107713211245710256802265203823917715299139499110],
|
||||
["tact-examples/jetton_JettonDefaultWallet.code.fc", 29421313492520031238091587108198906058157443241743283101866538036369069620563],
|
||||
["tact-examples/maps_MapTestContract.code.fc", 22556550222249123835909180266811414538971143565993192846012583552876721649744],
|
||||
["tact-examples/treasure_Treasure.code.fc", 13962538639825790677138656603323869918938565499584297120566680287245364723897],
|
||||
["tact-examples/jetton_SampleJetton.code.fc", 94076762218493729104783735200107713211245710256802265203823917715299139499110],
|
||||
["tact-examples/jetton_JettonDefaultWallet.code.fc", 29421313492520031238091587108198906058157443241743283101866538036369069620563],
|
||||
["tact-examples/maps_MapTestContract.code.fc", 22556550222249123835909180266811414538971143565993192846012583552876721649744],
|
||||
]
|
||||
|
||||
def getenv(name, default=None):
|
||||
|
@ -51,7 +51,6 @@ def getenv(name, default=None):
|
|||
|
||||
FUNC_EXECUTABLE = getenv("FUNC_EXECUTABLE", "func")
|
||||
FIFT_EXECUTABLE = getenv("FIFT_EXECUTABLE", "fift")
|
||||
FIFT_LIBS = getenv("FIFTPATH")
|
||||
TMP_DIR = tempfile.mkdtemp()
|
||||
|
||||
COMPILED_FIF = os.path.join(TMP_DIR, "compiled.fif")
|
||||
|
@ -63,49 +62,49 @@ class ExecutionError(Exception):
|
|||
pass
|
||||
|
||||
def pre_process_func(f):
|
||||
shutil.copyfile(f, f+"_backup")
|
||||
with open(f, "r") as src:
|
||||
sources = src.read()
|
||||
with open(f, "w") as src:
|
||||
for pragma in add_pragmas:
|
||||
src.write("#pragma %s;\n"%pragma)
|
||||
src.write(sources)
|
||||
shutil.copyfile(f, f+"_backup")
|
||||
with open(f, "r") as src:
|
||||
sources = src.read()
|
||||
with open(f, "w") as src:
|
||||
for pragma in add_pragmas:
|
||||
src.write("#pragma %s;\n"%pragma)
|
||||
src.write(sources)
|
||||
|
||||
def post_process_func(f):
|
||||
shutil.move(f+"_backup", f)
|
||||
shutil.move(f+"_backup", f)
|
||||
|
||||
def compile_func(f):
|
||||
res = None
|
||||
try:
|
||||
pre_process_func(f)
|
||||
if "storage-provider.fc" in f :
|
||||
# This contract requires building of storage-contract to include it as ref
|
||||
with open(f, "r") as src:
|
||||
sources = src.read()
|
||||
# This contract requires building of storage-contract to include it as ref
|
||||
with open(f, "r") as src:
|
||||
sources = src.read()
|
||||
COMPILED_ST_BOC = os.path.join(TMP_DIR, "storage-contract-code.boc")
|
||||
sources = sources.replace("storage-contract-code.boc", COMPILED_ST_BOC)
|
||||
with open(f, "w") as src:
|
||||
src.write(sources)
|
||||
COMPILED_ST_FIF = os.path.join(TMP_DIR, "storage-contract.fif")
|
||||
COMPILED_ST_BOC = os.path.join(TMP_DIR, "storage-contract-code.boc")
|
||||
sources = sources.replace("storage-contract-code.boc", COMPILED_ST_BOC)
|
||||
with open(f, "w") as src:
|
||||
src.write(sources)
|
||||
COMPILED_ST_FIF = os.path.join(TMP_DIR, "storage-contract.fif")
|
||||
COMPILED_ST_BOC = os.path.join(TMP_DIR, "storage-contract-code.boc")
|
||||
COMPILED_BUILD_BOC = os.path.join(TMP_DIR, "build-boc.fif")
|
||||
res = subprocess.run([FUNC_EXECUTABLE, "-o", COMPILED_ST_FIF, "-SPA", f.replace("storage-provider.fc","storage-contract.fc")], capture_output=False, timeout=10)
|
||||
with open(COMPILED_BUILD_BOC, "w") as scr:
|
||||
scr.write("\"%s\" include boc>B \"%s\" B>file "%(COMPILED_ST_FIF, COMPILED_ST_BOC))
|
||||
res = subprocess.run([FIFT_EXECUTABLE, COMPILED_BUILD_BOC ], capture_output=True, timeout=10)
|
||||
|
||||
|
||||
COMPILED_BUILD_BOC = os.path.join(TMP_DIR, "build-boc.fif")
|
||||
res = subprocess.run([FUNC_EXECUTABLE, "-o", COMPILED_ST_FIF, "-SPA", f.replace("storage-provider.fc","storage-contract.fc")], capture_output=False, timeout=10)
|
||||
with open(COMPILED_BUILD_BOC, "w") as scr:
|
||||
scr.write("\"%s\" include boc>B \"%s\" B>file "%(COMPILED_ST_FIF, COMPILED_ST_BOC))
|
||||
res = subprocess.run([FIFT_EXECUTABLE, COMPILED_BUILD_BOC ], capture_output=True, timeout=10)
|
||||
|
||||
|
||||
res = subprocess.run([FUNC_EXECUTABLE, "-o", COMPILED_FIF, "-SPA", f], capture_output=True, timeout=10)
|
||||
except Exception as e:
|
||||
post_process_func(f)
|
||||
raise e
|
||||
post_process_func(f)
|
||||
raise e
|
||||
else:
|
||||
post_process_func(f)
|
||||
post_process_func(f)
|
||||
if res.returncode != 0:
|
||||
raise ExecutionError(str(res.stderr, "utf-8"))
|
||||
|
||||
def run_runner():
|
||||
res = subprocess.run([FIFT_EXECUTABLE, "-I", FIFT_LIBS, RUNNER_FIF], capture_output=True, timeout=10)
|
||||
res = subprocess.run([FIFT_EXECUTABLE, RUNNER_FIF], capture_output=True, timeout=10)
|
||||
if res.returncode != 0:
|
||||
raise ExecutionError(str(res.stderr, "utf-8"))
|
||||
s = str(res.stdout, "utf-8")
|
||||
|
@ -138,16 +137,15 @@ for ti, t in enumerate(tests):
|
|||
try:
|
||||
func_out = run_runner()
|
||||
if func_out != th:
|
||||
raise ExecutionError("Error : expected '%d', found '%d'" % (th, func_out))
|
||||
raise ExecutionError("Error : expected '%d', found '%d'" % (th, func_out))
|
||||
success += 1
|
||||
except ExecutionError as e:
|
||||
print(e, file=sys.stderr)
|
||||
#print("Compiled:", file=sys.stderr)
|
||||
#with open(COMPILED_FIF, "r") as f:
|
||||
# print(f.read(), file=sys.stderr)
|
||||
#exit(2)
|
||||
print("Compiled:", file=sys.stderr)
|
||||
with open(COMPILED_FIF, "r") as f:
|
||||
print(f.read(), file=sys.stderr)
|
||||
exit(2)
|
||||
print(" OK ", file=sys.stderr)
|
||||
|
||||
print(get_version())
|
||||
print("Done: Success %d, Error: %d"%(success, len(tests)-success), file=sys.stderr)
|
||||
|
||||
print("Done: Success %d, Error: %d"%(success, len(tests)-success), file=sys.stderr)
|
|
@ -4,6 +4,7 @@ import subprocess
|
|||
import sys
|
||||
import tempfile
|
||||
|
||||
|
||||
def getenv(name, default=None):
|
||||
if name in os.environ:
|
||||
return os.environ[name]
|
||||
|
@ -12,10 +13,9 @@ def getenv(name, default=None):
|
|||
exit(1)
|
||||
return default
|
||||
|
||||
|
||||
FUNC_EXECUTABLE = getenv("FUNC_EXECUTABLE", "func")
|
||||
FIFT_EXECUTABLE = getenv("FIFT_EXECUTABLE", "fift")
|
||||
#FUNC_STDLIB = getenv("FUNC_STDLIB")
|
||||
FIFT_LIBS = getenv("FIFT_LIBS")
|
||||
TMP_DIR = tempfile.mkdtemp()
|
||||
COMPILED_FIF = os.path.join(TMP_DIR, "compiled.fif")
|
||||
RUNNER_FIF = os.path.join(TMP_DIR, "runner.fif")
|
||||
|
@ -25,22 +25,26 @@ if len(sys.argv) != 2:
|
|||
exit(1)
|
||||
TESTS_DIR = sys.argv[1]
|
||||
|
||||
|
||||
class ExecutionError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
def compile_func(f):
|
||||
res = subprocess.run([FUNC_EXECUTABLE, "-o", COMPILED_FIF, "-SPA", f], capture_output=True, timeout=10)
|
||||
if res.returncode != 0:
|
||||
raise ExecutionError(str(res.stderr, "utf-8"))
|
||||
|
||||
|
||||
def run_runner():
|
||||
res = subprocess.run([FIFT_EXECUTABLE, "-I", FIFT_LIBS, RUNNER_FIF], capture_output=True, timeout=10)
|
||||
res = subprocess.run([FIFT_EXECUTABLE, RUNNER_FIF], capture_output=True, timeout=10)
|
||||
if res.returncode != 0:
|
||||
raise ExecutionError(str(res.stderr, "utf-8"))
|
||||
s = str(res.stdout, "utf-8")
|
||||
s = [x.strip() for x in s.split("\n")]
|
||||
return [x for x in s if x != ""]
|
||||
|
||||
|
||||
tests = [s for s in os.listdir(TESTS_DIR) if s.endswith(".fc")]
|
||||
tests.sort()
|
||||
print("Found", len(tests), "tests", file=sys.stderr)
|
||||
|
@ -68,18 +72,18 @@ for ti, tf in enumerate(tests):
|
|||
|
||||
# preprocess arithmetics in input
|
||||
for i in range(len(cases)):
|
||||
inputs = cases[i][1].split(" ")
|
||||
processed_inputs = ""
|
||||
for in_arg in inputs:
|
||||
if "x{" in in_arg:
|
||||
processed_inputs += in_arg
|
||||
continue
|
||||
# filter and execute
|
||||
# is it safe enough?
|
||||
filtered_in = "".join(filter(lambda x: x in "0x123456789()+-*/<>", in_arg))
|
||||
if(filtered_in):
|
||||
processed_inputs += str(eval(filtered_in)) + " ";
|
||||
cases[i][1] = processed_inputs.strip()
|
||||
inputs = cases[i][1].split(" ")
|
||||
processed_inputs = ""
|
||||
for in_arg in inputs:
|
||||
if "x{" in in_arg:
|
||||
processed_inputs += in_arg
|
||||
continue
|
||||
# filter and execute
|
||||
# is it safe enough?
|
||||
filtered_in = "".join(filter(lambda x: x in "0x123456789()+-*/<>", in_arg))
|
||||
if filtered_in:
|
||||
processed_inputs += str(eval(filtered_in)) + " "
|
||||
cases[i][1] = processed_inputs.strip()
|
||||
|
||||
with open(RUNNER_FIF, "w") as f:
|
||||
print("\"%s\" include <s constant code" % COMPILED_FIF, file=f)
|
||||
|
@ -103,4 +107,4 @@ for ti, tf in enumerate(tests):
|
|||
exit(2)
|
||||
print(" OK, %d cases" % len(cases), file=sys.stderr)
|
||||
|
||||
print("Done", file=sys.stderr)
|
||||
print("Done", file=sys.stderr)
|
|
@ -232,6 +232,7 @@ Bignum& Bignum::import_lsb(const unsigned char* buffer, std::size_t size) {
|
|||
|
||||
std::string Bignum::to_str() const {
|
||||
char* ptr = BN_bn2dec(val);
|
||||
CHECK(ptr);
|
||||
std::string z(ptr);
|
||||
OPENSSL_free(ptr);
|
||||
return z;
|
||||
|
@ -239,6 +240,7 @@ std::string Bignum::to_str() const {
|
|||
|
||||
std::string Bignum::to_hex() const {
|
||||
char* ptr = BN_bn2hex(val);
|
||||
CHECK(ptr);
|
||||
std::string z(ptr);
|
||||
OPENSSL_free(ptr);
|
||||
return z;
|
||||
|
@ -255,7 +257,13 @@ std::istream& operator>>(std::istream& is, Bignum& x) {
|
|||
return is;
|
||||
}
|
||||
|
||||
bool is_prime(const Bignum& p, int nchecks, bool trial_div) {
|
||||
return BN_is_prime_fasttest_ex(p.bn_ptr(), BN_prime_checks, get_ctx(), trial_div, 0);
|
||||
bool is_prime(const Bignum& p) {
|
||||
#if OPENSSL_VERSION_MAJOR >= 3
|
||||
int result = BN_check_prime(p.bn_ptr(), get_ctx(), nullptr);
|
||||
LOG_IF(FATAL, result == -1);
|
||||
return result;
|
||||
#else
|
||||
return BN_is_prime_fasttest_ex(p.bn_ptr(), BN_prime_checks, get_ctx(), true, 0);
|
||||
#endif
|
||||
}
|
||||
} // namespace arith
|
||||
|
|
|
@ -335,7 +335,7 @@ const Bignum sqr(const Bignum& x);
|
|||
std::ostream& operator<<(std::ostream& os, const Bignum& x);
|
||||
std::istream& operator>>(std::istream& is, Bignum& x);
|
||||
|
||||
bool is_prime(const Bignum& p, int nchecks = 64, bool trial_div = true);
|
||||
bool is_prime(const Bignum& p);
|
||||
|
||||
inline int cmp(const Bignum& x, const Bignum& y) {
|
||||
return BN_cmp(x.bn_ptr(), y.bn_ptr());
|
||||
|
|
|
@ -250,7 +250,6 @@ const Lexem& Lexer::next() {
|
|||
}
|
||||
if (is_multiline_quote(src.get_ptr(), src.get_end_ptr())) {
|
||||
src.advance(multiline_quote.size());
|
||||
const char* begin = src.get_ptr();
|
||||
const char* end = nullptr;
|
||||
SrcLocation here = src.here();
|
||||
std::string body;
|
||||
|
|
|
@ -305,7 +305,7 @@ class ManualDns : public ton::SmartContract, public DnsInterface {
|
|||
if (!info.known_category.insert(action.category).second) {
|
||||
continue;
|
||||
}
|
||||
if (action.category == 0) {
|
||||
if (action.category.is_zero()) {
|
||||
info.closed = true;
|
||||
auto old_actions = std::move(info.actions);
|
||||
bool is_empty = true;
|
||||
|
@ -327,7 +327,7 @@ class ManualDns : public ton::SmartContract, public DnsInterface {
|
|||
if (info.closed) {
|
||||
CombinedActions<ActionT> ca;
|
||||
ca.name = it.first;
|
||||
ca.category = 0;
|
||||
ca.category = td::Bits256::zero();
|
||||
if (!info.actions.empty() || info.non_empty) {
|
||||
ca.actions = std::move(info.actions);
|
||||
}
|
||||
|
|
|
@ -181,7 +181,7 @@ SmartContract::Answer run_smartcont(SmartContract::State state, td::Ref<vm::Stac
|
|||
int vm_log_verbosity, bool debug_enabled,
|
||||
std::shared_ptr<const block::Config> config) {
|
||||
auto gas_credit = gas.gas_credit;
|
||||
vm::init_op_cp0(debug_enabled);
|
||||
vm::init_vm(debug_enabled).ensure();
|
||||
vm::DictionaryBase::get_empty_dictionary();
|
||||
|
||||
class Logger : public td::LogInterface {
|
||||
|
|
|
@ -33,7 +33,7 @@ std::string load_test(std::string name) {
|
|||
return td::read_file_str(current_dir() + "fift/" + name).move_as_ok();
|
||||
}
|
||||
|
||||
td::Status run_fift(std::string name, bool expect_error = false, bool preload_fift = true) {
|
||||
td::Status run_fift(std::string name, bool expect_error = false) {
|
||||
auto res = fift::mem_run_fift(load_test(name));
|
||||
if (expect_error) {
|
||||
res.ensure_error();
|
||||
|
|
|
@ -9,6 +9,9 @@
|
|||
[[ <{ RIST255_MULBASE DUP RIST255_VALIDATE }>s ]] 0 runvmx abort"Exitcode != 0"
|
||||
@' n . dup (x.) type cr
|
||||
@' ans <> abort"Invalid result"
|
||||
@' n
|
||||
[[ <{ 1 INT RIST255_MULBASE SWAP RIST255_MUL DUP RIST255_VALIDATE }>s ]] 0 runvmx abort"Exitcode != 0"
|
||||
@' ans <> abort"Invalid result"
|
||||
} : test-basepoint
|
||||
|
||||
0 0x0000000000000000000000000000000000000000000000000000000000000000 test-basepoint
|
||||
|
|
|
@ -180,7 +180,7 @@ struct MixedRadix {
|
|||
|
||||
template <int M>
|
||||
const MixedRadix<M>& as_shorter() const {
|
||||
static_assert(M <= N);
|
||||
static_assert(M <= N,"error");
|
||||
return *reinterpret_cast<const MixedRadix<M>*>(this);
|
||||
}
|
||||
|
||||
|
@ -458,7 +458,7 @@ struct ModArray {
|
|||
}
|
||||
template <int M>
|
||||
ModArray(const ModArray<M>& other) {
|
||||
static_assert(M >= N);
|
||||
static_assert(M >= N,"error");
|
||||
std::copy(other.a, other.a + N, a);
|
||||
}
|
||||
ModArray(const int* p) : a(p) {
|
||||
|
@ -819,7 +819,7 @@ struct ModArray {
|
|||
|
||||
template <int M>
|
||||
const ModArray<M>& as_shorter() const {
|
||||
static_assert(M <= N);
|
||||
static_assert(M <= N,"error");
|
||||
return *reinterpret_cast<const ModArray<M>*>(this);
|
||||
}
|
||||
|
||||
|
|
|
@ -16,12 +16,12 @@
|
|||
*/
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <array>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <random>
|
||||
#include <getopt.h>
|
||||
#include "common/refcnt.hpp"
|
||||
#include "common/bigint.hpp"
|
||||
#include "common/refint.h"
|
||||
|
@ -211,7 +211,7 @@ bool coin() {
|
|||
|
||||
// returns 0 with probability 1/2, 1 with prob. 1/4, ..., k with prob. 1/2^(k+1)
|
||||
int randexp(int max = 63, int min = 0) {
|
||||
return min + __builtin_clzll(Random() | (1ULL << (63 - max + min)));
|
||||
return min + td::count_leading_zeroes64(Random() | (1ULL << (63 - max + min)));
|
||||
}
|
||||
|
||||
void bin_add_small(unsigned char bin[64], long long val, int shift = 0) {
|
||||
|
@ -363,7 +363,7 @@ void check_one_int_repr(td::RefInt256 x, int mode, int in_range, const BInt* val
|
|||
if (is_small) {
|
||||
// special check for small (64-bit) values
|
||||
CHECK(x->to_long() == xval);
|
||||
CHECK((long long)__builtin_bswap64(*(long long*)(bytes + 64 - 8)) == xval);
|
||||
CHECK((long long)td::bswap64(*(long long*)(bytes + 64 - 8)) == xval);
|
||||
CHECK(in_range);
|
||||
// check sign
|
||||
CHECK(x->sgn() == (xval > 0 ? 1 : (xval < 0 ? -1 : 0)));
|
||||
|
|
|
@ -127,12 +127,12 @@ class BenchSha256Low : public td::Benchmark {
|
|||
|
||||
void run(int n) override {
|
||||
int res = 0;
|
||||
SHA256_CTX ctx;
|
||||
td::Sha256State ctx;
|
||||
for (int i = 0; i < n; i++) {
|
||||
SHA256_Init(&ctx);
|
||||
SHA256_Update(&ctx, "abcd", 4);
|
||||
ctx.init();
|
||||
ctx.feed("abcd");
|
||||
unsigned char buf[32];
|
||||
SHA256_Final(buf, &ctx);
|
||||
ctx.extract(td::MutableSlice{buf, 32});
|
||||
res += buf[0];
|
||||
}
|
||||
td::do_not_optimize_away(res);
|
||||
|
|
|
@ -958,7 +958,7 @@ class MapDns {
|
|||
}
|
||||
return;
|
||||
}
|
||||
if (!actions.category.is_zero()) {
|
||||
if (actions.category.is_zero()) {
|
||||
entries_.erase(actions.name);
|
||||
LOG(ERROR) << "CLEAR " << actions.name;
|
||||
if (!actions.actions) {
|
||||
|
@ -1003,7 +1003,7 @@ class CheckedDns {
|
|||
explicit CheckedDns(bool check_smc = true, bool check_combine = true) {
|
||||
if (check_smc) {
|
||||
key_ = td::Ed25519::generate_private_key().move_as_ok();
|
||||
dns_ = ManualDns::create(ManualDns::create_init_data_fast(key_.value().get_public_key().move_as_ok(), 123));
|
||||
dns_ = ManualDns::create(ManualDns::create_init_data_fast(key_.value().get_public_key().move_as_ok(), 123), -1);
|
||||
}
|
||||
if (check_combine) {
|
||||
combined_map_dns_ = MapDns();
|
||||
|
@ -1094,9 +1094,10 @@ class CheckedDns {
|
|||
}
|
||||
};
|
||||
|
||||
static td::Bits256 intToCat(int x) {
|
||||
td::Bits256 cat = td::Bits256::zero();
|
||||
cat.as_slice().copy_from(td::Slice((char*)&x, sizeof(x)));
|
||||
static td::Bits256 intToCat(td::uint32 x) {
|
||||
auto y = td::make_refint(x);
|
||||
td::Bits256 cat;
|
||||
y->export_bytes(cat.data(), 32, false);
|
||||
return cat;
|
||||
}
|
||||
|
||||
|
@ -1182,7 +1183,7 @@ TEST(Smartcont, DnsManual) {
|
|||
|
||||
auto key = td::Ed25519::generate_private_key().move_as_ok();
|
||||
|
||||
auto manual = ManualDns::create(ManualDns::create_init_data_fast(key.get_public_key().move_as_ok(), 123));
|
||||
auto manual = ManualDns::create(ManualDns::create_init_data_fast(key.get_public_key().move_as_ok(), 123), -1);
|
||||
CHECK(manual->get_wallet_id().move_as_ok() == 123);
|
||||
auto init_query = manual->create_init_query(key).move_as_ok();
|
||||
LOG(ERROR) << "A";
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
#include "td/utils/StringBuilder.h"
|
||||
|
||||
std::string run_vm(td::Ref<vm::Cell> cell) {
|
||||
vm::init_op_cp0();
|
||||
vm::init_vm().ensure();
|
||||
vm::DictionaryBase::get_empty_dictionary();
|
||||
|
||||
class Logger : public td::LogInterface {
|
||||
|
|
|
@ -159,7 +159,6 @@ std::string CppIdentSet::compute_cpp_ident(std::string orig_ident, int count) {
|
|||
}
|
||||
if (!cnt) {
|
||||
os << '_';
|
||||
prev_skip = true;
|
||||
}
|
||||
if (count) {
|
||||
os << count;
|
||||
|
|
|
@ -2252,11 +2252,9 @@ TypeExpr* parse_expr10(Lexer& lex, Constructor& cs, int mode) {
|
|||
}
|
||||
if (op == '>') {
|
||||
std::swap(expr, expr2);
|
||||
op = '<';
|
||||
op_name = Less_name;
|
||||
} else if (op == src::_Geq) {
|
||||
std::swap(expr, expr2);
|
||||
op = src::_Leq;
|
||||
op_name = Leq_name;
|
||||
}
|
||||
auto sym_def = sym::lookup_symbol(op_name, 2);
|
||||
|
|
|
@ -285,8 +285,11 @@ int exec_divmod(VmState* st, unsigned args, int quiet) {
|
|||
typename td::BigInt256::DoubleInt tmp{*x}, quot;
|
||||
tmp += *w;
|
||||
tmp.mod_div(*y, quot, round_mode);
|
||||
stack.push_int_quiet(td::make_refint(quot), quiet);
|
||||
stack.push_int_quiet(td::make_refint(tmp), quiet);
|
||||
auto q = td::make_refint(quot), r = td::make_refint(tmp);
|
||||
q.write().normalize();
|
||||
r.write().normalize();
|
||||
stack.push_int_quiet(std::move(q), quiet);
|
||||
stack.push_int_quiet(std::move(r), quiet);
|
||||
} else {
|
||||
switch (d) {
|
||||
case 1:
|
||||
|
@ -399,6 +402,7 @@ std::string dump_shrmod(CellSlice&, unsigned args, int mode) {
|
|||
if (mode & 1) {
|
||||
os << 'Q';
|
||||
}
|
||||
std::string end;
|
||||
switch (args & 12) {
|
||||
case 4:
|
||||
os << "RSHIFT";
|
||||
|
@ -407,17 +411,22 @@ std::string dump_shrmod(CellSlice&, unsigned args, int mode) {
|
|||
os << "MODPOW2";
|
||||
break;
|
||||
case 12:
|
||||
os << "RSHIFTMOD";
|
||||
os << "RSHIFT";
|
||||
end = "MOD";
|
||||
break;
|
||||
case 0:
|
||||
os << "ADDRSHIFTMOD";
|
||||
os << "ADDRSHIFT";
|
||||
end = "MOD";
|
||||
break;
|
||||
}
|
||||
if (!(mode & 2)) {
|
||||
os << end;
|
||||
}
|
||||
if (round_mode) {
|
||||
os << "FRC"[round_mode];
|
||||
}
|
||||
if (mode & 2) {
|
||||
os << ' ' << y;
|
||||
os << "#" << end << ' ' << y;
|
||||
}
|
||||
return os.str();
|
||||
}
|
||||
|
@ -519,7 +528,7 @@ int exec_mulshrmod(VmState* st, unsigned args, int mode) {
|
|||
if (add) {
|
||||
tmp = *w;
|
||||
}
|
||||
tmp.add_mul(*x, *y);
|
||||
tmp.add_mul(*x, *y).normalize();
|
||||
switch (d) {
|
||||
case 1:
|
||||
tmp.rshift(z, round_mode).normalize();
|
||||
|
@ -553,6 +562,7 @@ std::string dump_mulshrmod(CellSlice&, unsigned args, int mode) {
|
|||
if (mode & 1) {
|
||||
os << 'Q';
|
||||
}
|
||||
std::string end;
|
||||
switch (args & 12) {
|
||||
case 4:
|
||||
os << "MULRSHIFT";
|
||||
|
@ -561,15 +571,21 @@ std::string dump_mulshrmod(CellSlice&, unsigned args, int mode) {
|
|||
os << "MULMODPOW2";
|
||||
break;
|
||||
case 12:
|
||||
os << "MULRSHIFTMOD";
|
||||
os << "MULRSHIFT";
|
||||
end = "MOD";
|
||||
break;
|
||||
case 0:
|
||||
os << "MULADDRSHIFTMOD";
|
||||
os << "MULADDRSHIFT";
|
||||
end = "MOD";
|
||||
break;
|
||||
}
|
||||
if (round_mode) {
|
||||
os << "FRC"[round_mode];
|
||||
}
|
||||
if (mode & 2) {
|
||||
os << "#";
|
||||
}
|
||||
os << end;
|
||||
if (mode & 2) {
|
||||
os << ' ' << y;
|
||||
}
|
||||
|
@ -644,18 +660,22 @@ std::string dump_shldivmod(CellSlice&, unsigned args, int mode) {
|
|||
if (mode & 1) {
|
||||
os << "Q";
|
||||
}
|
||||
os << "LSHIFT";
|
||||
if (mode & 2) {
|
||||
os << "#";
|
||||
}
|
||||
switch (args & 12) {
|
||||
case 4:
|
||||
os << "LSHIFTDIV";
|
||||
os << "DIV";
|
||||
break;
|
||||
case 8:
|
||||
os << "LSHIFTMOD";
|
||||
os << "MOD";
|
||||
break;
|
||||
case 12:
|
||||
os << "LSHIFTDIVMOD";
|
||||
os << "DIVMOD";
|
||||
break;
|
||||
case 0:
|
||||
os << "LSHIFTADDDIVMOD";
|
||||
os << "ADDDIVMOD";
|
||||
break;
|
||||
}
|
||||
if (round_mode) {
|
||||
|
|
|
@ -101,7 +101,7 @@ void register_basic_gas_ops(OpcodeTable& cp0) {
|
|||
using namespace std::placeholders;
|
||||
cp0.insert(OpcodeInstr::mksimple(0xf800, 16, "ACCEPT", exec_accept))
|
||||
.insert(OpcodeInstr::mksimple(0xf801, 16, "SETGASLIMIT", exec_set_gas_limit))
|
||||
.insert(OpcodeInstr::mksimple(0xf802, 16, "GASCONSUMED", exec_gas_consumed)->require_version(4))
|
||||
.insert(OpcodeInstr::mksimple(0xf806, 16, "GASCONSUMED", exec_gas_consumed)->require_version(4))
|
||||
.insert(OpcodeInstr::mksimple(0xf80f, 16, "COMMIT", exec_commit));
|
||||
}
|
||||
|
||||
|
@ -620,7 +620,6 @@ int exec_ristretto255_from_hash(VmState* st) {
|
|||
if (!x2->export_bytes(xb + 32, 32, false)) {
|
||||
throw VmError{Excno::range_chk, "x2 must fit in an unsigned 256-bit integer"};
|
||||
}
|
||||
CHECK(sodium_init() >= 0);
|
||||
crypto_core_ristretto255_from_hash(rb, xb);
|
||||
td::RefInt256 r{true};
|
||||
CHECK(r.write().import_bytes(rb, 32, false));
|
||||
|
@ -633,8 +632,7 @@ int exec_ristretto255_validate(VmState* st, bool quiet) {
|
|||
Stack& stack = st->get_stack();
|
||||
auto x = stack.pop_int();
|
||||
st->consume_gas(VmState::rist255_validate_gas_price);
|
||||
unsigned char xb[64];
|
||||
CHECK(sodium_init() >= 0);
|
||||
unsigned char xb[32];
|
||||
if (!x->export_bytes(xb, 32, false) || !crypto_core_ristretto255_is_valid_point(xb)) {
|
||||
if (quiet) {
|
||||
stack.push_bool(false);
|
||||
|
@ -656,7 +654,6 @@ int exec_ristretto255_add(VmState* st, bool quiet) {
|
|||
auto x = stack.pop_int();
|
||||
st->consume_gas(VmState::rist255_add_gas_price);
|
||||
unsigned char xb[32], yb[32], rb[32];
|
||||
CHECK(sodium_init() >= 0);
|
||||
if (!x->export_bytes(xb, 32, false) || !y->export_bytes(yb, 32, false) || crypto_core_ristretto255_add(rb, xb, yb)) {
|
||||
if (quiet) {
|
||||
stack.push_bool(false);
|
||||
|
@ -681,7 +678,6 @@ int exec_ristretto255_sub(VmState* st, bool quiet) {
|
|||
auto x = stack.pop_int();
|
||||
st->consume_gas(VmState::rist255_add_gas_price);
|
||||
unsigned char xb[32], yb[32], rb[32];
|
||||
CHECK(sodium_init() >= 0);
|
||||
if (!x->export_bytes(xb, 32, false) || !y->export_bytes(yb, 32, false) || crypto_core_ristretto255_sub(rb, xb, yb)) {
|
||||
if (quiet) {
|
||||
stack.push_bool(false);
|
||||
|
@ -719,17 +715,20 @@ int exec_ristretto255_mul(VmState* st, bool quiet) {
|
|||
auto n = stack.pop_int() % get_ristretto256_l();
|
||||
auto x = stack.pop_int();
|
||||
st->consume_gas(VmState::rist255_mul_gas_price);
|
||||
unsigned char xb[32], nb[32], rb[32];
|
||||
memset(rb, 255, sizeof(rb));
|
||||
CHECK(sodium_init() >= 0);
|
||||
if (!x->export_bytes(xb, 32, false) || !export_bytes_little(n, nb) || crypto_scalarmult_ristretto255(rb, nb, xb)) {
|
||||
if (std::all_of(rb, rb + 32, [](unsigned char c) { return c == 255; })) {
|
||||
if (quiet) {
|
||||
stack.push_bool(false);
|
||||
return 0;
|
||||
}
|
||||
throw VmError{Excno::range_chk, "invalid x or n"};
|
||||
if (n->sgn() == 0) {
|
||||
stack.push_smallint(0);
|
||||
if (quiet) {
|
||||
stack.push_bool(true);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
unsigned char xb[32], nb[32], rb[32];
|
||||
if (!x->export_bytes(xb, 32, false) || !export_bytes_little(n, nb) || crypto_scalarmult_ristretto255(rb, nb, xb)) {
|
||||
if (quiet) {
|
||||
stack.push_bool(false);
|
||||
return 0;
|
||||
}
|
||||
throw VmError{Excno::range_chk, "invalid x or n"};
|
||||
}
|
||||
td::RefInt256 r{true};
|
||||
CHECK(r.write().import_bytes(rb, 32, false));
|
||||
|
@ -747,7 +746,6 @@ int exec_ristretto255_mul_base(VmState* st, bool quiet) {
|
|||
st->consume_gas(VmState::rist255_mulbase_gas_price);
|
||||
unsigned char nb[32], rb[32];
|
||||
memset(rb, 255, sizeof(rb));
|
||||
CHECK(sodium_init() >= 0);
|
||||
if (!export_bytes_little(n, nb) || crypto_scalarmult_ristretto255_base(rb, nb)) {
|
||||
if (std::all_of(rb, rb + 32, [](unsigned char c) { return c == 255; })) {
|
||||
if (quiet) {
|
||||
|
@ -833,7 +831,7 @@ int exec_bls_verify(VmState* st) {
|
|||
VM_LOG(st) << "execute BLS_VERIFY";
|
||||
Stack& stack = st->get_stack();
|
||||
stack.check_underflow(3);
|
||||
st->consume_gas(st->bls_verify_gas_price);
|
||||
st->consume_gas(VmState::bls_verify_gas_price);
|
||||
bls::P2 sig = slice_to_bls_p2(*stack.pop_cellslice());
|
||||
td::BufferSlice msg = slice_to_bls_msg(*stack.pop_cellslice());
|
||||
bls::P1 pub = slice_to_bls_p1(*stack.pop_cellslice());
|
||||
|
@ -845,8 +843,7 @@ int exec_bls_aggregate(VmState* st) {
|
|||
VM_LOG(st) << "execute BLS_AGGREGATE";
|
||||
Stack& stack = st->get_stack();
|
||||
int n = stack.pop_smallint_range(stack.depth() - 1, 1);
|
||||
st->consume_gas(
|
||||
std::max(0LL, VmState::bls_aggregate_base_gas_price + (long long)n * VmState::bls_aggregate_element_gas_price));
|
||||
st->consume_gas(VmState::bls_aggregate_base_gas_price + (long long)n * VmState::bls_aggregate_element_gas_price);
|
||||
std::vector<bls::P2> sigs(n);
|
||||
for (int i = n - 1; i >= 0; --i) {
|
||||
sigs[i] = slice_to_bls_p2(*stack.pop_cellslice());
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
#include "vm/dict.h"
|
||||
#include "vm/log.h"
|
||||
#include "vm/vm.h"
|
||||
#include "cp0.h"
|
||||
#include <sodium.h>
|
||||
|
||||
namespace vm {
|
||||
|
||||
|
@ -770,4 +772,15 @@ void VmState::restore_parent_vm(int res) {
|
|||
}
|
||||
}
|
||||
|
||||
td::Status init_vm(bool enable_debug) {
|
||||
if (!init_op_cp0(enable_debug)) {
|
||||
return td::Status::Error("Failed to init TVM: failed to init cp0");
|
||||
}
|
||||
auto code = sodium_init();
|
||||
if (code < 0) {
|
||||
return td::Status::Error(PSTRING() << "Failed to init TVM: sodium_init, code=" << code);
|
||||
}
|
||||
return td::Status::OK();
|
||||
}
|
||||
|
||||
} // namespace vm
|
||||
|
|
|
@ -423,4 +423,6 @@ int run_vm_code(Ref<CellSlice> _code, Stack& _stack, int flags = 0, Ref<Cell>* d
|
|||
|
||||
Ref<vm::Cell> lookup_library_in(td::ConstBitPtr key, Ref<vm::Cell> lib_root);
|
||||
|
||||
td::Status init_vm(bool enable_debug = false);
|
||||
|
||||
} // namespace vm
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue