├── test ├── contracts │ ├── bad-empty │ │ ├── bad-empty.export │ │ ├── bad-empty.c │ │ ├── multiversx.json │ │ └── output │ │ │ ├── bad-empty.wasm │ │ │ └── bad-empty.wat │ ├── counter │ │ ├── multiversx.json │ │ ├── counter.export │ │ ├── output │ │ │ └── counter.wasm │ │ └── counter.c │ ├── init-simple │ │ ├── init-simple.export │ │ ├── init-simple.c │ │ ├── multiversx.json │ │ └── output │ │ │ └── init-simple.wasm │ ├── init-wrong │ │ ├── init-wrong.export │ │ ├── init-wrong.c │ │ ├── multiversx.json │ │ └── output │ │ │ └── init-wrong.wasm │ ├── answer │ │ ├── answer.export │ │ ├── multiversx.json │ │ ├── answer.c │ │ └── output │ │ │ └── answer.wasm │ ├── breakpoint │ │ ├── breakpoint.export │ │ ├── multiversx.json │ │ ├── output │ │ │ ├── breakpoint.imports.json │ │ │ └── breakpoint.wasm │ │ └── breakpoint.c │ ├── deployer-child │ │ ├── deployer-child.export │ │ ├── multiversx.json │ │ ├── output │ │ │ └── deployer-child.wasm │ │ └── deployer-child.c │ ├── deployer-parent │ │ ├── deployer-parent.export │ │ ├── output │ │ │ └── deployer-parent.wasm │ │ └── multiversx.json │ ├── deployer │ │ ├── deployer.export │ │ ├── multiversx.json │ │ ├── output │ │ │ └── deployer.wasm │ │ └── deployer.c │ ├── misc │ │ ├── misc.export │ │ ├── multiversx.json │ │ ├── output │ │ │ └── misc.wasm │ │ └── misc.c │ ├── exec-dest-ctx-by-caller │ │ ├── child │ │ │ ├── child.export │ │ │ ├── multiversx.json │ │ │ ├── output │ │ │ │ └── child.wasm │ │ │ └── child.c │ │ └── parent │ │ │ ├── parent.export │ │ │ ├── multiversx.json │ │ │ ├── output │ │ │ └── parent.wasm │ │ │ └── parent.c │ ├── init-correct │ │ ├── init-correct.export │ │ ├── multiversx.json │ │ ├── output │ │ │ └── init-correct.wasm │ │ └── init-correct.c │ ├── opcodes │ │ ├── opcodes.export │ │ ├── multiversx.json │ │ ├── output │ │ │ └── opcodes.wasm │ │ └── opcodes.c │ ├── exec-dest-ctx-esdt │ │ └── basic │ │ │ ├── basic.export │ │ │ ├── output │ │ │ └── basic.wasm │ │ │ ├── multiversx.json │ │ │ └── basic.c │ ├── exec-sync-ctx-multiple │ │ ├── beta │ │ │ ├── beta.export │ │ │ ├── multiversx.json │ │ │ ├── output │ │ │ │ └── beta.wasm │ │ │ └── beta.c │ │ ├── delta │ │ │ ├── delta.export │ │ │ ├── multiversx.json │ │ │ ├── output │ │ │ │ └── delta.wasm │ │ │ └── delta.c │ │ ├── gamma │ │ │ ├── gamma.export │ │ │ ├── multiversx.json │ │ │ ├── output │ │ │ │ └── gamma.wasm │ │ │ └── gamma.c │ │ └── alpha │ │ │ ├── alpha.export │ │ │ ├── multiversx.json │ │ │ └── output │ │ │ └── alpha.wasm │ ├── memgrow-wrong │ │ ├── memgrow-wrong.export │ │ ├── multiversx.json │ │ ├── memgrow-wrong.c │ │ └── output │ │ │ └── memgrow-wrong.wasm │ ├── num-with-fp │ │ ├── num-with-fp.export │ │ ├── multiversx.json │ │ ├── output │ │ │ └── num-with-fp.wasm │ │ └── num-with-fp.c │ ├── bad-recursive │ │ ├── bad-recursive.export │ │ ├── output │ │ │ └── bad-recursive.wasm │ │ └── bad-recursive.c │ ├── exchange │ │ ├── multiversx.json │ │ ├── wasm │ │ │ └── src │ │ │ │ └── lib.rs │ │ ├── output │ │ │ └── exchange.wasm │ │ ├── .gitignore │ │ ├── snippets.sh │ │ └── src │ │ │ └── lib.rs │ ├── async-call-child-managed │ │ ├── async-call-child-managed.export │ │ ├── multiversx.json │ │ ├── async-call-child-managed.c │ │ └── output │ │ │ └── async-call-child-managed.wasm │ ├── async-call-child │ │ ├── async-call-child.export │ │ ├── multiversx.json │ │ └── output │ │ │ └── async-call-child.wasm │ ├── promises │ │ ├── tourist-tracking │ │ │ ├── trackingSystem.export │ │ │ ├── multiversx.json │ │ │ ├── output │ │ │ │ └── trackingSystem.wasm │ │ │ └── trackingSystem.c │ │ ├── child-simple │ │ │ ├── wasm │ │ │ │ └── src │ │ │ │ │ └── lib.rs │ │ │ ├── output │ │ │ │ └── child-simple.wasm │ │ │ └── src │ │ │ │ └── lib.rs │ │ ├── parent-simple │ │ │ ├── wasm │ │ │ │ └── src │ │ │ │ │ └── lib.rs │ │ │ └── output │ │ │ │ └── parent-simple.wasm │ │ ├── three-contracts │ │ │ ├── first-contract │ │ │ │ ├── wasm │ │ │ │ │ └── src │ │ │ │ │ │ └── lib.rs │ │ │ │ └── output │ │ │ │ │ └── first-contract.wasm │ │ │ ├── second-contract │ │ │ │ ├── wasm │ │ │ │ │ └── src │ │ │ │ │ │ └── lib.rs │ │ │ │ └── output │ │ │ │ │ └── second-contract.wasm │ │ │ └── third-contract │ │ │ │ ├── wasm │ │ │ │ └── src │ │ │ │ │ └── lib.rs │ │ │ │ └── output │ │ │ │ └── third-contract.wasm │ │ ├── tourist-bookings │ │ │ ├── bookings.export │ │ │ └── output │ │ │ │ └── bookings.wasm │ │ └── tourist-train │ │ │ ├── train.export │ │ │ └── output │ │ │ └── train.wasm │ ├── exec-same-ctx-simple-child │ │ ├── exec-same-ctx-simple-child.export │ │ ├── multiversx.json │ │ ├── output │ │ │ └── exec-same-ctx-simple-child.wasm │ │ └── exec-same-ctx-simple-child.c │ ├── async-call-parent-managed │ │ ├── async-call-parent-managed.export │ │ ├── multiversx.json │ │ ├── output │ │ │ └── async-call-parent-managed.wasm │ │ └── async-call-parent-managed.c │ ├── async-call-parent │ │ ├── async-call-parent.export │ │ ├── multiversx.json │ │ └── output │ │ │ └── async-call-parent.wasm │ ├── deployer-fromanother-contract │ │ ├── deployer.export │ │ ├── multiversx.json │ │ ├── output │ │ │ └── deployer-fromanother-contract.wasm │ │ └── deployer-fromanother-contract.c │ ├── upgrader-fromanother-contract │ │ ├── deployer.export │ │ ├── multiversx.json │ │ ├── output │ │ │ └── upgrader-fromanother-contract.wasm │ │ └── upgrader-fromanother-contract.c │ ├── async-call-builtin │ │ ├── async-call-builtin.export │ │ ├── multiversx.json │ │ ├── output │ │ │ └── async-call-builtin.wasm │ │ └── async-call-builtin.c │ ├── exec-dest-ctx-recursive-child │ │ ├── exec-dest-ctx-recursive-child.export │ │ ├── multiversx.json │ │ └── output │ │ │ └── exec-dest-ctx-recursive-child.wasm │ ├── exec-same-ctx-recursive-child │ │ ├── exec-same-ctx-recursive-child.export │ │ ├── multiversx.json │ │ └── output │ │ │ └── exec-same-ctx-recursive-child.wasm │ ├── exec-dest-ctx-recursive-parent │ │ ├── exec-dest-ctx-recursive-parent.export │ │ ├── multiversx.json │ │ └── output │ │ │ └── exec-dest-ctx-recursive-parent.wasm │ ├── exec-same-ctx-recursive-parent │ │ ├── exec-same-ctx-recursive-parent.export │ │ ├── multiversx.json │ │ └── output │ │ │ └── exec-same-ctx-recursive-parent.wasm │ ├── exec-same-ctx-simple-parent │ │ ├── exec-same-ctx-simple-parent.export │ │ ├── multiversx.json │ │ ├── output │ │ │ └── exec-same-ctx-simple-parent.wasm │ │ └── exec-same-ctx-simple-parent.c │ ├── timelocks │ │ ├── timelocks.export │ │ ├── multiversx.json │ │ ├── output │ │ │ └── timelocks.wasm │ │ └── timelocks.c │ ├── wasmbacking │ │ ├── memoryless │ │ │ └── output │ │ │ │ ├── memoryless.wasm │ │ │ │ └── memoryless.wat │ │ ├── mem-exceeded-pages │ │ │ └── output │ │ │ │ ├── mem-exceeded-pages.wasm │ │ │ │ └── mem-exceeded-pages.wat │ │ ├── mem-exceeded-max-pages │ │ │ └── output │ │ │ │ ├── mem-exceeded-max-pages.wasm │ │ │ │ └── mem-exceeded-max-pages.wat │ │ ├── multiple-memories │ │ │ └── output │ │ │ │ ├── multiple-memories.wasm │ │ │ │ └── multiple-memories.wat │ │ ├── mem-no-pages │ │ │ └── output │ │ │ │ ├── mem-no-pages.wasm │ │ │ │ └── mem-no-pages.wat │ │ ├── noglobals │ │ │ └── output │ │ │ │ ├── noglobals.wasm │ │ │ │ └── noglobals.wat │ │ ├── mem-single-page │ │ │ └── output │ │ │ │ ├── mem-single-page.wasm │ │ │ │ └── mem-single-page.wat │ │ ├── mem-no-max-pages │ │ │ └── output │ │ │ │ ├── mem-no-max-pages.wasm │ │ │ │ └── mem-no-max-pages.wat │ │ ├── mem-multiple-pages │ │ │ └── output │ │ │ │ ├── mem-multiple-pages.wasm │ │ │ │ └── mem-multiple-pages.wat │ │ ├── mem-min-pages-greater-than-max-pages │ │ │ └── output │ │ │ │ ├── mem-min-pages-greater-than-max-pages.wasm │ │ │ │ └── mem-min-pages-greater-than-max-pages.wat │ │ ├── mem-grow │ │ │ └── output │ │ │ │ ├── mem-grow.wasm │ │ │ │ └── mem-grow.wat │ │ ├── mem-multiple-max-pages │ │ │ └── output │ │ │ │ ├── mem-multiple-max-pages.wasm │ │ │ │ └── mem-multiple-max-pages.wat │ │ ├── middleware-globals │ │ │ └── output │ │ │ │ ├── middleware-globals.wasm │ │ │ │ └── middleware-globals.wat │ │ ├── imported-global │ │ │ └── output │ │ │ │ ├── imported-global.wasm │ │ │ │ └── imported-global.wat │ │ ├── mem-content │ │ │ └── output │ │ │ │ ├── mem-content.wasm │ │ │ │ └── mem-content.wat │ │ ├── single-mutable │ │ │ └── output │ │ │ │ ├── single-mutable.wasm │ │ │ │ └── single-mutable.wat │ │ ├── single-immutable │ │ │ └── output │ │ │ │ ├── single-immutable.wasm │ │ │ │ └── single-immutable.wat │ │ ├── mem-data-initializer │ │ │ └── output │ │ │ │ ├── mem-data-initializer.wasm │ │ │ │ └── mem-data-initializer.wat │ │ └── multiple-mutable │ │ │ └── output │ │ │ ├── multiple-mutable.wasm │ │ │ └── multiple-mutable.wat │ ├── signatures │ │ ├── signatures.export │ │ ├── multiversx.json │ │ ├── output │ │ │ ├── signatures.wasm │ │ │ └── signatures.wat │ │ └── signatures.c │ ├── async-promises-parent │ │ ├── async-promises-parent.export │ │ ├── multiversx.json │ │ └── output │ │ │ └── async-promises-parent.wasm │ ├── erc20 │ │ ├── multiversx.json │ │ ├── output │ │ │ ├── erc20.wasm │ │ │ └── erc20.imports.json │ │ └── erc20.export │ ├── exec-dest-ctx-child │ │ ├── exec-dest-ctx-child.export │ │ ├── multiversx.json │ │ └── output │ │ │ └── exec-dest-ctx-child.wasm │ ├── exec-same-ctx-child │ │ ├── exec-same-ctx-child.export │ │ ├── multiversx.json │ │ └── output │ │ │ └── exec-same-ctx-child.wasm │ ├── pair │ │ └── output │ │ │ ├── pair.wasm │ │ │ └── pair.imports.json │ ├── baseOps │ │ ├── multiversx.json │ │ ├── output │ │ │ └── baseOps.wasm │ │ └── baseOps.export │ ├── future │ │ └── hotel.c │ ├── bad-extra │ │ └── output │ │ │ └── bad-extra.wasm │ ├── bad-misc │ │ ├── output │ │ │ └── bad-misc.wasm │ │ └── bad-misc.export │ ├── big-floats │ │ ├── output │ │ │ └── big-floats.wasm │ │ ├── multiversx.json │ │ └── big-floats.export │ ├── exec-dest-ctx-builtin │ │ ├── exec-dest-ctx-builtin.export │ │ ├── multiversx.json │ │ └── output │ │ │ └── exec-dest-ctx-builtin.wasm │ ├── exec-dest-ctx-recursive │ │ ├── exec-dest-ctx-recursive.export │ │ ├── multiversx.json │ │ └── output │ │ │ └── exec-dest-ctx-recursive.wasm │ ├── exec-same-ctx-parent │ │ ├── multiversx.json │ │ ├── output │ │ │ └── exec-same-ctx-parent.wasm │ │ └── exec-same-ctx-parent.export │ ├── exec-same-ctx-recursive │ │ ├── exec-same-ctx-recursive.export │ │ ├── multiversx.json │ │ └── output │ │ │ └── exec-same-ctx-recursive.wasm │ ├── new-blockchain-hooks │ │ ├── Makefile │ │ └── output │ │ │ └── new-blockchain-hooks.wasm │ ├── big-floats-2 │ │ ├── output │ │ │ └── big-floats-2.wasm │ │ ├── multiversx.json │ │ └── big-floats.export │ ├── exec-dest-ctx-parent │ │ ├── multiversx.json │ │ ├── output │ │ │ └── exec-dest-ctx-parent.wasm │ │ └── exec-dest-ctx-parent.export │ ├── answer-locals │ │ ├── output │ │ │ └── answer-locals.wasm │ │ └── answer-locals.wat │ ├── forbidden-opcodes │ │ ├── simd │ │ │ └── output │ │ │ │ ├── simd.wasm │ │ │ │ └── simd.wat │ │ ├── data-drop │ │ │ └── output │ │ │ │ ├── data-drop.wasm │ │ │ │ └── data-drop.wat │ │ ├── memory-copy │ │ │ └── output │ │ │ │ ├── memory-copy.wasm │ │ │ │ └── memory-copy.wat │ │ ├── memory-fill │ │ │ └── output │ │ │ │ ├── memory-fill.wasm │ │ │ │ └── memory-fill.wat │ │ └── memory-init │ │ │ └── output │ │ │ ├── memory-init.wasm │ │ │ └── memory-init.wat │ ├── init-simple-popcnt │ │ ├── init-simple-popcnt.wasm │ │ ├── output │ │ │ └── init-simple-popcnt.wasm │ │ └── init-simple-popcnt.wat │ ├── managed-buffers │ │ ├── output │ │ │ └── managed-buffers.wasm │ │ ├── multiversx.json │ │ └── managed-buffers.export │ ├── transfer-with-return-error │ │ └── output │ │ │ └── transfer-with-return-error.wasm │ └── mxvm │ │ ├── types.h │ │ ├── cbuiltins.c │ │ ├── args.h │ │ └── util.h ├── dns │ ├── output │ │ └── dns.wasm │ └── scenarios │ │ ├── 07_bogus_name.steps.json │ │ └── main.scen.json ├── promises │ ├── train.wasm │ ├── promises.wasm │ ├── trackingSystem.wasm │ ├── promises_different_shards.async-call.json │ ├── promises_only_db_different_shard.sc_promise.async-call.json │ └── promises_only_db_different_shard.sc_train.async-call.json ├── timelocks │ └── timelocks.wasm ├── async │ ├── async-bob │ │ └── output │ │ │ └── bob.wasm │ └── async-alice │ │ └── output │ │ └── alice.wasm ├── attestation-c │ ├── attestation.wasm │ └── main.scen.json ├── delegation │ ├── v0_2 │ │ ├── delegation.wasm │ │ └── auction-mock.wasm │ ├── v0_3 │ │ ├── output │ │ │ └── delegation.wasm │ │ └── test │ │ │ └── integration │ │ │ ├── stake_partial_err │ │ │ └── 05_claim_failed.steps.json │ │ │ ├── main │ │ │ ├── 14x_unstake_too_soon.steps.json │ │ │ └── 10x_unbond_nodes_too_soon.steps.json │ │ │ ├── genesis │ │ │ └── 04b_genesis_activate.steps.json │ │ │ └── owner_share │ │ │ └── 04_activate_bad.steps.json │ ├── v0_4_genesis │ │ ├── output │ │ │ └── delegation.wasm │ │ └── test │ │ │ └── integration │ │ │ └── genesis │ │ │ └── 04b_genesis_activate.steps.json │ ├── auction-mock │ │ └── output │ │ │ └── auction-mock.wasm │ └── v0_5_latest │ │ ├── output │ │ ├── delegation_latest_full.wasm │ │ └── delegation_latest_update.wasm │ │ └── scenarios │ │ ├── version.scen.json │ │ ├── version.scen copy.json │ │ └── staking_2.scen.json ├── erc20-c │ └── contracts │ │ └── erc20-c.wasm ├── paymaster │ └── output │ │ └── paymaster.wasm ├── attestation-rust │ ├── output │ │ └── attestation.wasm │ └── scenarios │ │ └── main.scen.json ├── esdt-nft-marketplace │ └── output │ │ └── esdt-nft-marketplace.wasm ├── features │ ├── basic-features-legacy │ │ ├── output │ │ │ └── features-legacy.wasm │ │ └── scenarios │ │ │ ├── echo_nothing_legacy.scen.json │ │ │ ├── send_tx_legacy.scen.json │ │ │ ├── out_of_gas_legacy.scen.json │ │ │ └── return_error_legacy.scen.json │ ├── managed-map-features │ │ └── output │ │ │ └── managed-map-features.wasm │ ├── basic-features-no-small-int-api │ │ └── output │ │ │ └── features-no-small-int-api.wasm │ ├── alloc-features │ │ └── scenarios │ │ │ ├── managed_buffer_overwrite.scen.json │ │ │ ├── alloc_mem_leaking.scen.json │ │ │ └── alloc_mem_fail.scen.json │ ├── composability │ │ └── scenarios │ │ │ ├── forwarder_no_endpoint.scen.json │ │ │ └── promises_call_callback_directly.scen.json │ ├── basic-features │ │ └── scenarios │ │ │ ├── echo_nothing.scen.json │ │ │ ├── return_codes.scen.json │ │ │ ├── big_uint_sqrt.scen.json │ │ │ ├── big_uint_pow.scen.json │ │ │ ├── out_of_gas.scen.json │ │ │ └── count_ones.scen.json │ └── basic-features-ei-1-3 │ │ └── scenarios │ │ ├── echo_nothing.scen.json │ │ ├── return_codes.scen.json │ │ ├── big_uint_sqrt.scen.json │ │ ├── out_of_gas.scen.json │ │ ├── big_uint_pow.scen.json │ │ ├── count_ones.scen.json │ │ └── storage_i64_bad.scen.json ├── ping-pong-egld │ └── scenarios │ │ ├── ping-pong-call-pong-all.scen.json │ │ └── ping-pong-call-get-user-addresses.scen.json ├── multisig │ └── scenarios │ │ ├── changeBoard.scen.json │ │ └── deploy_duplicate_bm.scen.json └── factorial │ └── scenarios │ └── factorial.scen.json ├── cmd ├── testgen │ └── dns │ │ └── .gitignore └── scenariostest │ └── .gitignore ├── fuzz ├── .gitignore ├── dex │ └── v0.1 │ │ ├── wasms │ │ ├── dex_farm.wasm │ │ ├── dex_pair.wasm │ │ └── dex_router.wasm │ │ └── fuzzDexExecutorTokens.go ├── delegation │ ├── v0.3 │ │ └── fuzzDelegationInvariants.go │ └── v0.5 │ │ └── fuzzDelegationGetters.go ├── weightedroulette │ └── weightedRoulette.go └── util │ └── randomEventProvider.go ├── integrationTests └── json │ ├── .gitignore │ └── scenariosExecutorVersions_test.go ├── wasmer2 ├── libvmexeccapi.so ├── libvmexeccapi.dylib ├── libvmexeccapi_arm.so ├── libvmexeccapi_arm.dylib ├── wasmer2Static.go ├── wasmer2.go ├── wasmer2ImportsCgoHelper.go ├── wasmer2ExecutorFactory.go └── error2.go ├── sonar-project.properties ├── vmhost ├── vmhooks │ └── generate │ │ ├── cmd │ │ ├── .gitignore │ │ └── README.md │ │ ├── eiGenWriteRustVMHooksNames.go │ │ ├── eiGenWriteHeaders.go │ │ ├── eiGenWriter.go │ │ ├── eiGenWriteGoNames.go │ │ ├── eiGenModel.go │ │ ├── eiGenWriteOpcodeCost.go │ │ ├── eiGenWriteWASMOpcodeCost.go │ │ ├── eiGenWriteRustCapiVMHooksPointers.go │ │ ├── eiGenWriteWASMOpcodeCostConfigHelpers.go │ │ ├── eiGenWriteWASMOpcodeCostFuncHelpers.go │ │ ├── eiGenWriteOpcodeCostFuncHelpers.go │ │ └── eiGenWriteRustOpcodeCost.go ├── hostCore │ ├── executionAsync.go │ └── breakpoints.go ├── helpers_test.go ├── hosttest │ └── tools │ │ └── graphviz_tool.go ├── asyncCall.proto └── mock │ └── builtInFunctionStub.go ├── math ├── interface.go ├── randomnessGenerator.go └── errors.go ├── codecov.yml ├── crypto ├── signing │ ├── errors.go │ └── ed25519 │ │ └── ed25519.go ├── factory │ └── cryptovm.go ├── interface.go └── hashing │ └── hasher.go ├── mock ├── contracts │ ├── gasMismatchChild.go │ └── asyncChildSCMultiGroups.go └── context │ └── memoryMock.go ├── scenario └── gasSchedules │ ├── gasSchedules.go │ └── gasScheduleLoad.go ├── README.md ├── .gitignore ├── .github └── workflows │ ├── build-test.yml │ ├── golangci-lint.yml │ └── code-coverage.yml ├── executor ├── executorFactory.go ├── executorInstance.go ├── executorError.go └── executor.go └── testcommon └── testexecutor └── defaultTestExecutor.go /test/contracts/bad-empty/bad-empty.export: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /cmd/testgen/dns/.gitignore: -------------------------------------------------------------------------------- 1 | # binary 2 | dns 3 | -------------------------------------------------------------------------------- /fuzz/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | fuzz_gen*.scen.json 3 | -------------------------------------------------------------------------------- /test/contracts/counter/multiversx.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /integrationTests/json/.gitignore: -------------------------------------------------------------------------------- 1 | executorLog* 2 | -------------------------------------------------------------------------------- /test/contracts/init-simple/init-simple.export: -------------------------------------------------------------------------------- 1 | init -------------------------------------------------------------------------------- /test/contracts/init-wrong/init-wrong.export: -------------------------------------------------------------------------------- 1 | init 2 | -------------------------------------------------------------------------------- /test/contracts/answer/answer.export: -------------------------------------------------------------------------------- 1 | answer 2 | init 3 | -------------------------------------------------------------------------------- /test/contracts/breakpoint/breakpoint.export: -------------------------------------------------------------------------------- 1 | testFunc 2 | -------------------------------------------------------------------------------- /test/contracts/deployer-child/deployer-child.export: -------------------------------------------------------------------------------- 1 | init -------------------------------------------------------------------------------- /test/contracts/deployer-parent/deployer-parent.export: -------------------------------------------------------------------------------- 1 | init -------------------------------------------------------------------------------- /cmd/scenariostest/.gitignore: -------------------------------------------------------------------------------- 1 | # binary 2 | scenariostest 3 | -------------------------------------------------------------------------------- /test/contracts/deployer/deployer.export: -------------------------------------------------------------------------------- 1 | deployChildContract 2 | -------------------------------------------------------------------------------- /test/contracts/misc/misc.export: -------------------------------------------------------------------------------- 1 | iterate_over_byte_array 2 | -------------------------------------------------------------------------------- /test/contracts/bad-empty/bad-empty.c: -------------------------------------------------------------------------------- 1 | void _main(void) { 2 | } 3 | -------------------------------------------------------------------------------- /test/contracts/exec-dest-ctx-by-caller/child/child.export: -------------------------------------------------------------------------------- 1 | give 2 | -------------------------------------------------------------------------------- /test/contracts/init-correct/init-correct.export: -------------------------------------------------------------------------------- 1 | init 2 | upgrade 3 | -------------------------------------------------------------------------------- /test/contracts/opcodes/opcodes.export: -------------------------------------------------------------------------------- 1 | memSize 2 | memGrowDelta 3 | -------------------------------------------------------------------------------- /test/contracts/exec-dest-ctx-esdt/basic/basic.export: -------------------------------------------------------------------------------- 1 | basic_transfer 2 | -------------------------------------------------------------------------------- /test/contracts/exec-sync-ctx-multiple/beta/beta.export: -------------------------------------------------------------------------------- 1 | betaMethod 2 | -------------------------------------------------------------------------------- /test/contracts/exec-sync-ctx-multiple/delta/delta.export: -------------------------------------------------------------------------------- 1 | deltaMethod 2 | -------------------------------------------------------------------------------- /test/contracts/exec-sync-ctx-multiple/gamma/gamma.export: -------------------------------------------------------------------------------- 1 | gammaMethod 2 | -------------------------------------------------------------------------------- /test/contracts/memgrow-wrong/memgrow-wrong.export: -------------------------------------------------------------------------------- 1 | memGrowWrongIndex 2 | -------------------------------------------------------------------------------- /test/contracts/num-with-fp/num-with-fp.export: -------------------------------------------------------------------------------- 1 | init 2 | doSomething 3 | -------------------------------------------------------------------------------- /test/contracts/bad-recursive/bad-recursive.export: -------------------------------------------------------------------------------- 1 | init 2 | badRecursive 3 | -------------------------------------------------------------------------------- /test/contracts/exchange/multiversx.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "rust" 3 | } 4 | -------------------------------------------------------------------------------- /test/contracts/exec-dest-ctx-by-caller/parent/parent.export: -------------------------------------------------------------------------------- 1 | call_child 2 | -------------------------------------------------------------------------------- /test/contracts/async-call-child-managed/async-call-child-managed.export: -------------------------------------------------------------------------------- 1 | bar 2 | -------------------------------------------------------------------------------- /test/contracts/async-call-child/async-call-child.export: -------------------------------------------------------------------------------- 1 | transferToThirdParty 2 | -------------------------------------------------------------------------------- /test/contracts/init-wrong/init-wrong.c: -------------------------------------------------------------------------------- 1 | void init(int a) { 2 | a = a + 1; 3 | } 4 | -------------------------------------------------------------------------------- /test/contracts/promises/tourist-tracking/trackingSystem.export: -------------------------------------------------------------------------------- 1 | init 2 | bookTrain 3 | -------------------------------------------------------------------------------- /test/contracts/exchange/wasm/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![no_std] 2 | 3 | pub use exchange::*; 4 | 5 | -------------------------------------------------------------------------------- /test/contracts/exec-same-ctx-simple-child/exec-same-ctx-simple-child.export: -------------------------------------------------------------------------------- 1 | childFunction 2 | -------------------------------------------------------------------------------- /test/contracts/async-call-parent-managed/async-call-parent-managed.export: -------------------------------------------------------------------------------- 1 | foo 2 | callBack 3 | -------------------------------------------------------------------------------- /test/contracts/async-call-parent/async-call-parent.export: -------------------------------------------------------------------------------- 1 | parentPerformAsyncCall 2 | callBack 3 | -------------------------------------------------------------------------------- /test/contracts/counter/counter.export: -------------------------------------------------------------------------------- 1 | init 2 | upgrade 3 | increment 4 | decrement 5 | get 6 | -------------------------------------------------------------------------------- /test/contracts/deployer-fromanother-contract/deployer.export: -------------------------------------------------------------------------------- 1 | deployCodeFromAnotherContract 2 | -------------------------------------------------------------------------------- /test/contracts/upgrader-fromanother-contract/deployer.export: -------------------------------------------------------------------------------- 1 | upgradeCodeFromAnotherContract 2 | -------------------------------------------------------------------------------- /test/contracts/async-call-builtin/async-call-builtin.export: -------------------------------------------------------------------------------- 1 | performAsyncCallToBuiltin 2 | callBack 3 | -------------------------------------------------------------------------------- /test/contracts/exec-dest-ctx-recursive-child/exec-dest-ctx-recursive-child.export: -------------------------------------------------------------------------------- 1 | childCallsParent 2 | -------------------------------------------------------------------------------- /test/contracts/exec-same-ctx-recursive-child/exec-same-ctx-recursive-child.export: -------------------------------------------------------------------------------- 1 | childCallsParent 2 | -------------------------------------------------------------------------------- /test/contracts/exec-dest-ctx-recursive-parent/exec-dest-ctx-recursive-parent.export: -------------------------------------------------------------------------------- 1 | parentCallsChild 2 | -------------------------------------------------------------------------------- /test/contracts/exec-same-ctx-recursive-parent/exec-same-ctx-recursive-parent.export: -------------------------------------------------------------------------------- 1 | parentCallsChild 2 | -------------------------------------------------------------------------------- /test/contracts/exec-same-ctx-simple-parent/exec-same-ctx-simple-parent.export: -------------------------------------------------------------------------------- 1 | parentFunctionChildCall 2 | -------------------------------------------------------------------------------- /test/contracts/promises/child-simple/wasm/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![no_std] 2 | 3 | pub use child_simple::*; 4 | 5 | -------------------------------------------------------------------------------- /test/contracts/promises/parent-simple/wasm/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![no_std] 2 | 3 | pub use parent_simple::*; 4 | 5 | -------------------------------------------------------------------------------- /test/contracts/timelocks/timelocks.export: -------------------------------------------------------------------------------- 1 | init 2 | incrementCounter 3 | lockCounter 4 | releaseCounter 5 | -------------------------------------------------------------------------------- /test/contracts/wasmbacking/memoryless/output/memoryless.wasm: -------------------------------------------------------------------------------- 1 | asm` 2 | addTwo 3 |  j -------------------------------------------------------------------------------- /test/dns/output/dns.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/dns/output/dns.wasm -------------------------------------------------------------------------------- /test/promises/train.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/promises/train.wasm -------------------------------------------------------------------------------- /wasmer2/libvmexeccapi.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/wasmer2/libvmexeccapi.so -------------------------------------------------------------------------------- /test/contracts/signatures/signatures.export: -------------------------------------------------------------------------------- 1 | goodFunction 2 | wrongReturn 3 | wrongParams 4 | wrongParamsAndReturn 5 | -------------------------------------------------------------------------------- /test/promises/promises.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/promises/promises.wasm -------------------------------------------------------------------------------- /wasmer2/libvmexeccapi.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/wasmer2/libvmexeccapi.dylib -------------------------------------------------------------------------------- /wasmer2/libvmexeccapi_arm.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/wasmer2/libvmexeccapi_arm.so -------------------------------------------------------------------------------- /test/contracts/async-promises-parent/async-promises-parent.export: -------------------------------------------------------------------------------- 1 | parentPerformAsyncCall 2 | callBackSucc 3 | callBackErr -------------------------------------------------------------------------------- /test/contracts/exec-sync-ctx-multiple/alpha/alpha.export: -------------------------------------------------------------------------------- 1 | callChildrenDirectly_SameCtx 2 | callChildrenDirectly_DestCtx 3 | -------------------------------------------------------------------------------- /test/timelocks/timelocks.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/timelocks/timelocks.wasm -------------------------------------------------------------------------------- /wasmer2/libvmexeccapi_arm.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/wasmer2/libvmexeccapi_arm.dylib -------------------------------------------------------------------------------- /fuzz/dex/v0.1/wasms/dex_farm.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/fuzz/dex/v0.1/wasms/dex_farm.wasm -------------------------------------------------------------------------------- /fuzz/dex/v0.1/wasms/dex_pair.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/fuzz/dex/v0.1/wasms/dex_pair.wasm -------------------------------------------------------------------------------- /sonar-project.properties: -------------------------------------------------------------------------------- 1 | sonar.exclusions=**/*_test.go, fuzz/**, integrationTests/**, mock/**, scenario/**, testcommon/** 2 | -------------------------------------------------------------------------------- /test/contracts/promises/three-contracts/first-contract/wasm/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![no_std] 2 | 3 | pub use first_contract::*; 4 | 5 | -------------------------------------------------------------------------------- /test/contracts/promises/three-contracts/second-contract/wasm/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![no_std] 2 | 3 | pub use second_contract::*; 4 | 5 | -------------------------------------------------------------------------------- /test/contracts/promises/three-contracts/third-contract/wasm/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![no_std] 2 | 3 | pub use third_contract::*; 4 | 5 | -------------------------------------------------------------------------------- /test/contracts/wasmbacking/mem-exceeded-pages/output/mem-exceeded-pages.wasm: -------------------------------------------------------------------------------- 1 | asm`*memorymain 2 |  -------------------------------------------------------------------------------- /test/promises/trackingSystem.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/promises/trackingSystem.wasm -------------------------------------------------------------------------------- /fuzz/dex/v0.1/wasms/dex_router.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/fuzz/dex/v0.1/wasms/dex_router.wasm -------------------------------------------------------------------------------- /test/async/async-bob/output/bob.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/async/async-bob/output/bob.wasm -------------------------------------------------------------------------------- /test/attestation-c/attestation.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/attestation-c/attestation.wasm -------------------------------------------------------------------------------- /test/contracts/erc20/multiversx.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "clang", 3 | "source_files": [ 4 | "./erc20.c" 5 | ] 6 | } -------------------------------------------------------------------------------- /test/contracts/exec-dest-ctx-child/exec-dest-ctx-child.export: -------------------------------------------------------------------------------- 1 | childFunction 2 | childFunction_BigInts 3 | childFunction_OutOfGas 4 | -------------------------------------------------------------------------------- /test/contracts/exec-same-ctx-child/exec-same-ctx-child.export: -------------------------------------------------------------------------------- 1 | childFunction 2 | childFunction_BigInts 3 | childFunction_OutOfGas 4 | -------------------------------------------------------------------------------- /test/contracts/init-simple/init-simple.c: -------------------------------------------------------------------------------- 1 | void int64finish(long long value); 2 | 3 | void init() { 4 | int64finish(42); 5 | } 6 | -------------------------------------------------------------------------------- /test/contracts/misc/multiversx.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "clang", 3 | "source_files": [ 4 | "./misc.c" 5 | ] 6 | } -------------------------------------------------------------------------------- /test/contracts/misc/output/misc.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/misc/output/misc.wasm -------------------------------------------------------------------------------- /test/contracts/pair/output/pair.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/pair/output/pair.wasm -------------------------------------------------------------------------------- /test/delegation/v0_2/delegation.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/delegation/v0_2/delegation.wasm -------------------------------------------------------------------------------- /test/erc20-c/contracts/erc20-c.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/erc20-c/contracts/erc20-c.wasm -------------------------------------------------------------------------------- /test/paymaster/output/paymaster.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/paymaster/output/paymaster.wasm -------------------------------------------------------------------------------- /test/contracts/answer/multiversx.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "clang", 3 | "source_files": [ 4 | "./answer.c" 5 | ] 6 | } -------------------------------------------------------------------------------- /test/contracts/bad-empty/multiversx.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "clang", 3 | "source_files": [ 4 | "bad-empty.c" 5 | ] 6 | } -------------------------------------------------------------------------------- /test/contracts/baseOps/multiversx.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "clang", 3 | "source_files": [ 4 | "./baseOps.c" 5 | ] 6 | } -------------------------------------------------------------------------------- /test/contracts/erc20/output/erc20.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/erc20/output/erc20.wasm -------------------------------------------------------------------------------- /test/delegation/v0_2/auction-mock.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/delegation/v0_2/auction-mock.wasm -------------------------------------------------------------------------------- /test/async/async-alice/output/alice.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/async/async-alice/output/alice.wasm -------------------------------------------------------------------------------- /test/contracts/answer/answer.c: -------------------------------------------------------------------------------- 1 | #include "../mxvm/context.h" 2 | 3 | void init() {} 4 | 5 | void answer() { 6 | int64finish(42); 7 | } 8 | -------------------------------------------------------------------------------- /test/contracts/answer/output/answer.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/answer/output/answer.wasm -------------------------------------------------------------------------------- /test/contracts/breakpoint/multiversx.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "clang", 3 | "source_files": [ 4 | "./breakpoint.c" 5 | ] 6 | } -------------------------------------------------------------------------------- /test/contracts/breakpoint/output/breakpoint.imports.json: -------------------------------------------------------------------------------- 1 | [ 2 | "int64getArgument", 3 | "signalError", 4 | "int64finish" 5 | ] 6 | -------------------------------------------------------------------------------- /test/contracts/deployer/multiversx.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "clang", 3 | "source_files": [ 4 | "./deployer.c" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /test/contracts/init-simple/multiversx.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "clang", 3 | "source_files": [ 4 | "init-simple.c" 5 | ] 6 | } -------------------------------------------------------------------------------- /test/contracts/init-wrong/multiversx.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "clang", 3 | "source_files": [ 4 | "./init-wrong.c" 5 | ] 6 | } -------------------------------------------------------------------------------- /test/contracts/opcodes/multiversx.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "clang", 3 | "source_files": [ 4 | "opcodes.c" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /test/contracts/promises/tourist-bookings/bookings.export: -------------------------------------------------------------------------------- 1 | init 2 | bookMyStuff 3 | isMyStorageLocked 4 | myTrainSuccess 5 | myTrainError 6 | -------------------------------------------------------------------------------- /test/contracts/signatures/multiversx.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "clang", 3 | "source_files": [ 4 | "./signatures.c" 5 | ] 6 | } -------------------------------------------------------------------------------- /test/contracts/timelocks/multiversx.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "clang", 3 | "source_files": [ 4 | "./timelocks.c" 5 | ] 6 | } -------------------------------------------------------------------------------- /test/contracts/wasmbacking/mem-exceeded-max-pages/output/mem-exceeded-max-pages.wasm: -------------------------------------------------------------------------------- 1 | asm` 2 | *memorymain 3 |  -------------------------------------------------------------------------------- /test/contracts/wasmbacking/multiple-memories/output/multiple-memories.wasm: -------------------------------------------------------------------------------- 1 | asm` 2 | memorymain 3 |  -------------------------------------------------------------------------------- /test/contracts/baseOps/output/baseOps.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/baseOps/output/baseOps.wasm -------------------------------------------------------------------------------- /test/contracts/counter/output/counter.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/counter/output/counter.wasm -------------------------------------------------------------------------------- /test/contracts/deployer-child/multiversx.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "clang", 3 | "source_files": [ 4 | "deployer-child.c" 5 | ] 6 | } -------------------------------------------------------------------------------- /test/contracts/erc20/erc20.export: -------------------------------------------------------------------------------- 1 | init 2 | totalSupply 3 | balanceOf 4 | allowance 5 | transferToken 6 | approve 7 | transferFrom 8 | upgrade 9 | -------------------------------------------------------------------------------- /test/contracts/future/hotel.c: -------------------------------------------------------------------------------- 1 | #include "../mxvm/context.h" 2 | 3 | void init() {} 4 | 5 | void bookHotel() {} 6 | 7 | void cancelHotel() {} 8 | -------------------------------------------------------------------------------- /test/contracts/init-correct/multiversx.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "clang", 3 | "source_files": [ 4 | "./init-correct.c" 5 | ] 6 | } -------------------------------------------------------------------------------- /test/contracts/num-with-fp/multiversx.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "clang", 3 | "source_files": [ 4 | "./num-with-fp.c" 5 | ] 6 | } -------------------------------------------------------------------------------- /test/contracts/opcodes/output/opcodes.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/opcodes/output/opcodes.wasm -------------------------------------------------------------------------------- /test/contracts/wasmbacking/mem-no-pages/output/mem-no-pages.wasm: -------------------------------------------------------------------------------- 1 | asm``~env int64finishmemorymain 2 | B* -------------------------------------------------------------------------------- /test/contracts/wasmbacking/noglobals/output/noglobals.wasm: -------------------------------------------------------------------------------- 1 | asm`~`env int64finishmemory getnumber 2 | B* -------------------------------------------------------------------------------- /test/delegation/v0_3/output/delegation.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/delegation/v0_3/output/delegation.wasm -------------------------------------------------------------------------------- /test/attestation-rust/output/attestation.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/attestation-rust/output/attestation.wasm -------------------------------------------------------------------------------- /test/contracts/bad-empty/output/bad-empty.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/bad-empty/output/bad-empty.wasm -------------------------------------------------------------------------------- /test/contracts/bad-extra/output/bad-extra.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/bad-extra/output/bad-extra.wasm -------------------------------------------------------------------------------- /test/contracts/bad-misc/output/bad-misc.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/bad-misc/output/bad-misc.wasm -------------------------------------------------------------------------------- /test/contracts/deployer/output/deployer.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/deployer/output/deployer.wasm -------------------------------------------------------------------------------- /test/contracts/exchange/output/exchange.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/exchange/output/exchange.wasm -------------------------------------------------------------------------------- /test/contracts/exec-sync-ctx-multiple/beta/multiversx.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "clang", 3 | "source_files": [ 4 | "./beta.c" 5 | ] 6 | } -------------------------------------------------------------------------------- /test/contracts/memgrow-wrong/multiversx.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "clang", 3 | "source_files": [ 4 | "memgrow-wrong.c" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /test/contracts/timelocks/output/timelocks.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/timelocks/output/timelocks.wasm -------------------------------------------------------------------------------- /test/contracts/wasmbacking/mem-single-page/output/mem-single-page.wasm: -------------------------------------------------------------------------------- 1 | asm``~env int64finishmemorymain 2 | B* -------------------------------------------------------------------------------- /test/contracts/async-call-builtin/multiversx.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "clang", 3 | "source_files": [ 4 | "./async-call-builtin.c" 5 | ] 6 | } -------------------------------------------------------------------------------- /test/contracts/async-call-child/multiversx.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "clang", 3 | "source_files": [ 4 | "async-call-child.c" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /test/contracts/baseOps/baseOps.export: -------------------------------------------------------------------------------- 1 | test_getCallValue_1byte 2 | test_getCallValue_4bytes 3 | test_getCallValue_bigInt_to_Bytes 4 | test_int64getArgument 5 | -------------------------------------------------------------------------------- /test/contracts/big-floats/output/big-floats.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/big-floats/output/big-floats.wasm -------------------------------------------------------------------------------- /test/contracts/breakpoint/output/breakpoint.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/breakpoint/output/breakpoint.wasm -------------------------------------------------------------------------------- /test/contracts/exec-sync-ctx-multiple/alpha/multiversx.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "clang", 3 | "source_files": [ 4 | "./alpha.c" 5 | ] 6 | } -------------------------------------------------------------------------------- /test/contracts/exec-sync-ctx-multiple/delta/multiversx.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "clang", 3 | "source_files": [ 4 | "./delta.c" 5 | ] 6 | } -------------------------------------------------------------------------------- /test/contracts/exec-sync-ctx-multiple/gamma/multiversx.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "clang", 3 | "source_files": [ 4 | "./gamma.c" 5 | ] 6 | } -------------------------------------------------------------------------------- /test/contracts/init-wrong/output/init-wrong.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/init-wrong/output/init-wrong.wasm -------------------------------------------------------------------------------- /test/contracts/promises/tourist-train/train.export: -------------------------------------------------------------------------------- 1 | init 2 | bookTrain 3 | bookTrainSuccess 4 | bookTrainError 5 | cancelTrainBooking 6 | isMyTrainBooked 7 | -------------------------------------------------------------------------------- /test/contracts/signatures/output/signatures.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/signatures/output/signatures.wasm -------------------------------------------------------------------------------- /test/contracts/wasmbacking/mem-no-max-pages/output/mem-no-max-pages.wasm: -------------------------------------------------------------------------------- 1 | asm``~env int64finishmemorymain 2 | B* -------------------------------------------------------------------------------- /test/contracts/async-call-parent/multiversx.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "clang", 3 | "source_files": [ 4 | "async-call-parent.c" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /test/contracts/async-promises-parent/multiversx.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "clang", 3 | "source_files": [ 4 | "async-promises-parent.c" 5 | ] 6 | } -------------------------------------------------------------------------------- /test/contracts/exec-dest-ctx-builtin/exec-dest-ctx-builtin.export: -------------------------------------------------------------------------------- 1 | callBuiltinClaim 2 | callBuiltinDoSomething 3 | callNonexistingBuiltin 4 | callBuiltinFail 5 | -------------------------------------------------------------------------------- /test/contracts/exec-dest-ctx-by-caller/child/multiversx.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "clang", 3 | "source_files": [ 4 | "./child.c" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /test/contracts/exec-dest-ctx-by-caller/parent/multiversx.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "clang", 3 | "source_files": [ 4 | "./parent.c" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /test/contracts/exec-dest-ctx-child/multiversx.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "clang", 3 | "source_files": [ 4 | "exec-dest-ctx-child.c" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /test/contracts/exec-dest-ctx-recursive/exec-dest-ctx-recursive.export: -------------------------------------------------------------------------------- 1 | callRecursive 2 | callRecursiveMutualMethods 3 | recursiveMethodA 4 | recursiveMethodB 5 | -------------------------------------------------------------------------------- /test/contracts/exec-same-ctx-child/multiversx.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "clang", 3 | "source_files": [ 4 | "./exec-same-ctx-child.c" 5 | ] 6 | } -------------------------------------------------------------------------------- /test/contracts/exec-same-ctx-parent/multiversx.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "clang", 3 | "source_files": [ 4 | "./exec-same-ctx-parent.c" 5 | ] 6 | } -------------------------------------------------------------------------------- /test/contracts/exec-same-ctx-recursive/exec-same-ctx-recursive.export: -------------------------------------------------------------------------------- 1 | callRecursive 2 | callRecursiveMutualMethods 3 | recursiveMethodA 4 | recursiveMethodB 5 | -------------------------------------------------------------------------------- /test/contracts/init-simple/output/init-simple.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/init-simple/output/init-simple.wasm -------------------------------------------------------------------------------- /test/contracts/memgrow-wrong/memgrow-wrong.c: -------------------------------------------------------------------------------- 1 | void memGrowWrongIndex() { 2 | asm ( 3 | "i32.const 10\n" 4 | "memory.grow 1\n" 5 | "drop\n" 6 | ); 7 | } 8 | -------------------------------------------------------------------------------- /test/contracts/new-blockchain-hooks/Makefile: -------------------------------------------------------------------------------- 1 | build: 2 | rustc --target wasm32-unknown-unknown -O --crate-type=cdylib src/lib.rs -o output/new-blockchain-hooks.wasm -------------------------------------------------------------------------------- /test/contracts/num-with-fp/output/num-with-fp.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/num-with-fp/output/num-with-fp.wasm -------------------------------------------------------------------------------- /test/contracts/promises/tourist-tracking/multiversx.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "clang", 3 | "source_files": [ 4 | "./trackingSystem.c" 5 | ] 6 | } -------------------------------------------------------------------------------- /test/contracts/wasmbacking/mem-multiple-pages/output/mem-multiple-pages.wasm: -------------------------------------------------------------------------------- 1 | asm``~env int64finish 2 | memorymain 3 | B* -------------------------------------------------------------------------------- /test/delegation/v0_4_genesis/output/delegation.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/delegation/v0_4_genesis/output/delegation.wasm -------------------------------------------------------------------------------- /test/contracts/async-call-child-managed/multiversx.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "clang", 3 | "source_files": [ 4 | "async-call-child-managed.c" 5 | ] 6 | } -------------------------------------------------------------------------------- /test/contracts/big-floats-2/output/big-floats-2.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/big-floats-2/output/big-floats-2.wasm -------------------------------------------------------------------------------- /test/contracts/exec-dest-ctx-builtin/multiversx.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "clang", 3 | "source_files": [ 4 | "./exec-dest-ctx-builtin.c" 5 | ] 6 | } -------------------------------------------------------------------------------- /test/contracts/exec-dest-ctx-parent/multiversx.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "clang", 3 | "source_files": [ 4 | "exec-dest-ctx-parent.c" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /test/contracts/exec-dest-ctx-recursive/multiversx.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "clang", 3 | "source_files": [ 4 | "./exec-dest-ctx-recursive.c" 5 | ] 6 | } -------------------------------------------------------------------------------- /test/contracts/exec-same-ctx-recursive/multiversx.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "clang", 3 | "source_files": [ 4 | "./exec-same-ctx-recursive.c" 5 | ] 6 | } -------------------------------------------------------------------------------- /test/contracts/init-correct/output/init-correct.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/init-correct/output/init-correct.wasm -------------------------------------------------------------------------------- /test/contracts/wasmbacking/mem-min-pages-greater-than-max-pages/output/mem-min-pages-greater-than-max-pages.wasm: -------------------------------------------------------------------------------- 1 | asm`memorymain 2 |  -------------------------------------------------------------------------------- /test/delegation/auction-mock/output/auction-mock.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/delegation/auction-mock/output/auction-mock.wasm -------------------------------------------------------------------------------- /test/contracts/answer-locals/output/answer-locals.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/answer-locals/output/answer-locals.wasm -------------------------------------------------------------------------------- /test/contracts/async-call-parent-managed/multiversx.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "clang", 3 | "source_files": [ 4 | "async-call-parent-managed.c" 5 | ] 6 | } -------------------------------------------------------------------------------- /test/contracts/bad-recursive/output/bad-recursive.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/bad-recursive/output/bad-recursive.wasm -------------------------------------------------------------------------------- /test/contracts/deployer-child/output/deployer-child.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/deployer-child/output/deployer-child.wasm -------------------------------------------------------------------------------- /test/contracts/exchange/.gitignore: -------------------------------------------------------------------------------- 1 | # Generated by Cargo 2 | # will have compiled files and executables 3 | /target/ 4 | */target/ 5 | 6 | # The erdpy output 7 | output 8 | -------------------------------------------------------------------------------- /test/contracts/forbidden-opcodes/simd/output/simd.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/forbidden-opcodes/simd/output/simd.wasm -------------------------------------------------------------------------------- /test/contracts/memgrow-wrong/output/memgrow-wrong.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/memgrow-wrong/output/memgrow-wrong.wasm -------------------------------------------------------------------------------- /test/contracts/promises/tourist-train/output/train.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/promises/tourist-train/output/train.wasm -------------------------------------------------------------------------------- /test/contracts/wasmbacking/mem-grow/output/mem-grow.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/wasmbacking/mem-grow/output/mem-grow.wasm -------------------------------------------------------------------------------- /test/contracts/big-floats/multiversx.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "clang", 3 | "source_files": [ 4 | "big-floats.c", 5 | "../mxvm/cbuiltins.c" 6 | ] 7 | } -------------------------------------------------------------------------------- /test/contracts/deployer-fromanother-contract/multiversx.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "clang", 3 | "source_files": [ 4 | "deployer-fromanother-contract.c" 5 | ] 6 | } -------------------------------------------------------------------------------- /test/contracts/deployer-parent/output/deployer-parent.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/deployer-parent/output/deployer-parent.wasm -------------------------------------------------------------------------------- /test/contracts/exec-dest-ctx-esdt/basic/output/basic.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/exec-dest-ctx-esdt/basic/output/basic.wasm -------------------------------------------------------------------------------- /test/contracts/exec-same-ctx-simple-child/multiversx.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "clang", 3 | "source_files": [ 4 | "./exec-same-ctx-simple-child.c" 5 | ] 6 | } -------------------------------------------------------------------------------- /test/contracts/exec-same-ctx-simple-parent/multiversx.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "clang", 3 | "source_files": [ 4 | "./exec-same-ctx-simple-parent.c" 5 | ] 6 | } -------------------------------------------------------------------------------- /test/contracts/init-simple-popcnt/init-simple-popcnt.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/init-simple-popcnt/init-simple-popcnt.wasm -------------------------------------------------------------------------------- /test/contracts/managed-buffers/output/managed-buffers.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/managed-buffers/output/managed-buffers.wasm -------------------------------------------------------------------------------- /test/contracts/upgrader-fromanother-contract/multiversx.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "clang", 3 | "source_files": [ 4 | "upgrader-fromanother-contract.c" 5 | ] 6 | } -------------------------------------------------------------------------------- /test/contracts/wasmbacking/mem-multiple-max-pages/output/mem-multiple-max-pages.wasm: -------------------------------------------------------------------------------- 1 | asm``~env int64finish 2 | 3 | memorymain 4 | B* -------------------------------------------------------------------------------- /test/contracts/wasmbacking/middleware-globals/output/middleware-globals.wasm: -------------------------------------------------------------------------------- 1 | asm`~`env int64finish ~B* ~B+ memory getglobal 2 | # -------------------------------------------------------------------------------- /test/esdt-nft-marketplace/output/esdt-nft-marketplace.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/esdt-nft-marketplace/output/esdt-nft-marketplace.wasm -------------------------------------------------------------------------------- /test/contracts/async-call-child-managed/async-call-child-managed.c: -------------------------------------------------------------------------------- 1 | #include "../mxvm/context.h" 2 | #include "../mxvm/bigInt.h" 3 | 4 | void bar() { 5 | int64finish(42); 6 | } 7 | -------------------------------------------------------------------------------- /test/contracts/async-call-child/output/async-call-child.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/async-call-child/output/async-call-child.wasm -------------------------------------------------------------------------------- /test/contracts/big-floats-2/multiversx.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "clang", 3 | "source_files": [ 4 | "big-floats-2.c", 5 | "../mxvm/cbuiltins.c" 6 | ] 7 | } -------------------------------------------------------------------------------- /test/contracts/deployer-parent/multiversx.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "clang", 3 | "source_files": [ 4 | "deployer-parent.c", 5 | "../mxvm/args.c" 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /test/contracts/exec-dest-ctx-recursive-child/multiversx.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "clang", 3 | "source_files": [ 4 | "./exec-dest-ctx-recursive-child.c" 5 | ] 6 | } -------------------------------------------------------------------------------- /test/contracts/exec-dest-ctx-recursive-parent/multiversx.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "clang", 3 | "source_files": [ 4 | "./exec-dest-ctx-recursive-parent.c" 5 | ] 6 | } -------------------------------------------------------------------------------- /test/contracts/exec-same-ctx-recursive-child/multiversx.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "clang", 3 | "source_files": [ 4 | "./exec-same-ctx-recursive-child.c" 5 | ] 6 | } -------------------------------------------------------------------------------- /test/contracts/exec-same-ctx-recursive-parent/multiversx.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "clang", 3 | "source_files": [ 4 | "./exec-same-ctx-recursive-parent.c" 5 | ] 6 | } -------------------------------------------------------------------------------- /test/contracts/exec-sync-ctx-multiple/alpha/output/alpha.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/exec-sync-ctx-multiple/alpha/output/alpha.wasm -------------------------------------------------------------------------------- /test/contracts/exec-sync-ctx-multiple/beta/output/beta.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/exec-sync-ctx-multiple/beta/output/beta.wasm -------------------------------------------------------------------------------- /test/contracts/exec-sync-ctx-multiple/delta/output/delta.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/exec-sync-ctx-multiple/delta/output/delta.wasm -------------------------------------------------------------------------------- /test/contracts/exec-sync-ctx-multiple/gamma/output/gamma.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/exec-sync-ctx-multiple/gamma/output/gamma.wasm -------------------------------------------------------------------------------- /test/contracts/promises/child-simple/output/child-simple.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/promises/child-simple/output/child-simple.wasm -------------------------------------------------------------------------------- /test/contracts/promises/tourist-bookings/output/bookings.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/promises/tourist-bookings/output/bookings.wasm -------------------------------------------------------------------------------- /test/contracts/wasmbacking/imported-global/output/imported-global.wasm: -------------------------------------------------------------------------------- 1 | asm`~`$env importedG~env int64finish memoryget_imported_global 2 | # -------------------------------------------------------------------------------- /vmhost/vmhooks/generate/cmd/.gitignore: -------------------------------------------------------------------------------- 1 | # generated files that belong to other repos: 2 | output 3 | 4 | # optional path where to copy rust files 5 | wasm-vm-executor-rs-path.txt 6 | -------------------------------------------------------------------------------- /test/contracts/async-call-parent/output/async-call-parent.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/async-call-parent/output/async-call-parent.wasm -------------------------------------------------------------------------------- /test/contracts/exec-dest-ctx-by-caller/child/output/child.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/exec-dest-ctx-by-caller/child/output/child.wasm -------------------------------------------------------------------------------- /test/contracts/managed-buffers/multiversx.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "clang", 3 | "source_files": [ 4 | "managed-buffers.c", 5 | "../mxvm/cbuiltins.c" 6 | ] 7 | } -------------------------------------------------------------------------------- /test/contracts/promises/parent-simple/output/parent-simple.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/promises/parent-simple/output/parent-simple.wasm -------------------------------------------------------------------------------- /test/contracts/wasmbacking/mem-content/output/mem-content.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/wasmbacking/mem-content/output/mem-content.wasm -------------------------------------------------------------------------------- /test/contracts/wasmbacking/memoryless/output/memoryless.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (func (export "addTwo") (param i32 i32) (result i32) 3 | local.get 0 4 | local.get 1 5 | i32.add)) 6 | -------------------------------------------------------------------------------- /test/delegation/v0_5_latest/output/delegation_latest_full.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/delegation/v0_5_latest/output/delegation_latest_full.wasm -------------------------------------------------------------------------------- /test/features/basic-features-legacy/output/features-legacy.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/features/basic-features-legacy/output/features-legacy.wasm -------------------------------------------------------------------------------- /test/contracts/async-call-builtin/output/async-call-builtin.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/async-call-builtin/output/async-call-builtin.wasm -------------------------------------------------------------------------------- /test/contracts/exec-dest-ctx-by-caller/parent/output/parent.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/exec-dest-ctx-by-caller/parent/output/parent.wasm -------------------------------------------------------------------------------- /test/contracts/exec-dest-ctx-child/output/exec-dest-ctx-child.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/exec-dest-ctx-child/output/exec-dest-ctx-child.wasm -------------------------------------------------------------------------------- /test/contracts/exec-same-ctx-child/output/exec-same-ctx-child.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/exec-same-ctx-child/output/exec-same-ctx-child.wasm -------------------------------------------------------------------------------- /test/contracts/forbidden-opcodes/data-drop/output/data-drop.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/forbidden-opcodes/data-drop/output/data-drop.wasm -------------------------------------------------------------------------------- /test/contracts/init-simple-popcnt/output/init-simple-popcnt.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/init-simple-popcnt/output/init-simple-popcnt.wasm -------------------------------------------------------------------------------- /test/delegation/v0_5_latest/output/delegation_latest_update.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/delegation/v0_5_latest/output/delegation_latest_update.wasm -------------------------------------------------------------------------------- /test/contracts/bad-empty/output/bad-empty.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (table (;0;) 1 1 funcref) 3 | (memory (;0;) 2) 4 | (global (;0;) (mut i32) (i32.const 66560)) 5 | (export "memory" (memory 0))) 6 | -------------------------------------------------------------------------------- /test/contracts/exec-dest-ctx-parent/output/exec-dest-ctx-parent.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/exec-dest-ctx-parent/output/exec-dest-ctx-parent.wasm -------------------------------------------------------------------------------- /test/contracts/exec-same-ctx-parent/output/exec-same-ctx-parent.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/exec-same-ctx-parent/output/exec-same-ctx-parent.wasm -------------------------------------------------------------------------------- /test/contracts/exec-sync-ctx-multiple/beta/beta.c: -------------------------------------------------------------------------------- 1 | #include "../../mxvm/context.h" 2 | 3 | void betaMethod() { 4 | byte arg[4] = {0}; 5 | getArgument(0, arg); 6 | finish(arg, 4); 7 | } 8 | -------------------------------------------------------------------------------- /test/contracts/exec-sync-ctx-multiple/delta/delta.c: -------------------------------------------------------------------------------- 1 | #include "../../mxvm/context.h" 2 | 3 | void deltaMethod() { 4 | byte arg[4] = {0}; 5 | getArgument(0, arg); 6 | finish(arg, 4); 7 | } 8 | -------------------------------------------------------------------------------- /test/contracts/exec-sync-ctx-multiple/gamma/gamma.c: -------------------------------------------------------------------------------- 1 | #include "../../mxvm/context.h" 2 | 3 | void gammaMethod() { 4 | byte arg[4] = {0}; 5 | getArgument(0, arg); 6 | finish(arg, 4); 7 | } 8 | -------------------------------------------------------------------------------- /test/contracts/forbidden-opcodes/memory-copy/output/memory-copy.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/forbidden-opcodes/memory-copy/output/memory-copy.wasm -------------------------------------------------------------------------------- /test/contracts/forbidden-opcodes/memory-fill/output/memory-fill.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/forbidden-opcodes/memory-fill/output/memory-fill.wasm -------------------------------------------------------------------------------- /test/contracts/forbidden-opcodes/memory-init/output/memory-init.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/forbidden-opcodes/memory-init/output/memory-init.wasm -------------------------------------------------------------------------------- /test/contracts/new-blockchain-hooks/output/new-blockchain-hooks.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/new-blockchain-hooks/output/new-blockchain-hooks.wasm -------------------------------------------------------------------------------- /test/contracts/promises/tourist-tracking/output/trackingSystem.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/promises/tourist-tracking/output/trackingSystem.wasm -------------------------------------------------------------------------------- /test/contracts/wasmbacking/single-mutable/output/single-mutable.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/wasmbacking/single-mutable/output/single-mutable.wasm -------------------------------------------------------------------------------- /test/features/managed-map-features/output/managed-map-features.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/features/managed-map-features/output/managed-map-features.wasm -------------------------------------------------------------------------------- /wasmer2/wasmer2Static.go: -------------------------------------------------------------------------------- 1 | package wasmer2 2 | 3 | // SetLogLevel sets the log level for the Executor. 4 | func SetLogLevel(logLevel LogLevel) { 5 | cWasmerSetLogLevel(uint64(logLevel)) 6 | } 7 | -------------------------------------------------------------------------------- /test/contracts/async-promises-parent/output/async-promises-parent.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/async-promises-parent/output/async-promises-parent.wasm -------------------------------------------------------------------------------- /test/contracts/exec-dest-ctx-builtin/output/exec-dest-ctx-builtin.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/exec-dest-ctx-builtin/output/exec-dest-ctx-builtin.wasm -------------------------------------------------------------------------------- /test/contracts/wasmbacking/single-immutable/output/single-immutable.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/wasmbacking/single-immutable/output/single-immutable.wasm -------------------------------------------------------------------------------- /test/contracts/async-call-child-managed/output/async-call-child-managed.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/async-call-child-managed/output/async-call-child-managed.wasm -------------------------------------------------------------------------------- /test/contracts/exec-dest-ctx-recursive/output/exec-dest-ctx-recursive.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/exec-dest-ctx-recursive/output/exec-dest-ctx-recursive.wasm -------------------------------------------------------------------------------- /test/contracts/exec-same-ctx-recursive/output/exec-same-ctx-recursive.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/exec-same-ctx-recursive/output/exec-same-ctx-recursive.wasm -------------------------------------------------------------------------------- /test/contracts/async-call-parent-managed/output/async-call-parent-managed.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/async-call-parent-managed/output/async-call-parent-managed.wasm -------------------------------------------------------------------------------- /test/contracts/exec-dest-ctx-esdt/basic/multiversx.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "clang", 3 | "source_files": [ 4 | "basic.c", 5 | "../../mxvm/args.c", 6 | "../../mxvm/cbuiltins.c" 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /test/contracts/exec-same-ctx-parent/exec-same-ctx-parent.export: -------------------------------------------------------------------------------- 1 | parentFunctionPrepare 2 | parentFunctionWrongCall 3 | parentFunctionChildCall 4 | parentFunctionChildCall_BigInts 5 | parentFunctionChildCall_OutOfGas 6 | -------------------------------------------------------------------------------- /test/contracts/exec-same-ctx-simple-child/output/exec-same-ctx-simple-child.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/exec-same-ctx-simple-child/output/exec-same-ctx-simple-child.wasm -------------------------------------------------------------------------------- /test/contracts/promises/three-contracts/first-contract/output/first-contract.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/promises/three-contracts/first-contract/output/first-contract.wasm -------------------------------------------------------------------------------- /test/contracts/promises/three-contracts/third-contract/output/third-contract.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/promises/three-contracts/third-contract/output/third-contract.wasm -------------------------------------------------------------------------------- /test/contracts/transfer-with-return-error/output/transfer-with-return-error.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/transfer-with-return-error/output/transfer-with-return-error.wasm -------------------------------------------------------------------------------- /test/contracts/wasmbacking/mem-data-initializer/output/mem-data-initializer.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/wasmbacking/mem-data-initializer/output/mem-data-initializer.wasm -------------------------------------------------------------------------------- /test/contracts/exec-same-ctx-simple-parent/output/exec-same-ctx-simple-parent.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/exec-same-ctx-simple-parent/output/exec-same-ctx-simple-parent.wasm -------------------------------------------------------------------------------- /test/contracts/promises/three-contracts/second-contract/output/second-contract.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/promises/three-contracts/second-contract/output/second-contract.wasm -------------------------------------------------------------------------------- /test/features/basic-features-no-small-int-api/output/features-no-small-int-api.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/features/basic-features-no-small-int-api/output/features-no-small-int-api.wasm -------------------------------------------------------------------------------- /test/contracts/deployer-fromanother-contract/output/deployer-fromanother-contract.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/deployer-fromanother-contract/output/deployer-fromanother-contract.wasm -------------------------------------------------------------------------------- /test/contracts/exec-dest-ctx-recursive-child/output/exec-dest-ctx-recursive-child.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/exec-dest-ctx-recursive-child/output/exec-dest-ctx-recursive-child.wasm -------------------------------------------------------------------------------- /test/contracts/exec-same-ctx-recursive-child/output/exec-same-ctx-recursive-child.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/exec-same-ctx-recursive-child/output/exec-same-ctx-recursive-child.wasm -------------------------------------------------------------------------------- /test/contracts/upgrader-fromanother-contract/output/upgrader-fromanother-contract.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/upgrader-fromanother-contract/output/upgrader-fromanother-contract.wasm -------------------------------------------------------------------------------- /test/contracts/exec-dest-ctx-recursive-parent/output/exec-dest-ctx-recursive-parent.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/exec-dest-ctx-recursive-parent/output/exec-dest-ctx-recursive-parent.wasm -------------------------------------------------------------------------------- /test/contracts/exec-same-ctx-recursive-parent/output/exec-same-ctx-recursive-parent.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/multiversx/mx-chain-vm-go/HEAD/test/contracts/exec-same-ctx-recursive-parent/output/exec-same-ctx-recursive-parent.wasm -------------------------------------------------------------------------------- /test/contracts/wasmbacking/multiple-mutable/output/multiple-mutable.wasm: -------------------------------------------------------------------------------- 1 | asm`~`env int64finish~B ~B ~B ~B ~B memoryincrement_globals 2 | 42#B|$#B|$#B|$#B|$##### -------------------------------------------------------------------------------- /test/contracts/wasmbacking/mem-exceeded-pages/output/mem-exceeded-pages.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type $void (func)) 3 | (func $main (type $void)) 4 | (memory $mem 42) 5 | (export "memory" (memory $mem)) 6 | (export "main" (func $main)) 7 | ) 8 | -------------------------------------------------------------------------------- /test/contracts/wasmbacking/mem-exceeded-max-pages/output/mem-exceeded-max-pages.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type $void (func)) 3 | (func $main (type $void)) 4 | (memory $mem 10 42) 5 | (export "memory" (memory $mem)) 6 | (export "main" (func $main)) 7 | ) 8 | -------------------------------------------------------------------------------- /test/contracts/exec-dest-ctx-parent/exec-dest-ctx-parent.export: -------------------------------------------------------------------------------- 1 | parentFunctionPrepare 2 | parentFunctionWrongCall 3 | parentFunctionChildCall 4 | parentFunctionChildCall_ReturnedData 5 | parentFunctionChildCall_BigInts 6 | parentFunctionChildCall_OutOfGas 7 | -------------------------------------------------------------------------------- /math/interface.go: -------------------------------------------------------------------------------- 1 | package math 2 | 3 | // RandomnessGenerator will provide the interface to the main functionalities of the VM where randomness is needed 4 | type RandomnessGenerator interface { 5 | Read(p []byte) (n int, err error) 6 | IsInterfaceNil() bool 7 | } 8 | -------------------------------------------------------------------------------- /test/contracts/bad-misc/bad-misc.export: -------------------------------------------------------------------------------- 1 | memoryFault 2 | divideByZero 3 | badGetOwner1 4 | badGetBlockHash1 5 | badGetBlockHash2 6 | badGetBlockHash3 7 | badWriteLog1 8 | badWriteLog2 9 | badWriteLog3 10 | badWriteLog4 11 | badBigIntStorageStore1 12 | badRecursive 13 | -------------------------------------------------------------------------------- /test/contracts/mxvm/types.h: -------------------------------------------------------------------------------- 1 | #ifndef _TYPES_H_ 2 | #define _TYPES_H_ 3 | 4 | typedef unsigned char byte; 5 | typedef long long i64; 6 | typedef unsigned int u32; 7 | typedef int i32; 8 | typedef unsigned long long u64; 9 | typedef long long i64; 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | ignore: 2 | - "**/*.pb.go" 3 | - "**testInitializerInputs.go" 4 | - "**testInitializerVMOutput.go" 5 | - "**hosttest/**" 6 | - "**mock/**" 7 | - "**scenario/**" 8 | - "**test/**" 9 | - "**testcommon/**" 10 | - "**testgen/**" 11 | -------------------------------------------------------------------------------- /test/contracts/wasmbacking/mem-min-pages-greater-than-max-pages/output/mem-min-pages-greater-than-max-pages.wat: -------------------------------------------------------------------------------- 1 | ;; compile with: 2 | ;; wat2wasm --no-check 3 | (module 4 | (type $void (func)) 5 | (func $main (type $void)) 6 | (memory $mem 1 0) 7 | (export "memory" (memory $mem)) 8 | (export "main" (func $main)) 9 | ) 10 | -------------------------------------------------------------------------------- /test/contracts/promises/tourist-tracking/trackingSystem.c: -------------------------------------------------------------------------------- 1 | #include "../mxvm/context.h" 2 | 3 | byte isTrainBooked[] = "trainBooked"; 4 | 5 | void init() { 6 | int64storageStore(isTrainBooked, sizeof(isTrainBooked), 0); 7 | } 8 | 9 | void bookTrain() { 10 | int64storageStore(isTrainBooked, sizeof(isTrainBooked), 1); 11 | } 12 | -------------------------------------------------------------------------------- /test/contracts/misc/misc.c: -------------------------------------------------------------------------------- 1 | #include "../mxvm/context.h" 2 | 3 | byte array[] = "this is some random string of bytes"; 4 | i64 arrayLength = 35; 5 | 6 | void iterate_over_byte_array() { 7 | finish(array, arrayLength); 8 | finish((byte*)&arrayLength, 1); 9 | 10 | for (int i = 0; i < arrayLength; i++) { 11 | finish(&array[i], 1); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /test/contracts/wasmbacking/noglobals/output/noglobals.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type (;0;) (func (param i64))) 3 | (type (;1;) (func)) 4 | (import "env" "int64finish" (func (;0;) (type 0))) 5 | (func (;1;) (type 1) 6 | i64.const 42 7 | call 0 8 | ) 9 | (memory (;0;) 2) 10 | (export "memory" (memory 0)) 11 | (export "getnumber" (func 1)) 12 | ) 13 | -------------------------------------------------------------------------------- /test/contracts/signatures/signatures.c: -------------------------------------------------------------------------------- 1 | #include "../mxvm/types.h" 2 | 3 | // No imports provided on purpose. 4 | 5 | // It is intended exclusively to test the arity checker. 6 | 7 | void goodFunction() { 8 | } 9 | 10 | byte wrongReturn() { 11 | return 0; 12 | } 13 | 14 | void wrongParams(int param) { 15 | } 16 | 17 | void* wrongParamsAndReturn(int q, byte *p) { 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /test/contracts/wasmbacking/mem-no-pages/output/mem-no-pages.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type $void (func)) 3 | (type $finish(func (param i64))) 4 | (import "env" "int64finish" (func $int64finish (type $finish))) 5 | (func $main (type $void) 6 | i64.const 42 7 | call $int64finish 8 | ) 9 | (memory $mem 0) 10 | (export "memory" (memory $mem)) 11 | (export "main" (func $main)) 12 | ) 13 | -------------------------------------------------------------------------------- /test/contracts/wasmbacking/mem-single-page/output/mem-single-page.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type $void (func)) 3 | (type $finish(func (param i64))) 4 | (import "env" "int64finish" (func $int64finish (type $finish))) 5 | (func $main (type $void) 6 | i64.const 42 7 | call $int64finish 8 | ) 9 | (memory $mem 1) 10 | (export "memory" (memory $mem)) 11 | (export "main" (func $main)) 12 | ) 13 | -------------------------------------------------------------------------------- /test/contracts/wasmbacking/multiple-memories/output/multiple-memories.wat: -------------------------------------------------------------------------------- 1 | ;; compile with: 2 | ;; wat2wasm --no-check 3 | (module 4 | (type $void (func)) 5 | (func $main (type $void)) 6 | (memory $mem1 1 2) 7 | (memory $mem2 2 4) 8 | (memory $mem3 3 6) 9 | (memory $mem4 4 8) 10 | (memory $mem5 5 10) 11 | (export "memory" (memory $mem1)) 12 | (export "main" (func $main)) 13 | ) 14 | -------------------------------------------------------------------------------- /test/contracts/wasmbacking/mem-no-max-pages/output/mem-no-max-pages.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type $void (func)) 3 | (type $finish(func (param i64))) 4 | (import "env" "int64finish" (func $int64finish (type $finish))) 5 | (func $main (type $void) 6 | i64.const 42 7 | call $int64finish 8 | ) 9 | (memory $mem 0 0) 10 | (export "memory" (memory $mem)) 11 | (export "main" (func $main)) 12 | ) 13 | -------------------------------------------------------------------------------- /test/contracts/wasmbacking/mem-multiple-pages/output/mem-multiple-pages.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type $void (func)) 3 | (type $finish(func (param i64))) 4 | (import "env" "int64finish" (func $int64finish (type $finish))) 5 | (func $main (type $void) 6 | i64.const 42 7 | call $int64finish 8 | ) 9 | (memory $mem 10) 10 | (export "memory" (memory $mem)) 11 | (export "main" (func $main)) 12 | ) 13 | -------------------------------------------------------------------------------- /test/contracts/exec-same-ctx-simple-child/exec-same-ctx-simple-child.c: -------------------------------------------------------------------------------- 1 | #include "../mxvm/context.h" 2 | 3 | const int dataLen = 100; 4 | byte data[dataLen] = {}; 5 | 6 | void childFunction() { 7 | byte msg[] = "child"; 8 | finish(msg, 5); 9 | 10 | for (int i = 0; i < dataLen; i++) { 11 | data[i] = i; 12 | } 13 | 14 | for (int i = 1; i <= dataLen; i++) { 15 | int64finish(data[i-1]); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /test/contracts/wasmbacking/mem-multiple-max-pages/output/mem-multiple-max-pages.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type $void (func)) 3 | (type $finish(func (param i64))) 4 | (import "env" "int64finish" (func $int64finish (type $finish))) 5 | (func $main (type $void) 6 | i64.const 42 7 | call $int64finish 8 | ) 9 | (memory $mem 10 10) 10 | (export "memory" (memory $mem)) 11 | (export "main" (func $main)) 12 | ) 13 | -------------------------------------------------------------------------------- /test/contracts/num-with-fp/num-with-fp.c: -------------------------------------------------------------------------------- 1 | typedef unsigned char byte; 2 | typedef unsigned int i32; 3 | typedef unsigned long long i64; 4 | 5 | void int64finish(i64 value); 6 | 7 | void doSomething() { 8 | i64 x = 6; 9 | float a = 1.0f; 10 | a = a + 0.3f; 11 | float q = x * a; 12 | 13 | i64 s = *(i64*)(&q); 14 | 15 | int64finish(s); 16 | } 17 | 18 | void init() { 19 | } 20 | 21 | void _main() { 22 | } 23 | -------------------------------------------------------------------------------- /test/contracts/deployer-child/deployer-child.c: -------------------------------------------------------------------------------- 1 | #include "../mxvm/context.h" 2 | #include "../mxvm/test_utils.h" 3 | 4 | byte parentAddress[32] = {}; 5 | 6 | void init() { 7 | getArgument(0, parentAddress); 8 | 9 | int isParentContract = isSmartContract(parentAddress); 10 | if (isParentContract == 0) { 11 | byte message[] = "[from child] parent not a contract"; 12 | signalError(message, sizeof(message) - 1); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /test/contracts/managed-buffers/managed-buffers.export: -------------------------------------------------------------------------------- 1 | init 2 | mBufferMethod 3 | mBufferNewTest 4 | mBufferNewFromBytesTest 5 | mBufferSetRandomTest 6 | mBufferGetLengthTest 7 | mBufferGetBytesTest 8 | mBufferSetByteSliceTest 9 | mBufferAppendTest 10 | mBufferToBigIntUnsignedTest 11 | mBufferToBigIntSignedTest 12 | mBufferFromBigIntUnsignedTest 13 | mBufferFromBigIntSignedTest 14 | mBufferStorageStoreTest 15 | mBufferStorageLoadTest 16 | -------------------------------------------------------------------------------- /test/contracts/init-simple-popcnt/init-simple-popcnt.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type (;0;) (func (param i64))) 3 | (type (;1;) (func)) 4 | (import "env" "int64finish" (func (;0;) (type 0))) 5 | (func (;1;) (type 1) 6 | i64.const 42 7 | i64.popcnt 8 | call 0) 9 | (table (;0;) 1 1 funcref) 10 | (memory (;0;) 2) 11 | (global (;0;) (mut i32) (i32.const 66560)) 12 | (export "memory" (memory 0)) 13 | (export "init" (func 1))) 14 | -------------------------------------------------------------------------------- /test/contracts/erc20/output/erc20.imports.json: -------------------------------------------------------------------------------- 1 | [ 2 | "bigIntGetUnsignedBytes", 3 | "writeLog", 4 | "getNumArguments", 5 | "signalError", 6 | "getCaller", 7 | "bigIntNew", 8 | "bigIntGetUnsignedArgument", 9 | "bigIntStorageStoreUnsigned", 10 | "bigIntStorageLoadUnsigned", 11 | "bigIntFinishUnsigned", 12 | "getArgument", 13 | "bigIntCmp", 14 | "bigIntSub", 15 | "bigIntAdd", 16 | "int64finish" 17 | ] -------------------------------------------------------------------------------- /test/contracts/wasmbacking/mem-grow/output/mem-grow.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type $void (func)) 3 | (type $finish(func (param i64))) 4 | (import "env" "int64finish" (func $int64finish (type $finish))) 5 | (func $main (type $void) 6 | i32.const 5 7 | memory.grow 8 | drop 9 | memory.size 10 | i64.extend_i32_u 11 | call $int64finish 12 | ) 13 | (memory $mem 1) 14 | (export "memory" (memory $mem)) 15 | (export "main" (func $main)) 16 | ) 17 | -------------------------------------------------------------------------------- /wasmer2/wasmer2.go: -------------------------------------------------------------------------------- 1 | // Package wasmer2 is a Go library to run WebAssembly binaries. 2 | package wasmer2 3 | 4 | import logger "github.com/multiversx/mx-chain-logger-go" 5 | 6 | // VM logger. 7 | var logWasmer2 = logger.GetOrCreate("vm/executor") 8 | 9 | // Executor logger. 10 | type LogLevel uint64 11 | 12 | const ( 13 | LogLevelOff LogLevel = iota 14 | LogLevelError 15 | LogLevelWarn 16 | LogLevelInfo 17 | LogLevelDebug 18 | LogLevelTrace 19 | ) 20 | -------------------------------------------------------------------------------- /test/promises/promises_different_shards.async-call.json: -------------------------------------------------------------------------------- 1 | {"CallerAddr":"bXlfYWNjb3VudF9fX19fX19fX19fX19fX19fX19fX18=","ReturnData":null,"AsyncContextMap":{"my_first_vacation\u0000":{"Callback":"","AsyncCalls":[{"Status":0,"Destination":"dHJhaW5TQy4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4=","Data":"Ym9va1RyYWlu","GasLimit":4000000,"ValueBytes":"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=","SuccessCallback":"myTrainSuccess","ErrorCallback":"myTrainError","ProvidedGas":4000000}]}}} -------------------------------------------------------------------------------- /vmhost/vmhooks/generate/cmd/README.md: -------------------------------------------------------------------------------- 1 | # VM Hooks Code generator 2 | 3 | The code generator generates boilerplate code for both this Go VM, and for [the executor repository](https://github.com/multiversx/mx-vm-executor-rs) 4 | 5 | For it to automatically copy files there, create a file called `wasm-vm-executor-rs-path.txt` here, in the `cmd` folder, contianing your local path to that repository, on your disk. 6 | 7 | Finally, simply run `go generate` in `vmhost/vmhooks`. 8 | -------------------------------------------------------------------------------- /test/contracts/wasmbacking/middleware-globals/output/middleware-globals.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type (;0;) (func (param i64))) 3 | (type (;1;) (func)) 4 | (import "env" "int64finish" (func (;0;) (type 0))) 5 | (func (;1;) (type 1) 6 | global.get 2 7 | call 0 8 | ) 9 | (memory (;0;) 2) 10 | (export "memory" (memory 0)) 11 | (global (;0;) (mut i64) (i64.const 42)) 12 | (global (;1;) (mut i64) (i64.const 43)) 13 | (export "getglobal" (func 1)) 14 | ) 15 | -------------------------------------------------------------------------------- /test/promises/promises_only_db_different_shard.sc_promise.async-call.json: -------------------------------------------------------------------------------- 1 | {"CallerAddr":"bXlfYWNjb3VudF9fX19fX19fX19fX19fX19fX19fX18=","ReturnData":null,"AsyncContextMap":{"my_first_vacation\u0000":{"Callback":"","AsyncCalls":[{"Status":0,"Destination":"dHJhaW5TQy4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4=","Data":"Ym9va1RyYWlu","GasLimit":4000000,"ValueBytes":"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=","SuccessCallback":"myTrainSuccess","ErrorCallback":"myTrainError","ProvidedGas":4000000}]}}} -------------------------------------------------------------------------------- /test/promises/promises_only_db_different_shard.sc_train.async-call.json: -------------------------------------------------------------------------------- 1 | {"CallerAddr":"cHJvbWlzZVNDLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4=","ReturnData":null,"AsyncContextMap":{"somebody_booking_train\u0000":{"Callback":"","AsyncCalls":[{"Status":0,"Destination":"ZGF0YVNDLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4uLi4=","Data":"Ym9va1RyYWlu","GasLimit":2000000,"ValueBytes":"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=","SuccessCallback":"bookTrainSuccess","ErrorCallback":"bookTrainError","ProvidedGas":2000000}]}}} -------------------------------------------------------------------------------- /test/contracts/forbidden-opcodes/data-drop/output/data-drop.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type $void (func)) 3 | (type $finish(func (param i64))) 4 | (import "env" "int64finish" (func $int64finish (type $finish))) 5 | (func $main (type $void) 6 | (data.drop 0) ;; drop the data segment 0 7 | (i64.const 0) 8 | (call $int64finish) 9 | ) 10 | (memory $mem 1) 11 | (export "memory" (memory $mem)) 12 | (export "main" (func $main)) 13 | (data "ok") ;; data segment 0 14 | ) 15 | -------------------------------------------------------------------------------- /test/contracts/wasmbacking/imported-global/output/imported-global.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type $singleParam (func (param i64))) 3 | (type $void (func)) 4 | (global $importedG (import "env" "importedG") i64) 5 | (import "env" "int64finish" (func $int64finish (type $singleParam))) 6 | (func $main (type $singleParam) 7 | global.get $importedG 8 | call $int64finish 9 | ) 10 | (memory (;0;) 2) 11 | (export "memory" (memory 0)) 12 | (export "get_imported_global" (func $main)) 13 | ) 14 | -------------------------------------------------------------------------------- /wasmer2/wasmer2ImportsCgoHelper.go: -------------------------------------------------------------------------------- 1 | package wasmer2 2 | 3 | import ( 4 | "unsafe" 5 | 6 | "github.com/multiversx/mx-chain-vm-go/executor" 7 | ) 8 | 9 | func getVMHooksFromContextRawPtr(contextRawPtr unsafe.Pointer) executor.VMHooks { 10 | vmHooksPtrPtr := (*uintptr)(contextRawPtr) 11 | vmHooksPtr := *vmHooksPtrPtr 12 | return *(*executor.VMHooks)(unsafe.Pointer(vmHooksPtr)) 13 | } 14 | 15 | func funcPointer(cFuncPtr unsafe.Pointer) *[0]byte { 16 | return (*[0]byte)(cFuncPtr) 17 | } 18 | -------------------------------------------------------------------------------- /test/contracts/answer-locals/answer-locals.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type (;0;) (func (param i64))) 3 | (type (;1;) (func)) 4 | (import "env" "int64finish" (func (;0;) (type 0))) 5 | (func (;1;) (type 1)) 6 | (func (;2;) (type 1) 7 | (local i64 i64 i64 i64) 8 | i64.const 42 9 | call 0) 10 | (table (;0;) 1 1 funcref) 11 | (memory (;0;) 2) 12 | (global (;0;) (mut i32) (i32.const 66560)) 13 | (export "memory" (memory 0)) 14 | (export "init" (func 1)) 15 | (export "answer" (func 2))) 16 | -------------------------------------------------------------------------------- /test/contracts/wasmbacking/single-mutable/output/single-mutable.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type (;0;) (func (param i64))) 3 | (type (;1;) (func)) 4 | (import "env" "int64finish" (func (;0;) (type 0))) 5 | (func (;1;) (type 1) 6 | global.get 0 7 | i64.const 1 8 | i64.add 9 | global.set 0 10 | 11 | global.get 0 12 | call 0 13 | ) 14 | (memory (;0;) 2) 15 | (global (;0;) (mut i64) (i64.const 66560)) 16 | (export "memory" (memory 0)) 17 | (export "getglobal" (func 1)) 18 | ) 19 | -------------------------------------------------------------------------------- /test/contracts/mxvm/cbuiltins.c: -------------------------------------------------------------------------------- 1 | #include "types.h" 2 | 3 | void* memset(void *dest, int c, unsigned long n) { 4 | byte v = (byte)c; 5 | for (unsigned long i = 0; i < n; i++) { 6 | ((byte*)dest)[i] = v; 7 | } 8 | return dest; 9 | } 10 | 11 | void *memcpy(void *dest, const void *src, unsigned long n) 12 | { 13 | char *csrc = (char *)src; 14 | char *cdest = (char *)dest; 15 | 16 | for (unsigned long i = 0; i < n; i++) 17 | { 18 | cdest[i] = csrc[i]; 19 | } 20 | 21 | return dest; 22 | } -------------------------------------------------------------------------------- /vmhost/vmhooks/generate/eiGenWriteRustVMHooksNames.go: -------------------------------------------------------------------------------- 1 | package vmhooksgenerate 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func WriteRustHookNames( 8 | out *eiGenWriter, 9 | eiMetadata *EIMetadata, 10 | ) { 11 | autoGeneratedHeader(out) 12 | out.WriteString("\n") 13 | out.WriteString("pub const EI_1_5_NAMES: &[&str] = &[") 14 | 15 | for _, funcMetadata := range eiMetadata.AllFunctions { 16 | out.WriteString(fmt.Sprintf("\n \"%s\",", lowerInitial(funcMetadata.Name))) 17 | } 18 | 19 | out.WriteString(` 20 | ]; 21 | `) 22 | } 23 | -------------------------------------------------------------------------------- /crypto/signing/errors.go: -------------------------------------------------------------------------------- 1 | package signing 2 | 3 | import ( 4 | "errors" 5 | ) 6 | 7 | // ErrInvalidPublicKey is raised when an invalid public key is used 8 | var ErrInvalidPublicKey = errors.New("public key is invalid") 9 | 10 | // ErrInvalidSignature will be returned when ed25519 signature verification fails 11 | var ErrInvalidSignature = errors.New("invalid signature") 12 | 13 | // ErrHasherNotSupported will be returned when a provided hasher type is not supported by the signature scheme 14 | var ErrHasherNotSupported = errors.New("hasher not supported") 15 | -------------------------------------------------------------------------------- /test/contracts/big-floats/big-floats.export: -------------------------------------------------------------------------------- 1 | init 2 | BigFloatNewFromPartsTest 3 | BigFloatNewFromFracTest 4 | BigFloatNewFromSciTest 5 | BigFloatAddTest 6 | BigFloatSubTest 7 | BigFloatMulTest 8 | BigFloatDivTest 9 | BigFloatTruncateTest 10 | BigFloatAbsTest 11 | BigFloatNegTest 12 | BigFloatCmpTest 13 | BigFloatSignTest 14 | BigFloatCloneTest 15 | BigFloatSqrtTest 16 | BigFloatPowTest 17 | BigFloatFloorTest 18 | BigFloatCeilTest 19 | BigFloatIsIntTest 20 | BigFloatSetInt64Test 21 | BigFloatSetBigIntTest 22 | BigFloatGetConstPiTest 23 | BigFloatGetConstETest 24 | -------------------------------------------------------------------------------- /test/contracts/breakpoint/breakpoint.c: -------------------------------------------------------------------------------- 1 | #include "../mxvm/context.h" 2 | 3 | byte array[32] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; 4 | 5 | void testFunc() { 6 | i64 arg = int64getArgument(0); 7 | 8 | if (arg == 1) { 9 | byte msg[] = "exit here"; 10 | signalError(msg, 9); 11 | byte msg2[] = "exit later"; 12 | signalError(msg2, 10); 13 | } 14 | 15 | if (arg == 2) { 16 | array[2147483647] = 42; 17 | int64finish(array[2147483647]); 18 | } 19 | 20 | int64finish(100); 21 | } 22 | -------------------------------------------------------------------------------- /mock/contracts/gasMismatchChild.go: -------------------------------------------------------------------------------- 1 | package contracts 2 | 3 | import ( 4 | "math/big" 5 | 6 | mock "github.com/multiversx/mx-chain-vm-go/mock/context" 7 | ) 8 | 9 | // GasMismatchAsyncCallChildMock is an exposed mock contract method 10 | func GasMismatchAsyncCallChildMock(instanceMock *mock.InstanceMock, _ interface{}) { 11 | instanceMock.AddMockMethod("gasMismatchChild", func() *mock.InstanceMock { 12 | host := instanceMock.Host 13 | instance := mock.GetMockInstance(host) 14 | host.Output().Finish(big.NewInt(42).Bytes()) 15 | return instance 16 | }) 17 | } 18 | -------------------------------------------------------------------------------- /test/attestation-c/main.scen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "all tests", 3 | "steps": [ 4 | { 5 | "step": "externalSteps", 6 | "path": "attestation_init_steps.json" 7 | }, 8 | { 9 | "step": "externalSteps", 10 | "path": "register_ok.steps.json" 11 | }, 12 | { 13 | "step": "externalSteps", 14 | "path": "save_public_info_ok.steps.json" 15 | }, 16 | { 17 | "step": "externalSteps", 18 | "path": "attest_ok.steps.json" 19 | } 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /test/contracts/big-floats-2/big-floats.export: -------------------------------------------------------------------------------- 1 | init 2 | BigFloatToManagedBufferTest 3 | BigFloatNewFromPartsTest 4 | BigFloatNewFromFracTest 5 | BigFloatNewFromSciTest 6 | BigFloatAddTest 7 | BigFloatSubTest 8 | BigFloatMulTest 9 | BigFloatDivTest 10 | BigFloatTruncateTest 11 | BigFloatAbsTest 12 | BigFloatNegTest 13 | BigFloatCmpTest 14 | BigFloatSignTest 15 | BigFloatCloneTest 16 | BigFloatSqrtTest 17 | BigFloatPowTest 18 | BigFloatFloorTest 19 | BigFloatCeilTest 20 | BigFloatIsIntTest 21 | BigFloatSetInt64Test 22 | BigFloatSetBigIntTest 23 | BigFloatGetConstPiTest 24 | BigFloatGetConstETest 25 | -------------------------------------------------------------------------------- /test/contracts/forbidden-opcodes/memory-fill/output/memory-fill.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type $void (func)) 3 | (type $finish(func (param i64))) 4 | (import "env" "int64finish" (func $int64finish (type $finish))) 5 | (func $main (type $void) 6 | (memory.fill 7 | (i32.const 42) ;; destination address 8 | (i32.const 5) ;; byte value to set 9 | (i32.const 7) ;; size of memory region in bytes 10 | ) 11 | (i64.const 0) 12 | (call $int64finish) 13 | ) 14 | (memory $mem 1) 15 | (export "memory" (memory $mem)) 16 | (export "main" (func $main)) 17 | ) 18 | -------------------------------------------------------------------------------- /test/contracts/wasmbacking/single-immutable/output/single-immutable.wat: -------------------------------------------------------------------------------- 1 | ;; compile with: 2 | ;; wat2wasm --no-check 3 | (module 4 | (type (;0;) (func (param i64))) 5 | (type (;1;) (func)) 6 | (import "env" "int64finish" (func (;0;) (type 0))) 7 | (func (;1;) (type 1) 8 | global.get 1 9 | i64.const 1 10 | i64.add 11 | global.set 1 12 | 13 | global.get 1 14 | call 0 15 | ) 16 | (memory (;0;) 2) 17 | (global (;0;) (mut i64) (i64.const 66560)) 18 | (global (;1;) i64 (i64.const 42)) 19 | (export "memory" (memory 0)) 20 | (export "getglobal" (func 1)) 21 | ) 22 | -------------------------------------------------------------------------------- /fuzz/delegation/v0.3/fuzzDelegationInvariants.go: -------------------------------------------------------------------------------- 1 | package delegation 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func (pfe *fuzzDelegationExecutor) checkNoUnexpectedBalance() error { 8 | err := pfe.computeAllRewards() 9 | if err != nil { 10 | return err 11 | } 12 | 13 | unexpectedBalance, err := pfe.simpleQuery("getUnexpectedBalance") 14 | if err != nil { 15 | return err 16 | } 17 | 18 | if unexpectedBalance.Sign() > 0 { 19 | return fmt.Errorf( 20 | "should not have unexpected balance in the fuzzer. Unexpected balance: %d", 21 | unexpectedBalance) 22 | } 23 | 24 | return nil 25 | } 26 | -------------------------------------------------------------------------------- /test/attestation-rust/scenarios/main.scen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "all tests", 3 | "steps": [ 4 | { 5 | "step": "externalSteps", 6 | "path": "attestation_init_steps.json" 7 | }, 8 | { 9 | "step": "externalSteps", 10 | "path": "register_ok.steps.json" 11 | }, 12 | { 13 | "step": "externalSteps", 14 | "path": "save_public_info_ok.steps.json" 15 | }, 16 | { 17 | "step": "externalSteps", 18 | "path": "attest_ok.steps.json" 19 | } 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /test/contracts/exec-dest-ctx-by-caller/child/child.c: -------------------------------------------------------------------------------- 1 | #include "../../mxvm/context.h" 2 | #include "../../mxvm/test_utils.h" 3 | 4 | 5 | void give() { 6 | int numArgs = getNumArguments(); 7 | if (numArgs != 1) { 8 | byte message[] = "wrong number of arguments"; 9 | signalError(message, 25); 10 | } 11 | 12 | byte value_to_give = 0; 13 | getArgument(0, &value_to_give); 14 | 15 | byte caller[32] = {0}; 16 | getCaller(caller); 17 | 18 | byte value[32] = {0}; 19 | value[31] = value_to_give; 20 | 21 | transferValue(caller, value, 0, 0); 22 | 23 | byte msg[] = "sent"; 24 | finish(msg, 4); 25 | } 26 | -------------------------------------------------------------------------------- /test/contracts/opcodes/opcodes.c: -------------------------------------------------------------------------------- 1 | #include "../mxvm/context.h" 2 | 3 | void memSize() { 4 | i64 count = int64getArgument(0); 5 | for (i64 i = 0; i < count; i++) { 6 | asm ( 7 | "memory.size 0\n" 8 | "drop\n" 9 | ); 10 | int64finish(i); 11 | } 12 | } 13 | 14 | void memGrowDelta() { 15 | i64 count = int64getArgument(0); 16 | i32 delta = int64getArgument(1); 17 | for (i64 i = 0; i < count; i++) { 18 | asm ( 19 | "local.get %[delta]\n" 20 | "memory.grow 0\n" 21 | "drop\n" 22 | : /* No outputs, only inputs below */ 23 | : [delta] "r" (delta) 24 | ); 25 | int64finish(i); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /test/contracts/async-call-builtin/async-call-builtin.c: -------------------------------------------------------------------------------- 1 | #include "../mxvm/context.h" 2 | 3 | byte scAddress[] = "\0\0\0\0\0\0\0\0\x0F\x0FparentSC.............."; 4 | byte value[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; 5 | 6 | void performAsyncCallToBuiltin() { 7 | i64 arg = int64getArgument(0); 8 | 9 | byte msg[] = "hello"; 10 | finish(msg, 5); 11 | 12 | if (arg == 1) { 13 | byte callData[] = "builtinFail"; 14 | asyncCall(scAddress, value, callData, 11); 15 | } 16 | } 17 | 18 | void callBack() { 19 | i64 returnCode = int64getArgument(0); 20 | 21 | int64finish(returnCode); 22 | } 23 | -------------------------------------------------------------------------------- /scenario/gasSchedules/gasSchedules.go: -------------------------------------------------------------------------------- 1 | package gasschedules 2 | 3 | // TODO: go:embed can be used after we upgrade to go 1.16 4 | // import _ "embed" 5 | 6 | // //go:embed gasScheduleV1.toml 7 | // var gasScheduleV1 string 8 | 9 | // //go:embed gasScheduleV2.toml 10 | // var gasScheduleV2 string 11 | 12 | // //go:embed gasScheduleV3.toml 13 | // var gasScheduleV3 string 14 | 15 | //go:generate go run scripts/includetoml.go 16 | 17 | // GetV3 yields the schedule V3 18 | func GetV3() string { 19 | return gasScheduleV3 20 | } 21 | 22 | // GetV4 yields the schedule V4 23 | func GetV4() string { 24 | return gasScheduleV4 25 | } 26 | -------------------------------------------------------------------------------- /test/contracts/forbidden-opcodes/memory-copy/output/memory-copy.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type $void (func)) 3 | (type $finish(func (param i64))) 4 | (import "env" "int64finish" (func $int64finish (type $finish))) 5 | (func $main (type $void) 6 | (memory.copy 7 | (i32.const 42) ;; destination address 8 | (i32.const 1024) ;; source address 9 | (i32.const 2) ;; size of memory region in bytes 10 | ) 11 | (i64.const 0) 12 | (call $int64finish) 13 | ) 14 | (memory $mem 1) 15 | (export "memory" (memory $mem)) 16 | (export "main" (func $main)) 17 | (data (i32.const 1024) "ok") 18 | ) 19 | -------------------------------------------------------------------------------- /vmhost/hostCore/executionAsync.go: -------------------------------------------------------------------------------- 1 | package hostCore 2 | 3 | import ( 4 | "github.com/multiversx/mx-chain-vm-go/vmhost" 5 | ) 6 | 7 | func (host *vmHost) handleAsyncCallBreakpoint() error { 8 | runtime := host.Runtime() 9 | async := host.Async() 10 | runtime.SetRuntimeBreakpointValue(vmhost.BreakpointNone) 11 | 12 | legacyGroupID := vmhost.LegacyAsyncCallGroupID 13 | legacyGroup, exists := async.GetCallGroup(legacyGroupID) 14 | if !exists { 15 | return vmhost.ErrLegacyAsyncCallNotFound 16 | 17 | } 18 | 19 | if legacyGroup.IsComplete() { 20 | return vmhost.ErrLegacyAsyncCallInvalid 21 | } 22 | 23 | return nil 24 | } 25 | -------------------------------------------------------------------------------- /test/ping-pong-egld/scenarios/ping-pong-call-pong-all.scen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "call pong all in order to send the funds back to everyone", 3 | "gasSchedule": "v3", 4 | "steps": [ 5 | { 6 | "step": "externalSteps", 7 | "path": "ping-pong-call-ping-second-user.scen.json" 8 | }, 9 | { 10 | "step": "setState", 11 | "currentBlockInfo": { 12 | "blockTimestamp": "123,781" 13 | } 14 | }, 15 | { 16 | "step": "externalSteps", 17 | "path": "ping-pong-call-pong-all.steps.json" 18 | } 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /test/contracts/forbidden-opcodes/simd/output/simd.wat: -------------------------------------------------------------------------------- 1 | ;; SIMD instructions are not supported at the moment 2 | ;; Using any two SIMD instructions just to see the contract is invalid 3 | (module 4 | (type $void (func)) 5 | (type $finish(func (param i64))) 6 | (import "env" "int64finish" (func $int64finish (type $finish))) 7 | (func $main (type $void) 8 | (i32.const 42) 9 | (i8x16.splat) ;; Create vector with identical lanes 10 | (i64x2.extract_lane 1) ;; Extract lane 1 as a scalar 11 | (call $int64finish) 12 | ) 13 | (memory $mem 1) 14 | (export "memory" (memory $mem)) 15 | (export "main" (func $main)) 16 | ) 17 | -------------------------------------------------------------------------------- /test/contracts/init-correct/init-correct.c: -------------------------------------------------------------------------------- 1 | #include "../mxvm/context.h" 2 | 3 | void init() { 4 | if (getNumArguments() == 0) { 5 | unsigned char msg[] = "init successful"; 6 | finish(msg, 15); 7 | return; 8 | } 9 | 10 | byte arg = 0; 11 | getArgument(0, &arg); 12 | 13 | if (arg == 0) { 14 | unsigned char msg[] = "init successful"; 15 | finish(msg, 15); 16 | } 17 | 18 | if (arg == 1) { 19 | byte msg[] = "don't do this"; 20 | signalError(msg, 13); 21 | } 22 | 23 | if (arg == 2) { 24 | byte msg[] = "loop"; 25 | while (1) { 26 | finish(msg, 4); 27 | } 28 | } 29 | } 30 | 31 | void upgrade() { 32 | init(); 33 | } 34 | -------------------------------------------------------------------------------- /vmhost/vmhooks/generate/eiGenWriteHeaders.go: -------------------------------------------------------------------------------- 1 | package vmhooksgenerate 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func autoGeneratedHeader(out *eiGenWriter) { 8 | out.WriteString(`// Code generated by vmhooks generator. DO NOT EDIT. 9 | 10 | // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 11 | // !!!!!!!!!!!!!!!!!!!!!! AUTO-GENERATED FILE !!!!!!!!!!!!!!!!!!!!!! 12 | // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 13 | `) 14 | } 15 | 16 | func autoGeneratedGoHeader(out *eiGenWriter, packageName string) { 17 | out.WriteString(fmt.Sprintf(`package %s 18 | 19 | `, packageName)) 20 | autoGeneratedHeader(out) 21 | } 22 | -------------------------------------------------------------------------------- /vmhost/vmhooks/generate/eiGenWriter.go: -------------------------------------------------------------------------------- 1 | package vmhooksgenerate 2 | 3 | import ( 4 | "os" 5 | "path/filepath" 6 | ) 7 | 8 | type eiGenWriter struct { 9 | outFile *os.File 10 | } 11 | 12 | func NewEIGenWriter(pathToApiPackage string, relativePath string) *eiGenWriter { 13 | outFile, err := os.Create(filepath.Join(pathToApiPackage, relativePath)) 14 | if err != nil { 15 | panic(err) 16 | } 17 | return &eiGenWriter{ 18 | outFile: outFile, 19 | } 20 | } 21 | 22 | func (writer *eiGenWriter) WriteString(s string) { 23 | _, _ = writer.outFile.WriteString(s) 24 | } 25 | 26 | func (writer *eiGenWriter) Close() { 27 | _ = writer.outFile.Close() 28 | } 29 | -------------------------------------------------------------------------------- /test/contracts/exchange/snippets.sh: -------------------------------------------------------------------------------- 1 | DENOMINATION="000000000000000000" 2 | PROXY="https://api.multiversx.com" 3 | CHAIN="BoN" 4 | ALICE_PEM="~/wallet/alice.pem" 5 | CONTRACT_ADDRESS="erd1YourContractHere" 6 | 7 | deploy() { 8 | erdpy contract deploy ${CONTRACT_FOLDER} --recall-nonce --pem=${ALICE_PEM} --gas-limit=50000000 --proxy=${PROXY} --chain=${CHAIN} 9 | } 10 | 11 | add() { 12 | erdpy --verbose contract call ${CONTRACT_ADDRESS} --recall-nonce --pem=${ALICE_PEM} --gas-limit=50000000 --function="add" --proxy=${PROXY} --arguments 0x0064 13 | } 14 | 15 | getSum() { 16 | erdpy --verbose contract query ${CONTRACT_ADDRESS} --function="getSum" --proxy=${PROXY} 17 | } 18 | -------------------------------------------------------------------------------- /test/contracts/forbidden-opcodes/memory-init/output/memory-init.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type $void (func)) 3 | (type $finish(func (param i64))) 4 | (import "env" "int64finish" (func $int64finish (type $finish))) 5 | (func $main (type $void) 6 | (memory.init 0 ;; init from data segment 0 7 | (i32.const 42) ;; destination address 8 | (i32.const 0) ;; offset into the source segment 9 | (i32.const 2) ;; size of memory region in bytes 10 | ) 11 | (i64.const 0) 12 | (call $int64finish) 13 | ) 14 | (memory $mem 1) 15 | (export "memory" (memory $mem)) 16 | (export "main" (func $main)) 17 | (data "ok") ;; data segment 0 18 | ) 19 | -------------------------------------------------------------------------------- /integrationTests/json/scenariosExecutorVersions_test.go: -------------------------------------------------------------------------------- 1 | package vmjsonintegrationtest 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/multiversx/mx-chain-vm-go/executor" 7 | "github.com/multiversx/mx-chain-vm-go/wasmer2" 8 | ) 9 | 10 | func TestCErc20Executors_TwiceW1ThenTwiceW2(t *testing.T) { 11 | testCERC20WithExecutorFactory(t, wasmer2.ExecutorFactory()) 12 | testCERC20WithExecutorFactory(t, wasmer2.ExecutorFactory()) 13 | } 14 | 15 | func testCERC20WithExecutorFactory(t *testing.T, factory executor.ExecutorAbstractFactory) { 16 | ScenariosTest(t). 17 | Folder("erc20-c"). 18 | WithExecutorFactory(factory). 19 | WithExecutorLogs(). 20 | Run(). 21 | CheckNoError() 22 | } 23 | -------------------------------------------------------------------------------- /test/contracts/mxvm/args.h: -------------------------------------------------------------------------------- 1 | #ifndef _ARGS_H_ 2 | #define _ARGS_H_ 3 | 4 | #include "types.h" 5 | 6 | static const int MAX_BINARY_ARGS = 10; 7 | 8 | typedef struct binaryArgs { 9 | byte *arguments[MAX_BINARY_ARGS]; 10 | byte lengths[MAX_BINARY_ARGS]; 11 | unsigned int lengthsAsI32[MAX_BINARY_ARGS]; 12 | int numArgs; 13 | byte *serialized; 14 | int lenSerialized; 15 | } BinaryArgs; 16 | 17 | BinaryArgs NewBinaryArgs(); 18 | int AddBinaryArg(BinaryArgs *args, byte *arg, int arglen); 19 | int TrimLeftZeros(BinaryArgs *args, int argIndex); 20 | int SerializeBinaryArgs(BinaryArgs *args, byte *result); 21 | int SerializeBinaryArgsToDataString(BinaryArgs *args, byte *result); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /test/contracts/bad-recursive/bad-recursive.c: -------------------------------------------------------------------------------- 1 | typedef unsigned char byte; 2 | typedef unsigned int i32; 3 | typedef unsigned long long i64; 4 | typedef unsigned int bigInt; 5 | 6 | bigInt bigIntNew(long long value); 7 | void bigIntFinishUnsigned(bigInt reference); 8 | 9 | void init() 10 | { 11 | } 12 | 13 | i64 doStackoverflow(i64 a) 14 | { 15 | if (a % 2 == 0) 16 | { 17 | return 42; 18 | } 19 | 20 | i64 x = doStackoverflow(a * 8 + 1); 21 | i64 y = doStackoverflow(a * 2 + 1); 22 | return x + y + a; 23 | } 24 | 25 | void badRecursive() 26 | { 27 | i64 result = doStackoverflow(1); 28 | bigInt resultBig = bigIntNew(result); 29 | bigIntFinishUnsigned(resultBig); 30 | } 31 | -------------------------------------------------------------------------------- /test/contracts/signatures/output/signatures.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type (;0;) (func)) 3 | (type (;1;) (func (result i32))) 4 | (type (;2;) (func (param i32))) 5 | (type (;3;) (func (param i32 i32) (result i32))) 6 | (func (;0;) (type 0)) 7 | (func (;1;) (type 1) (result i32) 8 | i32.const 0) 9 | (func (;2;) (type 2) (param i32)) 10 | (func (;3;) (type 3) (param i32 i32) (result i32) 11 | i32.const 0) 12 | (table (;0;) 1 1 funcref) 13 | (memory (;0;) 2) 14 | (global (;0;) (mut i32) (i32.const 66560)) 15 | (export "memory" (memory 0)) 16 | (export "goodFunction" (func 0)) 17 | (export "wrongReturn" (func 1)) 18 | (export "wrongParams" (func 2)) 19 | (export "wrongParamsAndReturn" (func 3))) 20 | -------------------------------------------------------------------------------- /test/contracts/promises/child-simple/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![no_std] 2 | #![no_main] 3 | #![allow(unused_attributes)] 4 | #![feature(lang_items)] 5 | 6 | 7 | 8 | 9 | pub static EEI: VMHooksImpl = VMHooksImpl{}; 10 | 11 | #[no_mangle] 12 | pub extern "C" fn answer() { 13 | EEI.finish_u64(42); 14 | } 15 | 16 | #[no_mangle] 17 | pub extern "C" fn answer_wrong() { 18 | EEI.finish_u64(24); 19 | } 20 | 21 | // receives u64 as argument and returns it back 22 | #[no_mangle] 23 | pub extern "C" fn echo() { 24 | EEI.check_num_arguments(1); 25 | 26 | let arg = EEI.get_argument_u64(0); 27 | 28 | EEI.finish_u64(arg); 29 | } 30 | 31 | #[no_mangle] 32 | pub extern "C" fn fail() { 33 | EEI.signal_error(&b"fail"[..]); 34 | } 35 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # wasm-vm 2 | 3 | [![](https://img.shields.io/badge/made%20by-MultiversX-blue.svg)](http://multiversx.com/) 4 | ![Build](https://github.com/multiversx/mx-chain-vm-go/actions/workflows/build-test.yml/badge.svg?branch=master) 5 | [![Go Report Card](https://goreportcard.com/badge/github.com/multiversx/mx-chain-vm-go)](https://goreportcard.com/report/github.com/multiversx/mx-chain-vm-go) 6 | [![LoC](https://tokei.rs/b1/github/multiversx/mx-chain-vm-go?category=code)](https://github.com/multiversx/mx-chain-vm-go) 7 | [![codecov](https://codecov.io/gh/multiversx/mx-chain-vm-go/branch/master/graph/badge.svg?token=MYS5EDASOJ)](https://codecov.io/gh/multiversx/mx-chain-vm-go) 8 | 9 | WASM-based Virtual Machine for running MultiversX Smart Contracts. 10 | -------------------------------------------------------------------------------- /crypto/signing/ed25519/ed25519.go: -------------------------------------------------------------------------------- 1 | package ed25519 2 | 3 | import ( 4 | libed25519 "crypto/ed25519" 5 | 6 | "github.com/multiversx/mx-chain-vm-go/crypto/signing" 7 | ) 8 | 9 | type ed25519 struct { 10 | } 11 | 12 | // NewEd25519Signer returns the component able to verify Ed25519 signatures 13 | func NewEd25519Signer() *ed25519 { 14 | return &ed25519{} 15 | } 16 | 17 | // VerifyEd25519 verifies a Ed25519 signatures 18 | func (e *ed25519) VerifyEd25519(key []byte, msg []byte, sig []byte) error { 19 | if len(key) != libed25519.PublicKeySize { 20 | return signing.ErrInvalidPublicKey 21 | } 22 | 23 | isValidSig := libed25519.Verify(key, msg, sig) 24 | if !isValidSig { 25 | return signing.ErrInvalidSignature 26 | } 27 | 28 | return nil 29 | } 30 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # ide settings 2 | .idea/ 3 | 4 | # Binaries for programs and plugins 5 | *.exe 6 | *.exe~ 7 | bin/golangci-lint 8 | 9 | # Test binary, build with `go test -c` 10 | *.test 11 | 12 | # Output of the go coverage tool, specifically when used with LiteIDE 13 | *.out 14 | 15 | /vendor 16 | 17 | /vmhost/debug 18 | /vmserver/testdata/db 19 | /cmd/vmserver/vmserver 20 | /cmd/vmserver/db 21 | 22 | # VSCode settings 23 | .vscode 24 | 25 | tags 26 | *.backup 27 | 28 | # SmartContract compilation artefacts 29 | *.hex* 30 | *.ll 31 | *.o 32 | wasm32-unknown-unknown 33 | test/contracts/**/target 34 | test/contracts/**/wasm/target 35 | **/output/*.abi.json 36 | **/output/*.wat 37 | 38 | # Mac 39 | **/.DS_Store 40 | 41 | **/Cargo.lock 42 | vmhost/**/__debug_bin 43 | -------------------------------------------------------------------------------- /mock/contracts/asyncChildSCMultiGroups.go: -------------------------------------------------------------------------------- 1 | package contracts 2 | 3 | import ( 4 | mock "github.com/multiversx/mx-chain-vm-go/mock/context" 5 | test "github.com/multiversx/mx-chain-vm-go/testcommon" 6 | ) 7 | 8 | // ChildAsyncMultiGroupsMock is an exposed mock contract method 9 | func ChildAsyncMultiGroupsMock(instanceMock *mock.InstanceMock, config interface{}) { 10 | testConfig := config.(*test.TestConfig) 11 | for _, groupConfig := range AsyncGroupsConfig { 12 | for g := 1; g < len(groupConfig); g++ { 13 | functionName := groupConfig[g] 14 | instanceMock.AddMockMethod(functionName, 15 | test.WasteGasWithReturnDataMockMethod( 16 | instanceMock, 17 | testConfig.GasUsedByChild, 18 | []byte(functionName+test.TestReturnDataSuffix))) 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /test/contracts/deployer-fromanother-contract/deployer-fromanother-contract.c: -------------------------------------------------------------------------------- 1 | #include "../mxvm/context.h" 2 | #include "../mxvm/test_utils.h" 3 | 4 | byte sourceContractAddress[32] = {}; 5 | byte newAddress[32] = {}; 6 | 7 | byte deploymentValue[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,42}; 8 | 9 | byte arguments[0] = {}; 10 | int argumentsLengths[0] = {}; 11 | 12 | byte contractMetadata[2] = {3, 0}; 13 | 14 | 15 | void deployCodeFromAnotherContract() { 16 | getArgument(0, sourceContractAddress); 17 | 18 | int result = deployFromSourceContract( 19 | 2000, 20 | deploymentValue, 21 | sourceContractAddress, 22 | contractMetadata, 23 | newAddress, 24 | 0, 25 | (byte*)argumentsLengths, 26 | arguments); 27 | 28 | finishResult(result); 29 | } -------------------------------------------------------------------------------- /test/delegation/v0_3/test/integration/stake_partial_err/05_claim_failed.steps.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "activate pt 1", 3 | "steps": [ 4 | { 5 | "step": "scCall", 6 | "id": "claim-failed-stake", 7 | "tx": { 8 | "from": "''node_address__________________s1", 9 | "to": "sc:delegation", 10 | "function": "claimFailedStake", 11 | "arguments": [], 12 | "gasLimit": "10,000,000", 13 | "gasPrice": "0" 14 | }, 15 | "expect": { 16 | "out": [], 17 | "status": "", 18 | "logs": "*", 19 | "gas": "*", 20 | "refund": "*" 21 | } 22 | } 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /test/dns/scenarios/07_bogus_name.steps.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "register, ok", 3 | "steps": [ 4 | { 5 | "step": "scCall", 6 | "id": "bogus-name", 7 | "tx": { 8 | "from": "address:viewer", 9 | "to": "sc:dns#bb", 10 | "function": "resolve", 11 | "arguments": [ 12 | "str:bogusname000.|0x656C726F6E64" 13 | ], 14 | "gasLimit": "50,000,000", 15 | "gasPrice": "0" 16 | }, 17 | "expect": { 18 | "out": [], 19 | "status": "", 20 | "logs": "*", 21 | "gas": "*", 22 | "refund": "*" 23 | } 24 | } 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /vmhost/vmhooks/generate/eiGenWriteGoNames.go: -------------------------------------------------------------------------------- 1 | package vmhooksgenerate 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func WriteNames( 8 | out *eiGenWriter, 9 | packageName string, 10 | eiMetadata *EIMetadata, 11 | ) { 12 | autoGeneratedGoHeader(out, packageName) 13 | out.WriteString(` 14 | var empty struct{} 15 | 16 | var functionNames = map[string]struct{}{`) 17 | 18 | maxNameLength := longestFuncNameLengthCamel(eiMetadata) 19 | for _, funcMetadata := range eiMetadata.AllFunctions { 20 | out.WriteString(fmt.Sprintf("\n\t\"%s\":", lowerInitial(funcMetadata.Name))) 21 | numSpaces := maxNameLength - len(funcMetadata.Name) + 1 22 | for i := 0; i < numSpaces; i++ { 23 | out.WriteString(" ") 24 | } 25 | out.WriteString("empty,") 26 | } 27 | 28 | out.WriteString(` 29 | } 30 | `) 31 | } 32 | -------------------------------------------------------------------------------- /.github/workflows/build-test.yml: -------------------------------------------------------------------------------- 1 | name: Build and run tests 2 | 3 | on: 4 | push: 5 | branches: [ master, rc/*, feat/* ] 6 | pull_request: 7 | branches: [ master, feat/*, rc/* ] 8 | workflow_dispatch: 9 | 10 | jobs: 11 | test: 12 | strategy: 13 | matrix: 14 | go-version: [1.23.6] 15 | os: [ubuntu-latest, macos-13] 16 | runs-on: ${{ matrix.os }} 17 | steps: 18 | - name: Install Go 19 | uses: actions/setup-go@v5 20 | with: 21 | go-version: ${{ matrix.go-version }} 22 | - name: Checkout code 23 | uses: actions/checkout@v4 24 | 25 | - name: Test (Linux) 26 | if: runner.os == 'Linux' 27 | run: | 28 | make test 29 | 30 | - name: Test (MacOS ARM64) 31 | if: runner.os == 'macOS' 32 | run: | 33 | make test-w2 34 | 35 | -------------------------------------------------------------------------------- /test/contracts/exec-dest-ctx-by-caller/parent/parent.c: -------------------------------------------------------------------------------- 1 | #include "../../mxvm/context.h" 2 | #include "../../mxvm/test_utils.h" 3 | 4 | byte childSC[] = "\0\0\0\0\0\0\0\0\x0F\x0F" "childSC..............."; 5 | 6 | void call_child() { 7 | int numArgs = getNumArguments(); 8 | if (numArgs != 0) { 9 | byte message[] = "wrong number of arguments"; 10 | signalError(message, 25); 11 | } 12 | 13 | 14 | byte caller[32] = {0}; 15 | getCaller(caller); 16 | 17 | byte value[32] = {0}; 18 | byte function[] = "give"; 19 | i32 argLengths[1] = {1}; 20 | 21 | byte value_to_give = 42; 22 | executeOnDestContextByCaller( 23 | 1000, 24 | childSC, 25 | value, 26 | function, 27 | 4, 28 | 1, 29 | (byte*)argLengths, 30 | &value_to_give 31 | ); 32 | 33 | byte msg[] = "child called"; 34 | finish(msg, 12); 35 | } 36 | -------------------------------------------------------------------------------- /test/contracts/upgrader-fromanother-contract/upgrader-fromanother-contract.c: -------------------------------------------------------------------------------- 1 | #include "../mxvm/context.h" 2 | #include "../mxvm/test_utils.h" 3 | 4 | byte initialContractAddress[32] = {}; 5 | byte sourceContractAddress[32] = {}; 6 | byte newAddress[32] = {}; 7 | 8 | byte deploymentValue[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,42}; 9 | 10 | byte arguments[0] = {}; 11 | int argumentsLengths[0] = {}; 12 | 13 | byte contractMetadata[2] = {3, 0}; 14 | 15 | void upgradeCodeFromAnotherContract() { 16 | getArgument(0, initialContractAddress); 17 | getArgument(1, sourceContractAddress); 18 | 19 | upgradeFromSourceContract( 20 | initialContractAddress, 21 | 500000, 22 | deploymentValue, 23 | sourceContractAddress, 24 | contractMetadata, 25 | 0, 26 | (byte*)argumentsLengths, 27 | arguments); 28 | } 29 | -------------------------------------------------------------------------------- /fuzz/weightedroulette/weightedRoulette.go: -------------------------------------------------------------------------------- 1 | package weightedroulette 2 | 3 | import ( 4 | "math/rand" 5 | ) 6 | 7 | // Outcome holds a possible outcome of roulette random choice execution. 8 | type Outcome struct { 9 | Weight int 10 | Event func() 11 | } 12 | 13 | // RandomChoice executes one of the outcomes randomly, according to the weights. 14 | func RandomChoice(r *rand.Rand, outcomes ...Outcome) { 15 | weightSum := outputWeightSum(outcomes...) 16 | randomNum := r.Intn(weightSum) 17 | cumulative := 0 18 | for _, outcome := range outcomes { 19 | cumulative += outcome.Weight 20 | if randomNum < cumulative { 21 | outcome.Event() 22 | return 23 | } 24 | } 25 | } 26 | 27 | func outputWeightSum(outcomes ...Outcome) int { 28 | sum := 0 29 | for _, outcome := range outcomes { 30 | sum += outcome.Weight 31 | } 32 | return sum 33 | } 34 | -------------------------------------------------------------------------------- /test/contracts/exec-same-ctx-simple-parent/exec-same-ctx-simple-parent.c: -------------------------------------------------------------------------------- 1 | #include "../mxvm/context.h" 2 | 3 | byte executeValue[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,99}; 4 | byte childSC[] = "\0\0\0\0\0\0\0\0\x0F\x0F" "childSC..............."; 5 | 6 | void parentFunctionChildCall() { 7 | byte* childAddress = childSC; 8 | byte functionName[] = "childFunction"; 9 | 10 | u64 result = executeOnSameContext( 11 | 200000, 12 | childAddress, 13 | executeValue, 14 | functionName, 15 | 13, 16 | 0, 17 | 0, 18 | 0 19 | ); 20 | int64finish(result); 21 | 22 | result = executeOnSameContext( 23 | 200000, 24 | childAddress, 25 | executeValue, 26 | functionName, 27 | 13, 28 | 0, 29 | 0, 30 | 0 31 | ); 32 | int64finish(result); 33 | 34 | byte msg[] = "parent"; 35 | finish(msg, 6); 36 | } 37 | -------------------------------------------------------------------------------- /test/contracts/counter/counter.c: -------------------------------------------------------------------------------- 1 | #include "../mxvm/context.h" 2 | #include "../mxvm/util.h" 3 | 4 | STORAGE_KEY(COUNTER); 5 | 6 | void init() { 7 | int64storageStore(COUNTER_KEY, COUNTER_KEY_LEN, 1); 8 | } 9 | 10 | void upgrade() { 11 | int64storageStore(COUNTER_KEY, COUNTER_KEY_LEN, 1); 12 | } 13 | 14 | void increment() { 15 | i64 counter = int64storageLoad(COUNTER_KEY, COUNTER_KEY_LEN); 16 | counter++; 17 | int64storageStore(COUNTER_KEY, COUNTER_KEY_LEN, counter); 18 | int64finish(counter); 19 | } 20 | 21 | void decrement() { 22 | i64 counter = int64storageLoad(COUNTER_KEY, COUNTER_KEY_LEN); 23 | counter--; 24 | int64storageStore(COUNTER_KEY, COUNTER_KEY_LEN, counter); 25 | int64finish(counter); 26 | } 27 | 28 | void get() { 29 | i64 counter = int64storageLoad(COUNTER_KEY, COUNTER_KEY_LEN); 30 | int64finish(counter); 31 | } -------------------------------------------------------------------------------- /executor/executorFactory.go: -------------------------------------------------------------------------------- 1 | package executor 2 | 3 | import "github.com/multiversx/mx-chain-core-go/core/check" 4 | 5 | // ExecutorFactoryArgs define the Executor configurations that come from the VM, especially the hooks and the gas costs. 6 | type ExecutorFactoryArgs struct { 7 | VMHooks VMHooks 8 | OpcodeCosts *WASMOpcodeCost 9 | RkyvSerializationEnabled bool 10 | WasmerSIGSEGVPassthrough bool 11 | } 12 | 13 | // ExecutorAbstractFactory defines an object to be passed to the VM to configure the instantiation of the Executor. 14 | // The VM needs to create the Executor, because the VM hooks, gas costs and other configurations come from it. 15 | type ExecutorAbstractFactory interface { 16 | check.NilInterfaceChecker 17 | 18 | // CreateExecutor produces a new Executor instance. 19 | CreateExecutor(args ExecutorFactoryArgs) (Executor, error) 20 | } 21 | -------------------------------------------------------------------------------- /test/contracts/async-call-parent-managed/async-call-parent-managed.c: -------------------------------------------------------------------------------- 1 | #include "../mxvm/context.h" 2 | #include "../mxvm/bigInt.h" 3 | 4 | void managedAsyncCall(int addressBuffer, int valueBuffer, int functionBuffer, int argumentsBuffer); 5 | 6 | void foo() 7 | { 8 | int contractB = mBufferNew(); 9 | bigInt value = bigIntNew(0); 10 | int function = mBufferNewFromBytes("bar", 3); 11 | int noArguments = mBufferNew(); 12 | 13 | mBufferGetArgument(0, contractB); 14 | managedAsyncCall(contractB, value, function, noArguments); 15 | } 16 | 17 | void callBack() 18 | { 19 | int numArguments = getNumArguments(); 20 | 21 | int64finish(0xCA11BAC3); 22 | 23 | for (int i = 0; i < numArguments; i++) 24 | { 25 | int dump = mBufferNew(); 26 | mBufferGetArgument(i, dump); 27 | mBufferFinish(dump); 28 | } 29 | 30 | int64finish(0xCA11BAC3); 31 | } 32 | -------------------------------------------------------------------------------- /test/delegation/v0_5_latest/scenarios/version.scen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "check version", 3 | "gasSchedule": "v3", 4 | "steps": [ 5 | { 6 | "step": "setState", 7 | "accounts": { 8 | "sc:delegation": { 9 | "nonce": "0", 10 | "balance": "0", 11 | "code": "file:../output/delegation_latest_full.wasm" 12 | } 13 | } 14 | }, 15 | { 16 | "step": "scQuery", 17 | "id": "version", 18 | "tx": { 19 | "to": "sc:delegation", 20 | "function": "version", 21 | "arguments": [] 22 | }, 23 | "expect": { 24 | "out": [ 25 | "str:0.5.8" 26 | ] 27 | } 28 | } 29 | ] 30 | } 31 | -------------------------------------------------------------------------------- /test/contracts/timelocks/timelocks.c: -------------------------------------------------------------------------------- 1 | #include "../mxvm/context.h" 2 | 3 | 4 | byte counterKey[] = "counter"; 5 | const long long oneDay = 3600*24; 6 | 7 | void init() { 8 | int64storageStore(counterKey, sizeof(counterKey), 0); 9 | } 10 | 11 | void incrementCounter() { 12 | int counterKeySize = sizeof(counterKey); 13 | i64 counter = int64storageLoad(counterKey, counterKeySize); 14 | if (isStorageLocked(counterKey, counterKeySize) == 0) { 15 | counter++; 16 | int64storageStore(counterKey, counterKeySize, counter); 17 | } 18 | int64finish(counter); 19 | } 20 | 21 | void lockCounter() { 22 | long long lockTimestamp = getBlockTimestamp(); 23 | lockTimestamp += oneDay; 24 | setStorageLock(counterKey, sizeof(counterKey), lockTimestamp); 25 | } 26 | 27 | void releaseCounter() { 28 | clearStorageLock(counterKey, sizeof(counterKey)); 29 | } 30 | -------------------------------------------------------------------------------- /test/contracts/wasmbacking/mem-content/output/mem-content.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type $void (func)) 3 | (type $finish_type(func (param i32 i32))) 4 | (import "env" "finish" (func $finish (type $finish_type))) 5 | (func $main (type $void) 6 | (local $offset i32) 7 | i32.const 1024 8 | local.set $offset 9 | 10 | local.get $offset 11 | local.get $offset 12 | i32.load8_u 13 | i32.const 111 ;; the literal 'o' 14 | i32.add 15 | i32.store8 16 | 17 | local.get $offset 18 | i32.const 1 19 | i32.add 20 | local.get $offset 21 | i32.const 1 22 | i32.add 23 | i32.load8_u 24 | i32.const 107 ;; the literal 'k' 25 | i32.add 26 | i32.store8 27 | 28 | local.get $offset 29 | i32.const 2 30 | call $finish 31 | ) 32 | (memory $mem 1) 33 | (export "memory" (memory $mem)) 34 | (export "main" (func $main)) 35 | ) 36 | -------------------------------------------------------------------------------- /test/delegation/v0_5_latest/scenarios/version.scen copy.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "check version", 3 | "gasSchedule": "v3", 4 | "steps": [ 5 | { 6 | "step": "setState", 7 | "accounts": { 8 | "sc:delegation": { 9 | "nonce": "0", 10 | "balance": "0", 11 | "code": "file:../output/delegation_latest_update.wasm" 12 | } 13 | } 14 | }, 15 | { 16 | "step": "scQuery", 17 | "id": "version", 18 | "tx": { 19 | "to": "sc:delegation", 20 | "function": "version", 21 | "arguments": [] 22 | }, 23 | "expect": { 24 | "out": [ 25 | "str:0.5.8" 26 | ] 27 | } 28 | } 29 | ] 30 | } 31 | -------------------------------------------------------------------------------- /executor/executorInstance.go: -------------------------------------------------------------------------------- 1 | package executor 2 | 3 | // Instance defines the functionality of a Wasmer instance 4 | type Instance interface { 5 | GetPointsUsed() uint64 6 | SetPointsUsed(points uint64) 7 | SetGasLimit(gasLimit uint64) 8 | SetBreakpointValue(value uint64) 9 | GetBreakpointValue() uint64 10 | Cache() ([]byte, error) 11 | Clean() bool 12 | CallFunction(functionName string) error 13 | HasFunction(functionName string) bool 14 | GetFunctionNames() []string 15 | ValidateFunctionArities() error 16 | HasMemory() bool 17 | MemLoad(memPtr MemPtr, length MemLength) ([]byte, error) 18 | MemStore(memPtr MemPtr, data []byte) error 19 | MemLength() uint32 20 | MemGrow(pages uint32) error 21 | MemDump() []byte 22 | IsFunctionImported(name string) bool 23 | IsInterfaceNil() bool 24 | Reset() bool 25 | SetVMHooksPtr(vmHooksPtr uintptr) 26 | GetVMHooksPtr() uintptr 27 | ID() string 28 | IsAlreadyCleaned() bool 29 | } 30 | -------------------------------------------------------------------------------- /test/contracts/wasmbacking/mem-data-initializer/output/mem-data-initializer.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type $void (func)) 3 | (type $finish_type(func (param i32 i32))) 4 | (import "env" "finish" (func $finish (type $finish_type))) 5 | (func $main (type $void) 6 | (local $offset i32) 7 | i32.const 1024 8 | local.set $offset 9 | 10 | local.get $offset 11 | local.get $offset 12 | i32.load8_u 13 | i32.const 1 ;; makes 'n' into 'o' 14 | i32.add 15 | i32.store8 16 | 17 | local.get $offset 18 | i32.const 1 19 | i32.add 20 | local.get $offset 21 | i32.const 1 22 | i32.add 23 | i32.load8_u 24 | i32.const 1 ;; makes 'j' into 'k' 25 | i32.add 26 | i32.store8 27 | 28 | local.get $offset 29 | i32.const 2 30 | call $finish 31 | ) 32 | (memory $mem 1) 33 | (export "memory" (memory $mem)) 34 | (export "main" (func $main)) 35 | (data (i32.const 1024) "nj") 36 | ) 37 | -------------------------------------------------------------------------------- /math/randomnessGenerator.go: -------------------------------------------------------------------------------- 1 | package math 2 | 3 | import ( 4 | "crypto/sha256" 5 | "encoding/binary" 6 | "math/rand" 7 | ) 8 | 9 | type seedRandReader struct { 10 | rand *rand.Rand 11 | } 12 | 13 | // NewSeedRandReader creates and returns a new SeedRandReader 14 | func NewSeedRandReader(seed []byte) *seedRandReader { 15 | seedHash := sha256.Sum256(seed) 16 | seedNumber := binary.BigEndian.Uint64(seedHash[:]) 17 | 18 | source := rand.NewSource(int64(seedNumber)) 19 | randomizer := rand.New(source) 20 | 21 | return &seedRandReader{ 22 | rand: randomizer, 23 | } 24 | } 25 | 26 | // Read generates len(p) random bytes and writes them into p. It always returns len(p) and a nil error. 27 | func (srr *seedRandReader) Read(p []byte) (n int, err error) { 28 | return srr.rand.Read(p) 29 | } 30 | 31 | // IsInterfaceNil returns true if there is no value under the interface 32 | func (srr *seedRandReader) IsInterfaceNil() bool { 33 | return srr == nil 34 | } 35 | -------------------------------------------------------------------------------- /test/contracts/deployer/deployer.c: -------------------------------------------------------------------------------- 1 | #include "../mxvm/context.h" 2 | #include "../mxvm/test_utils.h" 3 | 4 | byte contractCode[5000] = {}; 5 | byte contractMetadata[2] = {1, 0}; 6 | byte contractID = 0; 7 | byte newAddress[32] = {}; 8 | 9 | byte deploymentValue[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,42}; 10 | 11 | byte arguments[1] = {0}; 12 | int argumentsLengths[1] = {1}; 13 | 14 | void deployChildContract() { 15 | getArgument(0, &contractID); 16 | int loadedLength = storageLoad(&contractID, 1, contractCode); 17 | int64finish(loadedLength); 18 | 19 | byte arg = 0; 20 | getArgument(1, &arg); 21 | 22 | arguments[0] = arg; 23 | 24 | int initArgLengths[] = {1}; 25 | int result = createContract( 26 | 2000, 27 | deploymentValue, 28 | contractCode, 29 | contractMetadata, 30 | loadedLength, 31 | newAddress, 32 | 1, 33 | (byte*)argumentsLengths, 34 | arguments); 35 | 36 | finishResult(result); 37 | } 38 | -------------------------------------------------------------------------------- /test/multisig/scenarios/changeBoard.scen.json: -------------------------------------------------------------------------------- 1 | { 2 | "steps": [ 3 | { 4 | "step": "externalSteps", 5 | "path": "steps/init_accounts.steps.json" 6 | }, 7 | { 8 | "step": "externalSteps", 9 | "path": "steps/deploy.steps.json" 10 | }, 11 | { 12 | "step": "externalSteps", 13 | "path": "steps/add_prop.steps.json" 14 | }, 15 | { 16 | "step": "externalSteps", 17 | "path": "steps/add_bm.steps.json" 18 | }, 19 | { 20 | "step": "externalSteps", 21 | "path": "steps/rem_alice.steps.json" 22 | }, 23 | { 24 | "step": "externalSteps", 25 | "path": "steps/rem_unknown.steps.json" 26 | }, 27 | { 28 | "step": "externalSteps", 29 | "path": "steps/sign_unsign_bad_action.steps.json" 30 | } 31 | ] 32 | } 33 | -------------------------------------------------------------------------------- /crypto/factory/cryptovm.go: -------------------------------------------------------------------------------- 1 | package factory 2 | 3 | import ( 4 | "github.com/multiversx/mx-chain-vm-go/crypto" 5 | "github.com/multiversx/mx-chain-vm-go/crypto/hashing" 6 | "github.com/multiversx/mx-chain-vm-go/crypto/signing/bls" 7 | "github.com/multiversx/mx-chain-vm-go/crypto/signing/ed25519" 8 | "github.com/multiversx/mx-chain-vm-go/crypto/signing/secp256" 9 | ) 10 | 11 | // NewVMCrypto returns a composite struct containing VMCrypto functionality implementations 12 | func NewVMCrypto() (crypto.VMCrypto, error) { 13 | blsVerifier, err := bls.NewBLS() 14 | if err != nil { 15 | return nil, err 16 | } 17 | 18 | secp, err := secp256.NewSecp256() 19 | if err != nil { 20 | return nil, err 21 | } 22 | 23 | return struct { 24 | crypto.Hasher 25 | crypto.Ed25519 26 | crypto.BLS 27 | crypto.Secp256 28 | }{ 29 | Hasher: hashing.NewHasher(), 30 | Ed25519: ed25519.NewEd25519Signer(), 31 | BLS: blsVerifier, 32 | Secp256: secp, 33 | }, nil 34 | } 35 | -------------------------------------------------------------------------------- /scenario/gasSchedules/gasScheduleLoad.go: -------------------------------------------------------------------------------- 1 | package gasschedules 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/multiversx/mx-chain-vm-go/config" 7 | "github.com/pelletier/go-toml" 8 | ) 9 | 10 | // LoadGasScheduleConfig parses and prepares a gas schedule read from file. 11 | func LoadGasScheduleConfig(fileContents string) (config.GasScheduleMap, error) { 12 | loadedTree, err := toml.Load(fileContents) 13 | if err != nil { 14 | fmt.Printf("cannot interpret file contents as toml: %s", err.Error()) 15 | return nil, err 16 | } 17 | 18 | gasScheduleConfig := loadedTree.ToMap() 19 | 20 | flattenedGasSchedule := make(config.GasScheduleMap) 21 | for libType, costs := range gasScheduleConfig { 22 | flattenedGasSchedule[libType] = make(map[string]uint64) 23 | costsMap := costs.(map[string]interface{}) 24 | for operationName, cost := range costsMap { 25 | flattenedGasSchedule[libType][operationName] = uint64(cost.(int64)) 26 | } 27 | } 28 | 29 | return flattenedGasSchedule, nil 30 | } 31 | -------------------------------------------------------------------------------- /test/contracts/mxvm/util.h: -------------------------------------------------------------------------------- 1 | #include "context.h" 2 | #include "bigInt.h" 3 | 4 | #define STORAGE_KEY(key) \ 5 | const int key##_KEY_LEN = sizeof #key - 1;\ 6 | byte key##_KEY[key##_KEY_LEN + 1] = #key; 7 | 8 | #define ERROR_MSG(var, str) \ 9 | const int var##_LEN = sizeof str - 1;\ 10 | byte var[var##_LEN + 1] = str; 11 | 12 | #define SIGNAL_ERROR(var) signalError(var, var##_LEN); 13 | 14 | ERROR_MSG(ERR_NUM_ARGS, "wrong number of arguments") 15 | #define CHECK_NUM_ARGS(expected) {\ 16 | if (getNumArguments() != expected) {\ 17 | SIGNAL_ERROR(ERR_NUM_ARGS);\ 18 | return;\ 19 | }\ 20 | } 21 | 22 | ERROR_MSG(ERR_NOT_PAYABLE, "attempted to transfer funds via a non-payable function") 23 | #define CHECK_NOT_PAYABLE() {\ 24 | int callValue = bigIntNew(0);\ 25 | bigIntGetCallValue(callValue);\ 26 | int zero = bigIntNew(0);\ 27 | if (bigIntCmp(callValue, zero) > 0) {\ 28 | SIGNAL_ERROR(ERR_NOT_PAYABLE);\ 29 | return;\ 30 | }\ 31 | } 32 | -------------------------------------------------------------------------------- /test/factorial/scenarios/factorial.scen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "factorial", 3 | "steps": [ 4 | { 5 | "step": "setState", 6 | "accounts": { 7 | "address:owner": { 8 | "nonce": "1", 9 | "balance": "0" 10 | }, 11 | "sc:factorial": { 12 | "code": "mxsc:../output/factorial.mxsc.json" 13 | } 14 | } 15 | }, 16 | { 17 | "step": "scQuery", 18 | "id": "factorial(3)", 19 | "tx": { 20 | "to": "sc:factorial", 21 | "function": "factorial", 22 | "arguments": [ 23 | "3" 24 | ] 25 | }, 26 | "expect": { 27 | "out": [ 28 | "6" 29 | ], 30 | "status": "", 31 | "logs": [] 32 | } 33 | } 34 | ] 35 | } 36 | -------------------------------------------------------------------------------- /fuzz/util/randomEventProvider.go: -------------------------------------------------------------------------------- 1 | package fuzzutil 2 | 3 | import ( 4 | "math/rand" 5 | ) 6 | 7 | // RandomEventProvider fuzzing utility. 8 | type RandomEventProvider struct { 9 | randProvider *rand.Rand 10 | currentRand float32 11 | cumulatedProb float32 12 | } 13 | 14 | // NewRandomEventProvider is a RandomEventProvider constructor. 15 | func NewRandomEventProvider(r *rand.Rand) *RandomEventProvider { 16 | re := &RandomEventProvider{ 17 | randProvider: r, 18 | } 19 | re.Reset() 20 | return re 21 | } 22 | 23 | // Reset clears the RandomEventProvider. 24 | func (re *RandomEventProvider) Reset() { 25 | re.currentRand = re.randProvider.Float32() 26 | re.cumulatedProb = 0 27 | } 28 | 29 | // WithProbability randomly provides true, according to cumulated probabilities. 30 | func (re *RandomEventProvider) WithProbability(p float32) bool { 31 | re.cumulatedProb += p 32 | if re.cumulatedProb > 1 { 33 | panic("probabilities exceed 1") 34 | } 35 | return re.currentRand < re.cumulatedProb 36 | } 37 | -------------------------------------------------------------------------------- /test/delegation/v0_5_latest/scenarios/staking_2.scen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "unstake-3", 3 | "gasSchedule": "v3", 4 | "steps": [ 5 | { 6 | "step": "externalSteps", 7 | "path": "steps/init_accounts.steps.json" 8 | }, 9 | { 10 | "step": "externalSteps", 11 | "path": "steps/deploy.steps.json" 12 | }, 13 | { 14 | "step": "externalSteps", 15 | "path": "steps/add_nodes.steps.json" 16 | }, 17 | { 18 | "step": "externalSteps", 19 | "path": "steps/stake_1.steps.json" 20 | }, 21 | { 22 | "step": "externalSteps", 23 | "path": "steps/increase_cap.steps.json" 24 | }, 25 | { 26 | "step": "externalSteps", 27 | "path": "steps/unstake.steps.json" 28 | }, 29 | { 30 | "step": "externalSteps", 31 | "path": "steps/stake_2.steps.json" 32 | } 33 | ] 34 | } 35 | -------------------------------------------------------------------------------- /test/dns/scenarios/main.scen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "big dns test", 3 | "gasSchedule": "dummy", 4 | "steps": [ 5 | { 6 | "step": "externalSteps", 7 | "path": "01_dns_init.steps.json" 8 | }, 9 | { 10 | "step": "externalSteps", 11 | "path": "02_dns_init_check.steps.json" 12 | }, 13 | { 14 | "step": "externalSteps", 15 | "path": "03_register_name_ok.steps.json" 16 | }, 17 | { 18 | "step": "externalSteps", 19 | "path": "04_register_name_again.steps.json" 20 | }, 21 | { 22 | "step": "externalSteps", 23 | "path": "05_claim.steps.json" 24 | }, 25 | { 26 | "step": "externalSteps", 27 | "path": "06_register_other_name_same_shard.steps.json" 28 | }, 29 | { 30 | "step": "externalSteps", 31 | "path": "07_bogus_name.steps.json" 32 | } 33 | ] 34 | } 35 | -------------------------------------------------------------------------------- /fuzz/dex/v0.1/fuzzDexExecutorTokens.go: -------------------------------------------------------------------------------- 1 | package dex 2 | 3 | import ( 4 | "math/big" 5 | 6 | "github.com/multiversx/mx-chain-core-go/data/esdt" 7 | ) 8 | 9 | func (pfe *fuzzDexExecutor) interpretExpr(expression string) []byte { 10 | bytes, err := pfe.parser.ExprInterpreter.InterpretString(expression) 11 | if err != nil { 12 | panic(err) 13 | } 14 | return bytes 15 | } 16 | 17 | func (pfe *fuzzDexExecutor) getTokensWithNonce(address string, toktik string, nonce int) (*big.Int, error) { 18 | return pfe.world.BuiltinFuncs.GetTokenBalance(pfe.interpretExpr(address), []byte(toktik), uint64(nonce)) 19 | } 20 | 21 | func (pfe *fuzzDexExecutor) getTokens(address string, toktik string) (*big.Int, error) { 22 | return pfe.world.BuiltinFuncs.GetTokenBalance(pfe.interpretExpr(address), []byte(toktik), 0) 23 | } 24 | 25 | func (pfe *fuzzDexExecutor) getTokenData(address string, toktik string, nonce int) (*esdt.ESDigitalToken, error) { 26 | return pfe.world.BuiltinFuncs.GetTokenData(pfe.interpretExpr(address), []byte(toktik), uint64(nonce)) 27 | } 28 | -------------------------------------------------------------------------------- /test/multisig/scenarios/deploy_duplicate_bm.scen.json: -------------------------------------------------------------------------------- 1 | { 2 | "comment": "add then check", 3 | "steps": [ 4 | { 5 | "step": "externalSteps", 6 | "path": "steps/init_accounts.steps.json" 7 | }, 8 | { 9 | "step": "scDeploy", 10 | "id": "multisig-deploy", 11 | "tx": { 12 | "from": "address:owner", 13 | "contractCode": "mxsc:../output/multisig.mxsc.json", 14 | "arguments": [ 15 | "2", 16 | "address:alice", 17 | "address:alice" 18 | ], 19 | "gasLimit": "50,000,000", 20 | "gasPrice": "0" 21 | }, 22 | "expect": { 23 | "out": [], 24 | "status": "4", 25 | "message": "str:duplicate board member", 26 | "logs": "*", 27 | "gas": "*", 28 | "refund": "*" 29 | } 30 | } 31 | ] 32 | } 33 | -------------------------------------------------------------------------------- /test/ping-pong-egld/scenarios/ping-pong-call-get-user-addresses.scen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "call getUserAddresses in order to check who registered", 3 | "gasSchedule": "v3", 4 | "steps": [ 5 | { 6 | "step": "externalSteps", 7 | "path": "ping-pong-call-ping-second-user.scen.json" 8 | }, 9 | { 10 | "step": "scCall", 11 | "tx": { 12 | "from": "address:participant1", 13 | "to": "sc:ping-pong", 14 | "function": "getUserAddresses", 15 | "arguments": [], 16 | "gasLimit": "10,000,000", 17 | "gasPrice": "0" 18 | }, 19 | "expect": { 20 | "out": [ 21 | "address:participant1", 22 | "address:participant2" 23 | ], 24 | "status": "0", 25 | "message": "", 26 | "gas": "*", 27 | "refund": "*" 28 | } 29 | } 30 | ] 31 | } 32 | -------------------------------------------------------------------------------- /test/features/alloc-features/scenarios/managed_buffer_overwrite.scen.json: -------------------------------------------------------------------------------- 1 | { 2 | "steps": [ 3 | { 4 | "step": "setState", 5 | "accounts": { 6 | "sc:alloc-features": { 7 | "nonce": "0", 8 | "balance": "0", 9 | "code": "mxsc:../output/alloc-features.mxsc.json" 10 | }, 11 | "address:an_account": { 12 | "nonce": "0", 13 | "balance": "0" 14 | } 15 | } 16 | }, 17 | { 18 | "step": "scQuery", 19 | "id": "1", 20 | "tx": { 21 | "to": "sc:alloc-features", 22 | "function": "mbuffer_overwrite", 23 | "arguments": [ 24 | "str:old", 25 | "str:new" 26 | ] 27 | }, 28 | "expect": { 29 | "out": [ 30 | "str:new" 31 | ] 32 | } 33 | } 34 | ] 35 | } 36 | -------------------------------------------------------------------------------- /vmhost/vmhooks/generate/eiGenModel.go: -------------------------------------------------------------------------------- 1 | package vmhooksgenerate 2 | 3 | type EIType int32 4 | 5 | const ( 6 | EITypeInt32 EIType = iota 7 | EITypeInt64 8 | EITypeMemPtr 9 | EITypeMemLength 10 | EITypeInvalid 11 | ) 12 | 13 | // EIFunctionArg models an executor callback method arg. 14 | type EIFunctionArg struct { 15 | Name string 16 | Type EIType 17 | } 18 | 19 | // EIFunctionResult models the executor callback method result. 20 | type EIFunctionResult struct { 21 | Type EIType 22 | } 23 | 24 | // EIFunction holds data about one function in the VM EI. 25 | type EIFunction struct { 26 | Name string 27 | Arguments []*EIFunctionArg 28 | Result *EIFunctionResult 29 | } 30 | 31 | // EIGroup groups EI functions into bundles. 32 | // They can end up in separate interfaces or files, if desired. 33 | type EIGroup struct { 34 | SourcePath string 35 | Name string 36 | Functions []*EIFunction 37 | } 38 | 39 | // EIMetadata holds all data about EI functions in the VM. 40 | type EIMetadata struct { 41 | Groups []*EIGroup 42 | AllFunctions []*EIFunction 43 | } 44 | -------------------------------------------------------------------------------- /test/delegation/v0_3/test/integration/main/14x_unstake_too_soon.steps.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "force unstake", 3 | "steps": [ 4 | { 5 | "step": "setState", 6 | "comment": "almost one week passes (1 second too early)", 7 | "currentBlockInfo": { 8 | "blockNonce": "521050" 9 | } 10 | }, 11 | { 12 | "step": "scCall", 13 | "id": "force-unstake-too-soon", 14 | "tx": { 15 | "from": "''delegator_1___________________s1", 16 | "to": "sc:delegation", 17 | "function": "unStake", 18 | "arguments": [], 19 | "gasLimit": "1,000,000", 20 | "gasPrice": "0" 21 | }, 22 | "expect": { 23 | "out": [], 24 | "status": "4", 25 | "message": "str:no stake eligible for unStake", 26 | "logs": "*", 27 | "gas": "*", 28 | "refund": "*" 29 | } 30 | } 31 | ] 32 | } 33 | -------------------------------------------------------------------------------- /vmhost/vmhooks/generate/eiGenWriteOpcodeCost.go: -------------------------------------------------------------------------------- 1 | package vmhooksgenerate 2 | 3 | import ( 4 | "bufio" 5 | "fmt" 6 | "os" 7 | ) 8 | 9 | // WriteWasmer2OpcodeCost generates code for wasmer2/opcodeCost.go 10 | func WriteWasmer2OpcodeCost(out *eiGenWriter) { 11 | out.WriteString(`// Code generated by vmhooks generator. DO NOT EDIT. 12 | 13 | // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 14 | // !!!!!!!!!!!!!!!!!!!!!! AUTO-GENERATED FILE !!!!!!!!!!!!!!!!!!!!!! 15 | // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 16 | 17 | `) 18 | out.WriteString("package wasmer2\n\n") 19 | out.WriteString("type OpcodeCost struct {\n") 20 | 21 | readFile, err := os.Open("generate/cmd/input/wasmer2_opcodes_short.txt") 22 | if err != nil { 23 | panic(err) 24 | } 25 | defer readFile.Close() 26 | 27 | fileScanner := bufio.NewScanner(readFile) 28 | fileScanner.Split(bufio.ScanLines) 29 | 30 | for fileScanner.Scan() { 31 | opcode := fileScanner.Text() 32 | out.WriteString(fmt.Sprintf("\t%-30suint32\n", opcode)) 33 | } 34 | out.WriteString("}\n") 35 | } 36 | -------------------------------------------------------------------------------- /vmhost/vmhooks/generate/eiGenWriteWASMOpcodeCost.go: -------------------------------------------------------------------------------- 1 | package vmhooksgenerate 2 | 3 | import ( 4 | "bufio" 5 | "fmt" 6 | "os" 7 | ) 8 | 9 | // WriteExecutorOpcodeCost generates code for executor/gasCostWASM.go 10 | func WriteExecutorOpcodeCost(out *eiGenWriter) { 11 | out.WriteString(`// Code generated by vmhooks generator. DO NOT EDIT. 12 | 13 | // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 14 | // !!!!!!!!!!!!!!!!!!!!!! AUTO-GENERATED FILE !!!!!!!!!!!!!!!!!!!!!! 15 | // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 16 | 17 | `) 18 | out.WriteString("package executor\n\n") 19 | out.WriteString("type WASMOpcodeCost struct {\n") 20 | 21 | readFile, err := os.Open("generate/cmd/input/wasm_opcodes.txt") 22 | if err != nil { 23 | panic(err) 24 | } 25 | defer readFile.Close() 26 | 27 | fileScanner := bufio.NewScanner(readFile) 28 | fileScanner.Split(bufio.ScanLines) 29 | 30 | for fileScanner.Scan() { 31 | opcode := fileScanner.Text() 32 | out.WriteString(fmt.Sprintf("\t%-30suint32\n", opcode)) 33 | } 34 | out.WriteString("}\n") 35 | } 36 | -------------------------------------------------------------------------------- /test/contracts/wasmbacking/multiple-mutable/output/multiple-mutable.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type (;0;) (func (param i64))) 3 | (type (;1;) (func)) 4 | (import "env" "int64finish" (func (;0;) (type 0))) 5 | (func (;1;) (type 1) 6 | global.get 1 7 | i64.const 1 8 | i64.add 9 | global.set 1 10 | 11 | global.get 2 12 | i64.const 1 13 | i64.add 14 | global.set 2 15 | 16 | global.get 3 17 | i64.const 1 18 | i64.add 19 | global.set 3 20 | 21 | global.get 4 22 | i64.const 1 23 | i64.add 24 | global.set 4 25 | 26 | global.get 0 27 | call 0 28 | global.get 1 29 | call 0 30 | global.get 2 31 | call 0 32 | global.get 3 33 | call 0 34 | global.get 4 35 | call 0 36 | ) 37 | (memory (;0;) 2) 38 | (global (;0;) (mut i64) (i64.const 0)) 39 | (global (;1;) (mut i64) (i64.const 1)) 40 | (global (;2;) (mut i64) (i64.const 2)) 41 | (global (;3;) (mut i64) (i64.const 4)) 42 | (global (;4;) (mut i64) (i64.const 6)) 43 | (export "memory" (memory 0)) 44 | (export "increment_globals" (func 1)) 45 | ) 46 | -------------------------------------------------------------------------------- /vmhost/helpers_test.go: -------------------------------------------------------------------------------- 1 | package vmhost 2 | 3 | import ( 4 | "bytes" 5 | "testing" 6 | 7 | "github.com/stretchr/testify/require" 8 | ) 9 | 10 | func TestGuardedGetBytesSlice(t *testing.T) { 11 | t.Parallel() 12 | 13 | dataSlice := []byte("data1_data2_data3_data4") 14 | 15 | slice, err := GuardedGetBytesSlice(dataSlice, 100, 100) 16 | require.Nil(t, slice) 17 | require.NotNil(t, err) 18 | 19 | slice, err = GuardedGetBytesSlice(dataSlice, 5, -1) 20 | require.Nil(t, slice) 21 | require.NotNil(t, err) 22 | 23 | expectedResult := []byte("data1") 24 | slice, err = GuardedGetBytesSlice(dataSlice, 0, 5) 25 | require.Nil(t, err) 26 | require.True(t, bytes.Equal(expectedResult, slice)) 27 | } 28 | 29 | func TestInverseBytes(t *testing.T) { 30 | t.Parallel() 31 | 32 | data := []byte("qwerty") 33 | expectedData := []byte("ytrewq") 34 | 35 | result := InverseBytes(data) 36 | require.Equal(t, expectedData, result) 37 | 38 | result = InverseBytes(nil) 39 | require.Equal(t, []byte{}, result) 40 | 41 | result = InverseBytes([]byte("a")) 42 | require.Equal(t, []byte("a"), result) 43 | } 44 | -------------------------------------------------------------------------------- /vmhost/vmhooks/generate/eiGenWriteRustCapiVMHooksPointers.go: -------------------------------------------------------------------------------- 1 | package vmhooksgenerate 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func WriteRustCapiVMHooksPointers(out *eiGenWriter, eiMetadata *EIMetadata) { 8 | autoGeneratedHeader(out) 9 | out.WriteString(` 10 | use std::ffi::c_void; 11 | 12 | #[repr(C)] 13 | #[derive(Clone)] 14 | #[allow(non_camel_case_types)] 15 | #[rustfmt::skip] 16 | pub struct vm_exec_vm_hook_c_func_pointers {`) 17 | 18 | for _, funcMetadata := range eiMetadata.AllFunctions { 19 | out.WriteString(fmt.Sprintf( 20 | "\n pub %s: extern \"C\" fn%s", 21 | cgoFuncPointerFieldName(funcMetadata), 22 | writeRustFnDeclarationArguments( 23 | "context: *mut c_void", 24 | funcMetadata, 25 | rustCapiType, 26 | rustVMHooksLegacyReturnType, 27 | ), 28 | )) 29 | 30 | out.WriteString(",") 31 | } 32 | 33 | out.WriteString(` 34 | } 35 | 36 | impl std::fmt::Debug for vm_exec_vm_hook_c_func_pointers { 37 | fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { 38 | write!(f, "vm_exec_vm_hook_c_func_pointers") 39 | } 40 | } 41 | `) 42 | } 43 | -------------------------------------------------------------------------------- /vmhost/vmhooks/generate/eiGenWriteWASMOpcodeCostConfigHelpers.go: -------------------------------------------------------------------------------- 1 | package vmhooksgenerate 2 | 3 | import ( 4 | "bufio" 5 | "fmt" 6 | "os" 7 | ) 8 | 9 | // WriteWASMOpcodeCostConfigHelpers generates code for config.txt 10 | // (to be copied manually in config/config.toml) 11 | func WriteWASMOpcodeCostConfigHelpers(out *eiGenWriter) { 12 | out.WriteString(`// Code generated by vmhooks generator. DO NOT EDIT. 13 | 14 | // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 15 | // !!!!!!!!!!!!!!!!!!!!!! AUTO-GENERATED FILE !!!!!!!!!!!!!!!!!!!!!! 16 | // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 17 | 18 | // !!!!!!!!!!!!!!!!!! USE IN config/config.toml !!!!!!!!!!!!!!!!!!!! 19 | 20 | `) 21 | out.WriteString("[WASMOpcodeCost]\n") 22 | readFile, err := os.Open("generate/cmd/input/wasm_opcodes.txt") 23 | if err != nil { 24 | panic(err) 25 | } 26 | defer readFile.Close() 27 | 28 | fileScanner := bufio.NewScanner(readFile) 29 | fileScanner.Split(bufio.ScanLines) 30 | 31 | for fileScanner.Scan() { 32 | opcode := fileScanner.Text() 33 | out.WriteString(fmt.Sprintf(" %s = 1\n", opcode)) 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /executor/executorError.go: -------------------------------------------------------------------------------- 1 | package executor 2 | 3 | import ( 4 | "errors" 5 | "fmt" 6 | ) 7 | 8 | // ErrInvalidFunction signals that the function is invalid 9 | var ErrInvalidFunction = errors.New("invalid function") 10 | 11 | // ErrFunctionNonvoidSignature signals that the signature for the function is invalid 12 | var ErrFunctionNonvoidSignature = fmt.Errorf("%w (nonvoid signature)", ErrInvalidFunction) 13 | 14 | // ErrFuncNotFound signals that the the function does not exist 15 | var ErrFuncNotFound = fmt.Errorf("%w (not found)", ErrInvalidFunction) 16 | 17 | // ErrMemoryBadBounds signals that a certain variable is out of bounds 18 | var ErrMemoryBadBounds = errors.New("bad bounds") 19 | 20 | // ErrMemoryBadBoundsLower signals that a certain variable is lower than allowed 21 | var ErrMemoryBadBoundsLower = fmt.Errorf("%w (lower)", ErrMemoryBadBounds) 22 | 23 | // ErrMemoryBadBoundsUpper signals that a certain variable is higher than allowed 24 | var ErrMemoryBadBoundsUpper = fmt.Errorf("%w (upper)", ErrMemoryBadBounds) 25 | 26 | // ErrMemoryNegativeLength signals that the given length is less than 0 27 | var ErrMemoryNegativeLength = errors.New("negative length") 28 | -------------------------------------------------------------------------------- /test/features/composability/scenarios/forwarder_no_endpoint.scen.json: -------------------------------------------------------------------------------- 1 | { 2 | "gasSchedule": "v3", 3 | "steps": [ 4 | { 5 | "step": "setState", 6 | "accounts": { 7 | "address:a_user": {}, 8 | "sc:forwarder": { 9 | "code": "mxsc:../forwarder/output/forwarder.mxsc.json" 10 | } 11 | } 12 | }, 13 | { 14 | "step": "scCall", 15 | "id": "no-endpoint", 16 | "comment": "checks that no endpoints were accidentally included from the vault", 17 | "tx": { 18 | "from": "address:a_user", 19 | "to": "sc:forwarder", 20 | "function": "echo_caller", 21 | "arguments": [], 22 | "gasLimit": "50,000,000", 23 | "gasPrice": "0" 24 | }, 25 | "expect": { 26 | "out": [], 27 | "status": "1", 28 | "message": "str:invalid function (not found)", 29 | "gas": "*", 30 | "refund": "*" 31 | } 32 | } 33 | ] 34 | } 35 | -------------------------------------------------------------------------------- /wasmer2/wasmer2ExecutorFactory.go: -------------------------------------------------------------------------------- 1 | package wasmer2 2 | 3 | import ( 4 | "os/signal" 5 | 6 | "github.com/multiversx/mx-chain-vm-go/executor" 7 | ) 8 | 9 | var _ = (executor.ExecutorAbstractFactory)((*Wasmer2ExecutorFactory)(nil)) 10 | 11 | // Wasmer2ExecutorFactory builds Wasmer2 Executors. 12 | type Wasmer2ExecutorFactory struct{} 13 | 14 | // ExecutorFactory returns the Wasmer executor factory. 15 | func ExecutorFactory() *Wasmer2ExecutorFactory { 16 | return &Wasmer2ExecutorFactory{} 17 | } 18 | 19 | // CreateExecutor creates a new Executor instance. 20 | func (wef *Wasmer2ExecutorFactory) CreateExecutor(args executor.ExecutorFactoryArgs) (executor.Executor, error) { 21 | signal.Reset() 22 | 23 | executor, err := CreateExecutor() 24 | if err != nil { 25 | return nil, err 26 | } 27 | executor.initVMHooks(args.VMHooks) 28 | if args.OpcodeCosts != nil { 29 | // opcode costs are sometimes not initialized at this point in certain tests 30 | executor.SetOpcodeCosts(args.OpcodeCosts) 31 | } 32 | 33 | return executor, nil 34 | } 35 | 36 | // IsInterfaceNil returns true if there is no value under the interface 37 | func (wef *Wasmer2ExecutorFactory) IsInterfaceNil() bool { 38 | return wef == nil 39 | } 40 | -------------------------------------------------------------------------------- /test/delegation/v0_3/test/integration/main/10x_unbond_nodes_too_soon.steps.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "unBondNodes-too-soon", 3 | "steps": [ 4 | { 5 | "step": "setState", 6 | "comment": "1 block too early for unbond", 7 | "currentBlockInfo": { 8 | "blockNonce": "321060" 9 | } 10 | }, 11 | { 12 | "step": "scCall", 13 | "id": "unBondNodes-too-soon", 14 | "tx": { 15 | "from": "''node_address__________________s1", 16 | "to": "sc:delegation", 17 | "function": "unBondNodes", 18 | "arguments": [ 19 | "''bls_key_5_______________________________________________________________________________________" 20 | ], 21 | "gasLimit": "100,000,000", 22 | "gasPrice": "0" 23 | }, 24 | "expect": { 25 | "out": [], 26 | "status": "4", 27 | "message": "str:too soon to unbond node", 28 | "logs": "*", 29 | "gas": "*", 30 | "refund": "*" 31 | } 32 | } 33 | ] 34 | } 35 | -------------------------------------------------------------------------------- /vmhost/hosttest/tools/graphviz_tool.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/multiversx/mx-chain-vm-go/testcommon" 5 | test "github.com/multiversx/mx-chain-vm-go/testcommon" 6 | ) 7 | 8 | func main() { 9 | callGraph := test.CreateGraphTestOneAsyncCallNoCallback() 10 | 11 | graphviz := testcommon.ToGraphviz(callGraph, true) 12 | testcommon.CreateSvg("1 call-graph", graphviz) 13 | 14 | executionGraph := callGraph.CreateExecutionGraphFromCallGraph() 15 | graphviz = testcommon.ToGraphviz(executionGraph, true) 16 | testcommon.CreateSvg("2 execution-graph", graphviz) 17 | 18 | gasGraph := executionGraph.ComputeGasGraphFromExecutionGraph() 19 | gasGraph.PropagateSyncFailures() 20 | gasGraph.AssignExecutionRounds(nil) 21 | 22 | graphviz = testcommon.ToGraphviz(gasGraph, false) 23 | testcommon.CreateSvg("3 initial-gas-graph", graphviz) 24 | 25 | gasGraph.ComputeRemainingGasBeforeCallbacks(nil) 26 | graphviz = testcommon.ToGraphviz(gasGraph, false) 27 | testcommon.CreateSvg("4 gas-graph-gasbeforecallbacks", graphviz) 28 | 29 | gasGraph.ComputeRemainingGasAfterCallbacks() 30 | graphviz = testcommon.ToGraphviz(gasGraph, false) 31 | testcommon.CreateSvg("5 gas-graph-gasaftercallbacks-norestore", graphviz) 32 | } 33 | -------------------------------------------------------------------------------- /fuzz/delegation/v0.5/fuzzDelegationGetters.go: -------------------------------------------------------------------------------- 1 | //nolint:all 2 | package delegation 3 | 4 | import ( 5 | "fmt" 6 | "math/big" 7 | ) 8 | 9 | func (pfe *fuzzDelegationExecutor) interpretExpr(expression string) []byte { 10 | bytes, err := pfe.parser.ExprInterpreter.InterpretString(expression) 11 | if err != nil { 12 | panic(err) 13 | } 14 | return bytes 15 | } 16 | 17 | func (pfe *fuzzDelegationExecutor) delegatorAddress(delegIndex int) string { 18 | if delegIndex == 0 { 19 | return pfe.ownerAddress 20 | } 21 | 22 | return fmt.Sprintf("address:delegator-%05d", delegIndex) 23 | } 24 | 25 | func (pfe *fuzzDelegationExecutor) getAuctionBalance() *big.Int { 26 | // pfe.parser.ExprInterpreter.InterpretString() 27 | acct := pfe.world.AcctMap.GetAccount(pfe.interpretExpr(pfe.auctionMockAddress)) 28 | return acct.Balance 29 | } 30 | 31 | func (pfe *fuzzDelegationExecutor) getWithdrawTargetBalance() *big.Int { 32 | acct := pfe.world.AcctMap.GetAccount(pfe.interpretExpr(pfe.withdrawTargetAddress)) 33 | return acct.Balance 34 | } 35 | 36 | func (pfe *fuzzDelegationExecutor) getContractBalance() *big.Int { 37 | acct := pfe.world.AcctMap.GetAccount(pfe.interpretExpr(pfe.delegationContractAddress)) 38 | return acct.Balance 39 | } 40 | -------------------------------------------------------------------------------- /test/contracts/exec-dest-ctx-esdt/basic/basic.c: -------------------------------------------------------------------------------- 1 | #include "../../mxvm/context.h" 2 | #include "../../mxvm/test_utils.h" 3 | #include "../../mxvm/args.h" 4 | 5 | byte executeValue[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; 6 | byte self[32] = "\0\0\0\0\0\0\0\0\x0f\x0f" "parentSC.............."; 7 | byte vaultSC[] = "\0\0\0\0\0\0\0\0\x0F\x0F" "vaultSC..............."; 8 | byte ESDTTransfer[] = "ESDTTransfer"; 9 | 10 | void basic_transfer() { 11 | byte tokenName[265] = {0}; 12 | int tokenNameLen = getESDTTokenName(tokenName); 13 | 14 | byte esdtValue[32] = {0}; 15 | int esdtValueLen = getESDTValue(esdtValue); 16 | 17 | esdtValue[31] -= 1; 18 | 19 | BinaryArgs args = NewBinaryArgs(); 20 | 21 | int lastArg = 0; 22 | lastArg = AddBinaryArg(&args, tokenName, tokenNameLen); 23 | lastArg = AddBinaryArg(&args, esdtValue, esdtValueLen); 24 | TrimLeftZeros(&args, lastArg); 25 | 26 | byte arguments[100]; 27 | int argsLen = SerializeBinaryArgs(&args, arguments); 28 | 29 | int result = executeOnDestContext( 30 | 1000000, 31 | self, 32 | executeValue, 33 | ESDTTransfer, 34 | sizeof ESDTTransfer - 1, 35 | args.numArgs, 36 | (byte*)args.lengthsAsI32, 37 | args.serialized 38 | ); 39 | } 40 | -------------------------------------------------------------------------------- /test/features/basic-features/scenarios/echo_nothing.scen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "echo_nothing", 3 | "gasSchedule": "v3", 4 | "steps": [ 5 | { 6 | "step": "setState", 7 | "accounts": { 8 | "sc:basic-features": { 9 | "nonce": "0", 10 | "balance": "0", 11 | "code": "mxsc:../output/basic-features.mxsc.json" 12 | }, 13 | "address:an_account": { 14 | "nonce": "0", 15 | "balance": "0" 16 | } 17 | } 18 | }, 19 | { 20 | "step": "scCall", 21 | "id": "1", 22 | "tx": { 23 | "from": "address:an_account", 24 | "to": "sc:basic-features", 25 | "function": "echo_nothing", 26 | "arguments": [], 27 | "gasLimit": "50,000,000", 28 | "gasPrice": "0" 29 | }, 30 | "expect": { 31 | "out": [], 32 | "status": "", 33 | "logs": "*", 34 | "gas": "*", 35 | "refund": "*" 36 | } 37 | } 38 | ] 39 | } 40 | -------------------------------------------------------------------------------- /test/features/basic-features-ei-1-3/scenarios/echo_nothing.scen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "echo_nothing", 3 | "gasSchedule": "v3", 4 | "steps": [ 5 | { 6 | "step": "setState", 7 | "accounts": { 8 | "sc:basic-features": { 9 | "nonce": "0", 10 | "balance": "0", 11 | "code": "mxsc:../output/basic-features.mxsc.json" 12 | }, 13 | "address:an_account": { 14 | "nonce": "0", 15 | "balance": "0" 16 | } 17 | } 18 | }, 19 | { 20 | "step": "scCall", 21 | "id": "1", 22 | "tx": { 23 | "from": "address:an_account", 24 | "to": "sc:basic-features", 25 | "function": "echo_nothing", 26 | "arguments": [], 27 | "gasLimit": "50,000,000", 28 | "gasPrice": "0" 29 | }, 30 | "expect": { 31 | "out": [], 32 | "status": "", 33 | "logs": "*", 34 | "gas": "*", 35 | "refund": "*" 36 | } 37 | } 38 | ] 39 | } 40 | -------------------------------------------------------------------------------- /test/delegation/v0_3/test/integration/genesis/04b_genesis_activate.steps.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "genesis activate", 3 | "steps": [ 4 | { 5 | "step": "scCall", 6 | "id": "activate-genesis-1", 7 | "tx": { 8 | "from": "''node_address__________________s1", 9 | "to": "sc:delegation", 10 | "function": "activateGenesis", 11 | "arguments": [], 12 | "gasLimit": "100,000,000", 13 | "gasPrice": "0" 14 | }, 15 | "expect": { 16 | "out": [], 17 | "status": "", 18 | "logs": [ 19 | { 20 | "address": "sc:delegation", 21 | "endpoint": "str:activateGenesis", 22 | "topics": [ 23 | "0x0000000000000000000000000000000000000000000000000000000000000003" 24 | ], 25 | "data": [ 26 | "0x" 27 | ] 28 | } 29 | ], 30 | "gas": "*", 31 | "refund": "*" 32 | } 33 | } 34 | ] 35 | } 36 | -------------------------------------------------------------------------------- /test/features/basic-features-legacy/scenarios/echo_nothing_legacy.scen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "echo_nothing", 3 | "gasSchedule": "dummy", 4 | "steps": [ 5 | { 6 | "step": "setState", 7 | "accounts": { 8 | "sc:basic-features": { 9 | "nonce": "0", 10 | "balance": "0x100", 11 | "code": "file:../output/features-legacy.wasm" 12 | }, 13 | "address:an_account": { 14 | "nonce": "0", 15 | "balance": "0" 16 | } 17 | } 18 | }, 19 | { 20 | "step": "scCall", 21 | "id": "1", 22 | "tx": { 23 | "from": "address:an_account", 24 | "to": "sc:basic-features", 25 | "function": "echo_nothing", 26 | "arguments": [], 27 | "gasLimit": "1,000,000", 28 | "gasPrice": "0" 29 | }, 30 | "expect": { 31 | "out": [], 32 | "status": "", 33 | "logs": "*", 34 | "gas": "*", 35 | "refund": "*" 36 | } 37 | } 38 | ] 39 | } 40 | -------------------------------------------------------------------------------- /test/delegation/v0_4_genesis/test/integration/genesis/04b_genesis_activate.steps.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "genesis activate", 3 | "steps": [ 4 | { 5 | "step": "scCall", 6 | "id": "activate-genesis-1", 7 | "tx": { 8 | "from": "''node_address__________________s1", 9 | "to": "sc:delegation", 10 | "function": "activateGenesis", 11 | "arguments": [], 12 | "gasLimit": "100,000,000", 13 | "gasPrice": "0" 14 | }, 15 | "expect": { 16 | "out": [], 17 | "status": "", 18 | "logs": [ 19 | { 20 | "address": "sc:delegation", 21 | "endpoint": "str:activateGenesis", 22 | "topics": [ 23 | "0x0000000000000000000000000000000000000000000000000000000000000003" 24 | ], 25 | "data": [ 26 | "0x" 27 | ] 28 | } 29 | ], 30 | "gas": "*", 31 | "refund": "*" 32 | } 33 | } 34 | ] 35 | } 36 | -------------------------------------------------------------------------------- /wasmer2/error2.go: -------------------------------------------------------------------------------- 1 | package wasmer2 2 | 3 | import ( 4 | "errors" 5 | "fmt" 6 | "unsafe" 7 | ) 8 | 9 | var ErrFailedInstantiation = errors.New("could not create wasmer instance") 10 | 11 | var ErrFailedCacheImports = errors.New("could not cache imports") 12 | 13 | var ErrInvalidBytecode = errors.New("invalid bytecode") 14 | 15 | var ErrCachingFailed = errors.New("instance caching failed") 16 | 17 | // GetLastError returns the last error message if any, otherwise returns an error. 18 | func GetLastError() (string, error) { 19 | var errorLength = cWasmerLastErrorLength() 20 | 21 | if errorLength == 0 { 22 | return "", nil 23 | } 24 | 25 | var errorMessage = make([]cChar, errorLength) 26 | var errorMessagePointer = (*cChar)(unsafe.Pointer(&errorMessage[0])) 27 | 28 | var errorResult = cWasmerLastErrorMessage(errorMessagePointer, errorLength) 29 | 30 | if errorResult == -1 { 31 | return "", errors.New("cannot read last error") 32 | } 33 | 34 | return cGoString(errorMessagePointer), nil 35 | } 36 | 37 | func newWrappedError(target error) error { 38 | var lastError string 39 | var err error 40 | lastError, err = GetLastError() 41 | 42 | if err != nil { 43 | lastError = "unknown details" 44 | } 45 | 46 | return fmt.Errorf("%w: %s", target, lastError) 47 | } 48 | -------------------------------------------------------------------------------- /test/features/alloc-features/scenarios/alloc_mem_leaking.scen.json: -------------------------------------------------------------------------------- 1 | { 2 | "gasSchedule": "v3", 3 | "steps": [ 4 | { 5 | "step": "setState", 6 | "accounts": { 7 | "sc:alloc-mem-leaking": { 8 | "nonce": "0", 9 | "balance": "0", 10 | "code": "mxsc:../output/alloc-mem-leaking.mxsc.json" 11 | }, 12 | "address:an_account": { 13 | "nonce": "0", 14 | "balance": "0" 15 | } 16 | } 17 | }, 18 | { 19 | "step": "scCall", 20 | "id": "1", 21 | "tx": { 22 | "from": "address:an_account", 23 | "to": "sc:alloc-mem-leaking", 24 | "function": "alloc_with_leaking_memory", 25 | "arguments": [], 26 | "gasLimit": "50,000,000", 27 | "gasPrice": "0" 28 | }, 29 | "expect": { 30 | "out": [ 31 | "1" 32 | ], 33 | "status": "", 34 | "logs": "*", 35 | "gas": "*", 36 | "refund": "*" 37 | } 38 | } 39 | ] 40 | } 41 | -------------------------------------------------------------------------------- /test/features/alloc-features/scenarios/alloc_mem_fail.scen.json: -------------------------------------------------------------------------------- 1 | { 2 | "gasSchedule": "v3", 3 | "steps": [ 4 | { 5 | "step": "setState", 6 | "accounts": { 7 | "sc:alloc-mem-fail": { 8 | "nonce": "0", 9 | "balance": "0", 10 | "code": "mxsc:../output/alloc-mem-fail.mxsc.json" 11 | }, 12 | "address:an_account": { 13 | "nonce": "0", 14 | "balance": "0" 15 | } 16 | } 17 | }, 18 | { 19 | "step": "scCall", 20 | "id": "1", 21 | "tx": { 22 | "from": "address:an_account", 23 | "to": "sc:alloc-mem-fail", 24 | "function": "alloc_with_fail_memory", 25 | "arguments": [], 26 | "gasLimit": "50,000,000", 27 | "gasPrice": "0" 28 | }, 29 | "expect": { 30 | "out": [], 31 | "status": "4", 32 | "message": "str:memory allocation forbidden", 33 | "logs": "*", 34 | "gas": "*", 35 | "refund": "*" 36 | } 37 | } 38 | ] 39 | } 40 | -------------------------------------------------------------------------------- /test/features/composability/scenarios/promises_call_callback_directly.scen.json: -------------------------------------------------------------------------------- 1 | { 2 | "steps": [ 3 | { 4 | "step": "setState", 5 | "accounts": { 6 | "address:a_user": { 7 | "nonce": "0", 8 | "balance": "0" 9 | }, 10 | "sc:forwarder": { 11 | "nonce": "0", 12 | "balance": "0", 13 | "code": "mxsc:../forwarder/output/forwarder.mxsc.json" 14 | } 15 | } 16 | }, 17 | { 18 | "step": "scCall", 19 | "id": "1", 20 | "tx": { 21 | "from": "address:a_user", 22 | "to": "sc:forwarder", 23 | "function": "retrieve_funds_callback", 24 | "arguments": [], 25 | "gasLimit": "70,000,000", 26 | "gasPrice": "0" 27 | }, 28 | "expect": { 29 | "out": [], 30 | "status": "10", 31 | "message": "str:no callback for closure, cannot call callback directly", 32 | "logs": "*", 33 | "gas": "*", 34 | "refund": "*" 35 | } 36 | } 37 | ] 38 | } 39 | -------------------------------------------------------------------------------- /.github/workflows/golangci-lint.yml: -------------------------------------------------------------------------------- 1 | name: golangci-lint 2 | on: 3 | push: 4 | branches: 5 | - master 6 | pull_request: 7 | branches: [ master, feat/*, rc/* ] 8 | 9 | permissions: 10 | contents: read 11 | 12 | jobs: 13 | golangci: 14 | name: golangci linter 15 | runs-on: ubuntu-latest 16 | steps: 17 | - uses: actions/setup-go@v5 18 | with: 19 | go-version: 1.23.6 20 | - uses: actions/checkout@v4 21 | - name: golangci-lint 22 | uses: golangci/golangci-lint-action@v6 23 | with: 24 | # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. 25 | version: v1.64.5 26 | 27 | # Optional: working directory, useful for monorepos 28 | # working-directory: somedir 29 | 30 | # Optional: golangci-lint command line arguments. 31 | args: --timeout 10m0s --max-issues-per-linter 0 --max-same-issues 0 --print-issued-lines 32 | 33 | # Optional: show only new issues if it's a pull request. The default value is `false`. 34 | only-new-issues: true 35 | 36 | # Optional: if set to true then the action will use pre-installed Go 37 | # skip-go-installation: true 38 | -------------------------------------------------------------------------------- /math/errors.go: -------------------------------------------------------------------------------- 1 | package math 2 | 3 | import ( 4 | "errors" 5 | ) 6 | 7 | // ErrAdditionOverflow is raised when there is an overflow because of the addition of two numbers 8 | var ErrAdditionOverflow = errors.New("addition overflow") 9 | 10 | // ErrMultiplicationOverflow is raised when there is an overflow because of the multiplication of two numbers 11 | var ErrMultiplicationOverflow = errors.New("multiplication overflow") 12 | 13 | // ErrBigFloatSub is raised when sub of floats produces a panic 14 | var ErrBigFloatSub = errors.New("this big Float operation is not permitted while doing float.Sub") 15 | 16 | // ErrBigFloatAdd is raised when add of floats produces a panic 17 | var ErrBigFloatAdd = errors.New("this big Float operation is not permitted while doing float.Add") 18 | 19 | // ErrBigFloatQuo is raised when quo of floats produces a panic 20 | var ErrBigFloatQuo = errors.New("this big Float operation is not permitted while doing float.Quo") 21 | 22 | // ErrBigFloatMul is raised when mul of floats produces a panic 23 | var ErrBigFloatMul = errors.New("this big Float operation is not permitted while doing float.Mul") 24 | 25 | // ErrBigFloatSqrt is raised when sqrt of floats produces a panic 26 | var ErrBigFloatSqrt = errors.New("this big Float operation is not permitted while doing float.Sqrt") 27 | -------------------------------------------------------------------------------- /test/delegation/v0_3/test/integration/owner_share/04_activate_bad.steps.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "activate not possible because owner has not enough skin in the game", 3 | "steps": [ 4 | { 5 | "step": "scCall", 6 | "id": "activate-1", 7 | "tx": { 8 | "from": "''node_address__________________s1", 9 | "to": "sc:delegation", 10 | "function": "stakeNodes", 11 | "arguments": [ 12 | "''bls_key_2_______________________________________________________________________________________", 13 | "''bls_key_3_______________________________________________________________________________________", 14 | "''bls_key_6_______________________________________________________________________________________" 15 | ], 16 | "gasLimit": "100,000,000", 17 | "gasPrice": "0" 18 | }, 19 | "expect": { 20 | "out": [], 21 | "status": "4", 22 | "message": "str:owner doesn't have enough stake in the contract", 23 | "logs": "*", 24 | "gas": "*", 25 | "refund": "*" 26 | } 27 | } 28 | ] 29 | } 30 | -------------------------------------------------------------------------------- /vmhost/asyncCall.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | option go_package = "vmhost"; 4 | option (gogoproto.stable_marshaler_all) = true; 5 | 6 | import "github.com/gogo/protobuf/gogoproto/gogo.proto"; 7 | 8 | package vmhost; 9 | 10 | enum SerializableAsyncCallStatus { 11 | SerializableAsyncCallPending = 0; 12 | SerializableAsyncCallResolved = 1; 13 | SerializableAsyncCallRejected = 2; 14 | } 15 | 16 | enum SerializableAsyncCallExecutionMode { 17 | SerializableSyncExecution = 0; 18 | SerializableAsyncBuiltinFuncIntraShard = 1; 19 | SerializableAsyncBuiltinFuncCrossShard = 2; 20 | SerializableAsyncUnknown = 3; 21 | } 22 | 23 | message SerializableAsyncCall { 24 | bytes CallID = 1; 25 | SerializableAsyncCallStatus Status = 2; 26 | SerializableAsyncCallExecutionMode ExecutionMode = 3; 27 | bytes Destination = 5; 28 | bytes Data = 6; 29 | uint64 GasLimit = 7; 30 | uint64 GasLocked = 8; 31 | bytes ValueBytes = 9; 32 | string SuccessCallback = 10; 33 | string ErrorCallback = 11; 34 | bytes CallbackClosure = 12; 35 | } 36 | 37 | message SerializableAsyncCallGroup { 38 | string Callback = 1; 39 | uint64 GasLocked = 2; 40 | bytes CallbackData = 3; 41 | string Identifier = 4; 42 | repeated SerializableAsyncCall AsyncCalls = 5; 43 | } 44 | -------------------------------------------------------------------------------- /test/contracts/exchange/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![no_std] 2 | 3 | imports!(); 4 | 5 | const TOKEN_NAME: &[u8] = b"TT"; 6 | 7 | 8 | pub trait Exchange { 9 | 10 | #[endpoint(validateGetters)] 11 | fn validate_getters(&self) -> SCResult<()> { 12 | sc_try!(self.validate_esdt_token_name()); 13 | sc_try!(self.validate_esdt_token_value(5)); 14 | Ok(()) 15 | } 16 | 17 | fn validate_esdt_token_name(&self) -> SCResult<()> { 18 | let token_name: Option> = self.get_esdt_token_name(); 19 | match token_name { 20 | None => { 21 | sc_error!("esdt token required") 22 | }, 23 | Some(name) => { 24 | require!(name.as_slice() == TOKEN_NAME, "wrong esdt token"); 25 | Ok(()) 26 | } 27 | } 28 | } 29 | 30 | fn validate_esdt_token_value(&self, expected_value: u64) -> SCResult<()> { 31 | let token_value = self.get_esdt_value_big_uint(); 32 | let expected_value = BigUint::from(expected_value); 33 | require!(expected_value == token_value, "wrong esdt value"); 34 | Ok(()) 35 | } 36 | 37 | #[endpoint(validateGettersAfterESDTTransfer)] 38 | fn validate_getters_after_esdt_transfer(&self) -> SCResult<()> { 39 | Ok(()) 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /crypto/interface.go: -------------------------------------------------------------------------------- 1 | package crypto 2 | 3 | // Hasher defines the functionality of a component able to generate hashes 4 | type Hasher interface { 5 | Sha256(data []byte) ([]byte, error) 6 | Keccak256(data []byte) ([]byte, error) 7 | Ripemd160(data []byte) ([]byte, error) 8 | } 9 | 10 | // BLS defines the functionality of a component able to verify BLS signatures 11 | type BLS interface { 12 | VerifyBLS(key []byte, msg []byte, sig []byte) error 13 | VerifySignatureShare(publicKey []byte, message []byte, sig []byte) error 14 | VerifyAggregatedSig(pubKeysSigners [][]byte, message []byte, aggSig []byte) error 15 | } 16 | 17 | // Ed25519 defines the functionality of a component able to verify Ed25519 signatures 18 | type Ed25519 interface { 19 | VerifyEd25519(key []byte, msg []byte, sig []byte) error 20 | } 21 | 22 | // Secp256 defines the functionality of a component able to verify and encode Secp256 signatures 23 | type Secp256 interface { 24 | VerifySecp256k1(key []byte, msg []byte, sig []byte, hashType uint8) error 25 | EncodeSecp256k1DERSignature(r, s []byte) []byte 26 | VerifySecp256r1(key []byte, msg []byte, sig []byte) error 27 | } 28 | 29 | // VMCrypto will provide the interface to the main crypto functionalities of the vm 30 | type VMCrypto interface { 31 | Hasher 32 | Ed25519 33 | BLS 34 | Secp256 35 | } 36 | -------------------------------------------------------------------------------- /test/contracts/pair/output/pair.imports.json: -------------------------------------------------------------------------------- 1 | [ 2 | "bigIntSetInt64", 3 | "bigIntAdd", 4 | "signalError", 5 | "mBufferNew", 6 | "mBufferAppend", 7 | "mBufferEq", 8 | "getGasLeft", 9 | "managedSCAddress", 10 | "cleanReturnData", 11 | "managedCaller", 12 | "mBufferGetLength", 13 | "managedGetMultiESDTCallValue", 14 | "mBufferGetArgument", 15 | "mBufferAppendBytes", 16 | "managedSignalError", 17 | "smallIntGetUnsignedArgument", 18 | "bigIntGetUnsignedArgument", 19 | "getNumArguments", 20 | "smallIntFinishUnsigned", 21 | "mBufferFinish", 22 | "bigIntFinishUnsigned", 23 | "bigIntSign", 24 | "mBufferSetBytes", 25 | "bigIntTDiv", 26 | "bigIntMul", 27 | "mBufferFromBigIntUnsigned", 28 | "mBufferToBigIntUnsigned", 29 | "validateTokenIdentifier", 30 | "mBufferCopyByteSlice", 31 | "mBufferStorageLoad", 32 | "mBufferStorageStore", 33 | "bigIntCmp", 34 | "managedExecuteOnDestContext", 35 | "managedMultiTransferESDTNFTExecute", 36 | "getBlockEpoch", 37 | "getBlockNonce", 38 | "getBlockTimestamp", 39 | "managedWriteLog", 40 | "checkNoPayment", 41 | "smallIntFinishSigned", 42 | "finish", 43 | "mBufferGetBytes", 44 | "isSmartContract", 45 | "bigIntSub", 46 | "mBufferGetByteSlice" 47 | ] -------------------------------------------------------------------------------- /test/features/basic-features/scenarios/return_codes.scen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "return_codes", 3 | "steps": [ 4 | { 5 | "step": "setState", 6 | "accounts": { 7 | "sc:basic-features": { 8 | "nonce": "0", 9 | "balance": "0", 10 | "code": "mxsc:../output/basic-features.mxsc.json" 11 | }, 12 | "address:an_account": { 13 | "nonce": "0", 14 | "balance": "0" 15 | } 16 | } 17 | }, 18 | { 19 | "step": "scCall", 20 | "id": "call-a-function-which-does-not-exist", 21 | "tx": { 22 | "from": "address:an_account", 23 | "to": "sc:basic-features", 24 | "function": "function_which_does_not_exist", 25 | "arguments": [], 26 | "gasLimit": "50,000,000", 27 | "gasPrice": "0" 28 | }, 29 | "expect": { 30 | "out": [], 31 | "status": "1", 32 | "message": "str:invalid function (not found)", 33 | "logs": "*", 34 | "gas": "*", 35 | "refund": "*" 36 | } 37 | } 38 | ] 39 | } 40 | -------------------------------------------------------------------------------- /test/features/basic-features-ei-1-3/scenarios/return_codes.scen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "return_codes", 3 | "steps": [ 4 | { 5 | "step": "setState", 6 | "accounts": { 7 | "sc:basic-features": { 8 | "nonce": "0", 9 | "balance": "0", 10 | "code": "mxsc:../output/basic-features.mxsc.json" 11 | }, 12 | "address:an_account": { 13 | "nonce": "0", 14 | "balance": "0" 15 | } 16 | } 17 | }, 18 | { 19 | "step": "scCall", 20 | "id": "call-a-function-which-does-not-exist", 21 | "tx": { 22 | "from": "address:an_account", 23 | "to": "sc:basic-features", 24 | "function": "function_which_does_not_exist", 25 | "arguments": [], 26 | "gasLimit": "50,000,000", 27 | "gasPrice": "0" 28 | }, 29 | "expect": { 30 | "out": [], 31 | "status": "1", 32 | "message": "str:invalid function (not found)", 33 | "logs": "*", 34 | "gas": "*", 35 | "refund": "*" 36 | } 37 | } 38 | ] 39 | } 40 | -------------------------------------------------------------------------------- /vmhost/mock/builtInFunctionStub.go: -------------------------------------------------------------------------------- 1 | package mock 2 | 3 | import ( 4 | vmcommon "github.com/multiversx/mx-chain-vm-common-go" 5 | ) 6 | 7 | // BuiltInFunctionStub - 8 | type BuiltInFunctionStub struct { 9 | ProcessBuiltinFunctionCalled func(acntSnd, acntDst vmcommon.UserAccountHandler, vmInput *vmcommon.ContractCallInput) (*vmcommon.VMOutput, error) 10 | SetNewGasConfigCalled func(gasCost *vmcommon.GasCost) 11 | IsActiveCalled func() bool 12 | } 13 | 14 | // ProcessBuiltinFunction - 15 | func (b *BuiltInFunctionStub) ProcessBuiltinFunction(acntSnd, acntDst vmcommon.UserAccountHandler, vmInput *vmcommon.ContractCallInput) (*vmcommon.VMOutput, error) { 16 | if b.ProcessBuiltinFunctionCalled != nil { 17 | return b.ProcessBuiltinFunctionCalled(acntSnd, acntDst, vmInput) 18 | } 19 | return &vmcommon.VMOutput{}, nil 20 | } 21 | 22 | // SetNewGasConfig - 23 | func (b *BuiltInFunctionStub) SetNewGasConfig(gasCost *vmcommon.GasCost) { 24 | if b.SetNewGasConfigCalled != nil { 25 | b.SetNewGasConfigCalled(gasCost) 26 | } 27 | } 28 | 29 | // IsActive - 30 | func (b *BuiltInFunctionStub) IsActive() bool { 31 | if b.IsActiveCalled != nil { 32 | return b.IsActiveCalled() 33 | } 34 | return true 35 | } 36 | 37 | // IsInterfaceNil - 38 | func (b *BuiltInFunctionStub) IsInterfaceNil() bool { 39 | return b == nil 40 | } 41 | -------------------------------------------------------------------------------- /test/features/basic-features/scenarios/big_uint_sqrt.scen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "sqrt", 3 | "gasSchedule": "v3", 4 | "steps": [ 5 | { 6 | "step": "setState", 7 | "accounts": { 8 | "sc:basic-features": { 9 | "nonce": "0", 10 | "balance": "0", 11 | "code": "mxsc:../output/basic-features.mxsc.json" 12 | }, 13 | "address:an_account": { 14 | "nonce": "0", 15 | "balance": "0" 16 | } 17 | } 18 | }, 19 | { 20 | "step": "scCall", 21 | "id": "sqrt", 22 | "tx": { 23 | "from": "address:an_account", 24 | "to": "sc:basic-features", 25 | "function": "sqrt_big_uint", 26 | "arguments": [ 27 | "100" 28 | ], 29 | "gasLimit": "50,000,000", 30 | "gasPrice": "0" 31 | }, 32 | "expect": { 33 | "out": [ 34 | "10" 35 | ], 36 | "status": "0", 37 | "logs": "*", 38 | "gas": "*", 39 | "refund": "*" 40 | } 41 | } 42 | ] 43 | } 44 | -------------------------------------------------------------------------------- /test/features/basic-features-ei-1-3/scenarios/big_uint_sqrt.scen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "sqrt", 3 | "gasSchedule": "v3", 4 | "steps": [ 5 | { 6 | "step": "setState", 7 | "accounts": { 8 | "sc:basic-features": { 9 | "nonce": "0", 10 | "balance": "0", 11 | "code": "mxsc:../output/basic-features.mxsc.json" 12 | }, 13 | "address:an_account": { 14 | "nonce": "0", 15 | "balance": "0" 16 | } 17 | } 18 | }, 19 | { 20 | "step": "scCall", 21 | "id": "sqrt", 22 | "tx": { 23 | "from": "address:an_account", 24 | "to": "sc:basic-features", 25 | "function": "sqrt_big_uint", 26 | "arguments": [ 27 | "100" 28 | ], 29 | "gasLimit": "50,000,000", 30 | "gasPrice": "0" 31 | }, 32 | "expect": { 33 | "out": [ 34 | "10" 35 | ], 36 | "status": "0", 37 | "logs": "*", 38 | "gas": "*", 39 | "refund": "*" 40 | } 41 | } 42 | ] 43 | } 44 | -------------------------------------------------------------------------------- /testcommon/testexecutor/defaultTestExecutor.go: -------------------------------------------------------------------------------- 1 | // Package testexecutor provides with a default executor for testing 2 | package testexecutor 3 | 4 | import ( 5 | "fmt" 6 | "os" 7 | "testing" 8 | 9 | "github.com/multiversx/mx-chain-vm-go/executor" 10 | "github.com/multiversx/mx-chain-vm-go/wasmer2" 11 | ) 12 | 13 | // EnvVMEXECUTOR is the name of the environment variable that controls the default test executor 14 | var EnvVMEXECUTOR = "VMEXECUTOR" 15 | 16 | // ExecWasmer2 is the value of the EnvVMEXECUTOR variable which selects Wasmer 2 17 | var ExecWasmer2 = "wasmer2" 18 | 19 | var defaultExecutorString = ExecWasmer2 20 | 21 | // NewDefaultTestExecutorFactory instantiates an executor factory based on the $VMEXECUTOR environment variable 22 | func NewDefaultTestExecutorFactory(tb testing.TB) executor.ExecutorAbstractFactory { 23 | execStr := getVMExecutorString() 24 | 25 | if execStr == ExecWasmer2 { 26 | return wasmer2.ExecutorFactory() 27 | } 28 | 29 | if tb == (testing.TB)(nil) { 30 | panic(fmt.Sprintf("executor %s not recognized", execStr)) 31 | } 32 | tb.Fatalf("executor %s not recognized", execStr) 33 | 34 | return nil 35 | } 36 | 37 | func getVMExecutorString() string { 38 | execStr := os.Getenv(EnvVMEXECUTOR) 39 | 40 | if len(execStr) == 0 { 41 | execStr = defaultExecutorString 42 | } 43 | 44 | return execStr 45 | } 46 | -------------------------------------------------------------------------------- /test/features/basic-features-legacy/scenarios/send_tx_legacy.scen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "eventA1", 3 | "gasSchedule": "dummy", 4 | "steps": [ 5 | { 6 | "step": "setState", 7 | "accounts": { 8 | "sc:basic-features": { 9 | "nonce": "0", 10 | "balance": "100", 11 | "code": "file:../output/features-legacy.wasm" 12 | }, 13 | "address:an_account": { 14 | "nonce": "0", 15 | "balance": "0" 16 | } 17 | } 18 | }, 19 | { 20 | "step": "scCall", 21 | "id": "1", 22 | "tx": { 23 | "from": "address:an_account", 24 | "to": "sc:basic-features", 25 | "function": "send_tx_endpoint", 26 | "arguments": [ 27 | "address:an_account", 28 | "10000" 29 | ], 30 | "gasLimit": "0x100000", 31 | "gasPrice": "0" 32 | }, 33 | "expect": { 34 | "out": [], 35 | "status": "10", 36 | "message": "str:failed transfer (insufficient funds)", 37 | "logs": "*" 38 | } 39 | } 40 | ] 41 | } 42 | -------------------------------------------------------------------------------- /mock/context/memoryMock.go: -------------------------------------------------------------------------------- 1 | package mock 2 | 3 | // MemoryMock mocks the linear memory of a Wasmer instance and is used by the 4 | // InstanceMock. 5 | type MemoryMock struct { 6 | Pages uint32 7 | PageSize uint32 8 | Contents []byte 9 | } 10 | 11 | // NewMemoryMock creates a new MemoryMock instance 12 | func NewMemoryMock() *MemoryMock { 13 | memory := &MemoryMock{} 14 | memory.Pages = 2 15 | memory.PageSize = 65536 16 | memory.initMemory() 17 | return memory 18 | } 19 | 20 | // Length mocked method 21 | func (memory *MemoryMock) Length() uint32 { 22 | return uint32(len(memory.Contents)) 23 | } 24 | 25 | // Data mocked method 26 | func (memory *MemoryMock) Data() []byte { 27 | return memory.Contents 28 | } 29 | 30 | // Grow mocked method 31 | func (memory *MemoryMock) Grow(pages uint32) error { 32 | newPages := make([]byte, pages*memory.PageSize) 33 | memory.Contents = append(memory.Contents, newPages...) 34 | return nil 35 | } 36 | 37 | // Destroy mocked method 38 | func (memory *MemoryMock) Destroy() { 39 | memory.Contents = nil 40 | } 41 | 42 | // initMemory mocked method 43 | func (memory *MemoryMock) initMemory() { 44 | memory.Contents = make([]byte, memory.Pages*memory.PageSize) 45 | } 46 | 47 | // IsInterfaceNil returns true if underlying object is nil 48 | func (memory *MemoryMock) IsInterfaceNil() bool { 49 | return memory == nil 50 | } 51 | -------------------------------------------------------------------------------- /vmhost/vmhooks/generate/eiGenWriteWASMOpcodeCostFuncHelpers.go: -------------------------------------------------------------------------------- 1 | package vmhooksgenerate 2 | 3 | import ( 4 | "bufio" 5 | "fmt" 6 | "os" 7 | ) 8 | 9 | // WriteWASMOpcodeCostHelpers generates code for FillGasMap_WASMOpcodeCosts.txt 10 | // (to be copied manually in config/gasSchedule.go) 11 | func WriteWASMOpcodeCostFuncHelpers(out *eiGenWriter) { 12 | out.WriteString(`// Code generated by vmhooks generator. DO NOT EDIT. 13 | 14 | // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 15 | // !!!!!!!!!!!!!!!!!!!!!! AUTO-GENERATED FILE !!!!!!!!!!!!!!!!!!!!!! 16 | // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 17 | 18 | // !!!!!!!!!!!!!!!!!! USE IN config/gasSchedule.go !!!!!!!!!!!!!!!!! 19 | 20 | `) 21 | out.WriteString("func FillGasMap_WASMOpcodeCosts(value uint64) map[string]uint64 {\n") 22 | out.WriteString("\tgasMap := make(map[string]uint64)\n\n") 23 | 24 | readFile, err := os.Open("generate/cmd/input/wasm_opcodes.txt") 25 | if err != nil { 26 | panic(err) 27 | } 28 | defer readFile.Close() 29 | 30 | fileScanner := bufio.NewScanner(readFile) 31 | fileScanner.Split(bufio.ScanLines) 32 | 33 | for fileScanner.Scan() { 34 | opcode := fileScanner.Text() 35 | out.WriteString(fmt.Sprintf("\tgasMap[\"%s\"] = value\n", opcode)) 36 | } 37 | out.WriteString("\n\treturn gasMap\n") 38 | out.WriteString("}\n") 39 | } 40 | -------------------------------------------------------------------------------- /test/features/basic-features/scenarios/big_uint_pow.scen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "pow", 3 | "gasSchedule": "v3", 4 | "steps": [ 5 | { 6 | "step": "setState", 7 | "accounts": { 8 | "sc:basic-features": { 9 | "nonce": "0", 10 | "balance": "0", 11 | "code": "mxsc:../output/basic-features.mxsc.json" 12 | }, 13 | "address:an_account": { 14 | "nonce": "0", 15 | "balance": "0" 16 | } 17 | } 18 | }, 19 | { 20 | "step": "scCall", 21 | "id": "pow", 22 | "tx": { 23 | "from": "address:an_account", 24 | "to": "sc:basic-features", 25 | "function": "pow_big_uint", 26 | "arguments": [ 27 | "10", 28 | "2" 29 | ], 30 | "gasLimit": "50,000,000", 31 | "gasPrice": "0" 32 | }, 33 | "expect": { 34 | "out": [ 35 | "100" 36 | ], 37 | "status": "0", 38 | "logs": "*", 39 | "gas": "*", 40 | "refund": "*" 41 | } 42 | } 43 | ] 44 | } 45 | -------------------------------------------------------------------------------- /test/features/basic-features/scenarios/out_of_gas.scen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "storage", 3 | "gasSchedule": "v3", 4 | "steps": [ 5 | { 6 | "step": "setState", 7 | "accounts": { 8 | "sc:basic-features": { 9 | "nonce": "0", 10 | "balance": "0", 11 | "code": "mxsc:../output/basic-features.mxsc.json" 12 | }, 13 | "address:an_account": { 14 | "nonce": "0", 15 | "balance": "0" 16 | } 17 | } 18 | }, 19 | { 20 | "step": "scCall", 21 | "id": "oog", 22 | "tx": { 23 | "from": "address:an_account", 24 | "to": "sc:basic-features", 25 | "function": "store_map3", 26 | "arguments": [ 27 | "0x57", 28 | "true" 29 | ], 30 | "gasLimit": "100", 31 | "gasPrice": "0" 32 | }, 33 | "expect": { 34 | "out": [], 35 | "status": "5", 36 | "message": "str:not enough gas", 37 | "logs": "*", 38 | "gas": "*", 39 | "refund": "*" 40 | } 41 | } 42 | ] 43 | } 44 | -------------------------------------------------------------------------------- /.github/workflows/code-coverage.yml: -------------------------------------------------------------------------------- 1 | name: Code-coverage 2 | 3 | on: 4 | push: 5 | branches: [ master, rc/*, feat/* ] 6 | pull_request: 7 | branches: [ master, feat/*, rc/* ] 8 | workflow_dispatch: 9 | 10 | jobs: 11 | build: 12 | strategy: 13 | matrix: 14 | runs-on: [ubuntu-latest] 15 | runs-on: ${{ matrix.runs-on }} 16 | name: Build 17 | steps: 18 | - name: Set up Go 1.x 19 | uses: actions/setup-go@v5 20 | with: 21 | go-version: 1.23.6 22 | id: go 23 | 24 | - name: Check out code into the Go module directory 25 | uses: actions/checkout@v4 26 | 27 | - name: Get dependencies 28 | run: | 29 | go get -v -t -d ./... 30 | if [ -f Gopkg.toml ]; then 31 | curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh 32 | dep ensure 33 | fi 34 | - name: Run unit tests 35 | run: | 36 | TESTS_TO_RUN=$(go list ./... | grep -v /integrationTests/ | grep -v /fuzz/) 37 | go test -short -cover -coverprofile=coverage.txt -covermode=atomic -v ${TESTS_TO_RUN} 38 | 39 | - name: Upload coverage 40 | uses: codecov/codecov-action@v5 41 | with: 42 | fail_ci_if_error: true 43 | files: coverage.txt 44 | token: ${{ secrets.CODECOV_TOKEN }} 45 | -------------------------------------------------------------------------------- /test/features/basic-features-ei-1-3/scenarios/out_of_gas.scen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "storage", 3 | "gasSchedule": "v3", 4 | "steps": [ 5 | { 6 | "step": "setState", 7 | "accounts": { 8 | "sc:basic-features": { 9 | "nonce": "0", 10 | "balance": "0", 11 | "code": "mxsc:../output/basic-features.mxsc.json" 12 | }, 13 | "address:an_account": { 14 | "nonce": "0", 15 | "balance": "0" 16 | } 17 | } 18 | }, 19 | { 20 | "step": "scCall", 21 | "id": "oog", 22 | "tx": { 23 | "from": "address:an_account", 24 | "to": "sc:basic-features", 25 | "function": "store_map3", 26 | "arguments": [ 27 | "0x57", 28 | "true" 29 | ], 30 | "gasLimit": "100", 31 | "gasPrice": "0" 32 | }, 33 | "expect": { 34 | "out": [], 35 | "status": "5", 36 | "message": "str:not enough gas", 37 | "logs": "*", 38 | "gas": "*", 39 | "refund": "*" 40 | } 41 | } 42 | ] 43 | } 44 | -------------------------------------------------------------------------------- /vmhost/vmhooks/generate/eiGenWriteOpcodeCostFuncHelpers.go: -------------------------------------------------------------------------------- 1 | package vmhooksgenerate 2 | 3 | import ( 4 | "bufio" 5 | "fmt" 6 | "os" 7 | ) 8 | 9 | // WriteOpcodeCostFuncHelpers generates code for extractOpcodeCost.txt 10 | // (to be copied manually in wasmer2/wasmer2Executor.go) 11 | func WriteOpcodeCostFuncHelpers(out *eiGenWriter) { 12 | out.WriteString(`// Code generated by vmhooks generator. DO NOT EDIT. 13 | 14 | // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 15 | // !!!!!!!!!!!!!!!!!!!!!! AUTO-GENERATED FILE !!!!!!!!!!!!!!!!!!!!!! 16 | // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 17 | 18 | // !!!!!!!!!!!!!!! USE IN wasmer2/wasmer2Executor.go !!!!!!!!!!!!!!! 19 | 20 | `) 21 | out.WriteString("func (wasmerExecutor *Wasmer2Executor) extractOpcodeCost(wasmOps *executor.WASMOpcodeCost) *OpcodeCost {\n") 22 | out.WriteString("\treturn &OpcodeCost {\n") 23 | 24 | readFile, err := os.Open("generate/cmd/input/wasmer2_opcodes_short.txt") 25 | if err != nil { 26 | panic(err) 27 | } 28 | defer readFile.Close() 29 | 30 | fileScanner := bufio.NewScanner(readFile) 31 | fileScanner.Split(bufio.ScanLines) 32 | 33 | for fileScanner.Scan() { 34 | opcode := fileScanner.Text() 35 | out.WriteString(fmt.Sprintf("\t\t%s: wasmOps.%s,\n", opcode, opcode)) 36 | } 37 | out.WriteString("\t}\n") 38 | out.WriteString("}\n") 39 | } 40 | -------------------------------------------------------------------------------- /crypto/hashing/hasher.go: -------------------------------------------------------------------------------- 1 | //nolint:all 2 | package hashing 3 | 4 | import ( 5 | "crypto/sha256" 6 | 7 | "golang.org/x/crypto/ripemd160" 8 | "golang.org/x/crypto/sha3" 9 | ) 10 | 11 | type hasher struct { 12 | } 13 | 14 | // NewHasher returns a new hasher instance implementing wrappers over different hash functions 15 | func NewHasher() *hasher { 16 | return &hasher{} 17 | } 18 | 19 | // Sha256 returns a sha 256 hash of the input string. Should return in hex format 20 | func (h *hasher) Sha256(data []byte) ([]byte, error) { 21 | hash := sha256.New() 22 | _, err := hash.Write(data) 23 | if err != nil { 24 | return nil, err 25 | } 26 | 27 | result := hash.Sum(nil) 28 | return result, nil 29 | } 30 | 31 | // Keccak256 returns a keccak 256 hash of the input string. Should return in hex format 32 | func (h *hasher) Keccak256(data []byte) ([]byte, error) { 33 | hash := sha3.NewLegacyKeccak256() 34 | _, err := hash.Write(data) 35 | if err != nil { 36 | return nil, err 37 | } 38 | 39 | result := hash.Sum(nil) 40 | return result, nil 41 | } 42 | 43 | // Ripemd160 is a legacy hash and should not be used for new applications 44 | func (h *hasher) Ripemd160(data []byte) ([]byte, error) { 45 | hash := ripemd160.New() 46 | _, err := hash.Write(data) 47 | if err != nil { 48 | return nil, err 49 | } 50 | 51 | result := hash.Sum(nil) 52 | return result, nil 53 | } 54 | -------------------------------------------------------------------------------- /test/features/basic-features-ei-1-3/scenarios/big_uint_pow.scen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "pow", 3 | "gasSchedule": "v3", 4 | "steps": [ 5 | { 6 | "step": "setState", 7 | "accounts": { 8 | "sc:basic-features": { 9 | "nonce": "0", 10 | "balance": "0", 11 | "code": "mxsc:../output/basic-features.mxsc.json" 12 | }, 13 | "address:an_account": { 14 | "nonce": "0", 15 | "balance": "0" 16 | } 17 | } 18 | }, 19 | { 20 | "step": "scCall", 21 | "id": "pow", 22 | "tx": { 23 | "from": "address:an_account", 24 | "to": "sc:basic-features", 25 | "function": "pow_big_uint", 26 | "arguments": [ 27 | "10", 28 | "2" 29 | ], 30 | "gasLimit": "50,000,000", 31 | "gasPrice": "0" 32 | }, 33 | "expect": { 34 | "out": [ 35 | "100" 36 | ], 37 | "status": "0", 38 | "logs": "*", 39 | "gas": "*", 40 | "refund": "*" 41 | } 42 | } 43 | ] 44 | } 45 | -------------------------------------------------------------------------------- /test/features/basic-features-legacy/scenarios/out_of_gas_legacy.scen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "storage", 3 | "gasSchedule": "dummy", 4 | "steps": [ 5 | { 6 | "step": "setState", 7 | "accounts": { 8 | "sc:basic-features": { 9 | "nonce": "0", 10 | "balance": "0", 11 | "code": "file:../output/features-legacy.wasm" 12 | }, 13 | "address:an_account": { 14 | "nonce": "0", 15 | "balance": "100000000000000000" 16 | } 17 | } 18 | }, 19 | { 20 | "step": "scCall", 21 | "id": "oog", 22 | "tx": { 23 | "from": "address:an_account", 24 | "to": "sc:basic-features", 25 | "function": "store_map3", 26 | "arguments": [ 27 | "0x57", 28 | "true" 29 | ], 30 | "gasLimit": "100", 31 | "gasPrice": "1" 32 | }, 33 | "expect": { 34 | "out": [], 35 | "status": "5", 36 | "message": "str:not enough gas", 37 | "logs": "*", 38 | "gas": "*", 39 | "refund": "*" 40 | } 41 | } 42 | ] 43 | } 44 | -------------------------------------------------------------------------------- /test/features/basic-features-legacy/scenarios/return_error_legacy.scen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "count ones", 3 | "comment": "should fail if the processor doesn't support the `count ones` instruction", 4 | "gasSchedule": "dummy", 5 | "steps": [ 6 | { 7 | "step": "setState", 8 | "accounts": { 9 | "sc:basic-features": { 10 | "nonce": "0", 11 | "balance": "0", 12 | "code": "file:../output/features-legacy.wasm" 13 | }, 14 | "address:an_account": { 15 | "nonce": "0", 16 | "balance": "0" 17 | } 18 | } 19 | }, 20 | { 21 | "step": "scCall", 22 | "id": "1", 23 | "tx": { 24 | "from": "address:an_account", 25 | "to": "sc:basic-features", 26 | "function": "return_error", 27 | "arguments": [], 28 | "gasLimit": "0x100000", 29 | "gasPrice": "0" 30 | }, 31 | "expect": { 32 | "out": [], 33 | "status": "4", 34 | "message": "str:return_error", 35 | "logs": "*", 36 | "gas": "*", 37 | "refund": "*" 38 | } 39 | } 40 | ] 41 | } 42 | -------------------------------------------------------------------------------- /vmhost/vmhooks/generate/eiGenWriteRustOpcodeCost.go: -------------------------------------------------------------------------------- 1 | package vmhooksgenerate 2 | 3 | import ( 4 | "bufio" 5 | "fmt" 6 | "os" 7 | "strings" 8 | ) 9 | 10 | const useStatements = ` 11 | use serde::{Deserialize, Serialize}; 12 | 13 | ` 14 | 15 | // WriteRustOpcodeCost generates code for opcode_cost.rs 16 | func WriteRustOpcodeCost(out *eiGenWriter) { 17 | out.WriteString(`// Code generated by vmhooks generator. DO NOT EDIT. 18 | 19 | // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 20 | // !!!!!!!!!!!!!!!!!!!!!! AUTO-GENERATED FILE !!!!!!!!!!!!!!!!!!!!!! 21 | // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 22 | `) 23 | out.WriteString(useStatements) 24 | out.WriteString("#[derive(Clone, Debug, Default, Deserialize, Serialize, PartialEq)]\n") 25 | out.WriteString("#[serde(default)]\n") 26 | out.WriteString("pub struct OpcodeCost {\n") 27 | 28 | readFile, err := os.Open("generate/cmd/input/wasmer2_opcodes_short.txt") 29 | if err != nil { 30 | panic(err) 31 | } 32 | defer readFile.Close() 33 | 34 | fileScanner := bufio.NewScanner(readFile) 35 | fileScanner.Split(bufio.ScanLines) 36 | 37 | for fileScanner.Scan() { 38 | line := fileScanner.Text() 39 | out.WriteString(fmt.Sprintf(" #[serde(rename = \"%s\", default)]\n", line)) 40 | out.WriteString(fmt.Sprintf(" pub opcode_%s: u32,\n", strings.ToLower(line))) 41 | } 42 | out.WriteString("}\n") 43 | } 44 | -------------------------------------------------------------------------------- /executor/executor.go: -------------------------------------------------------------------------------- 1 | // Package executor contains the interfaces and definitions for the VM Executor 2 | package executor 3 | 4 | import ( 5 | "github.com/multiversx/mx-chain-core-go/core/check" 6 | vmcommon "github.com/multiversx/mx-chain-vm-common-go" 7 | ) 8 | 9 | // CompilationOptions contains configurations for instantiating an executor instance. 10 | type CompilationOptions struct { 11 | GasLimit uint64 12 | UnmeteredLocals uint64 13 | MaxMemoryGrow uint64 14 | MaxMemoryGrowDelta uint64 15 | OpcodeTrace bool 16 | Metering bool 17 | RuntimeBreakpoints bool 18 | } 19 | 20 | // Executor defines the functionality needed to create any executor instance. 21 | type Executor interface { 22 | check.NilInterfaceChecker 23 | 24 | // SetOpcodeCosts sets gas costs globally inside an executor. 25 | SetOpcodeCosts(opcodeCosts *WASMOpcodeCost) 26 | 27 | // FunctionNames return the low-level function names provided to contracts. 28 | FunctionNames() vmcommon.FunctionNames 29 | 30 | // NewInstanceWithOptions creates a new executor instance. 31 | NewInstanceWithOptions( 32 | contractCode []byte, 33 | options CompilationOptions) (Instance, error) 34 | 35 | // NewInstanceFromCompiledCodeWithOptions is used to restore an executor instance from cache. 36 | NewInstanceFromCompiledCodeWithOptions( 37 | compiledCode []byte, 38 | options CompilationOptions) (Instance, error) 39 | } 40 | -------------------------------------------------------------------------------- /test/features/basic-features/scenarios/count_ones.scen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "count ones", 3 | "comment": "should fail if the processor doesn't support the `count ones` instruction", 4 | "gasSchedule": "v3", 5 | "steps": [ 6 | { 7 | "step": "setState", 8 | "accounts": { 9 | "sc:basic-features": { 10 | "nonce": "0", 11 | "balance": "0", 12 | "code": "mxsc:../output/basic-features.mxsc.json" 13 | }, 14 | "address:an_account": { 15 | "nonce": "0", 16 | "balance": "0" 17 | } 18 | } 19 | }, 20 | { 21 | "step": "scCall", 22 | "id": "1", 23 | "tx": { 24 | "from": "address:an_account", 25 | "to": "sc:basic-features", 26 | "function": "count_ones", 27 | "arguments": [ 28 | "0b010110" 29 | ], 30 | "gasLimit": "50,000,000", 31 | "gasPrice": "0" 32 | }, 33 | "expect": { 34 | "out": [ 35 | "3" 36 | ], 37 | "status": "", 38 | "logs": "*", 39 | "gas": "*", 40 | "refund": "*" 41 | } 42 | } 43 | ] 44 | } 45 | -------------------------------------------------------------------------------- /vmhost/hostCore/breakpoints.go: -------------------------------------------------------------------------------- 1 | package hostCore 2 | 3 | import ( 4 | "github.com/multiversx/mx-chain-vm-go/vmhost" 5 | ) 6 | 7 | func (host *vmHost) handleBreakpointIfAny(executionErr error) error { 8 | if executionErr == nil { 9 | return nil 10 | } 11 | 12 | runtime := host.Runtime() 13 | breakpointValue := runtime.GetRuntimeBreakpointValue() 14 | log.Trace("handleBreakpointIfAny", "value", breakpointValue) 15 | if breakpointValue != vmhost.BreakpointNone { 16 | err := host.handleBreakpoint(breakpointValue) 17 | runtime.AddError(err, runtime.FunctionName()) 18 | return err 19 | } 20 | 21 | log.Trace("wasmer execution error", "err", executionErr) 22 | runtime.AddError(executionErr, runtime.FunctionName()) 23 | return vmhost.ErrExecutionFailed 24 | } 25 | 26 | func (host *vmHost) handleBreakpoint(breakpointValue vmhost.BreakpointValue) error { 27 | if breakpointValue == vmhost.BreakpointAsyncCall { 28 | return host.handleAsyncCallBreakpoint() 29 | } 30 | if breakpointValue == vmhost.BreakpointExecutionFailed { 31 | return vmhost.ErrExecutionFailed 32 | } 33 | if breakpointValue == vmhost.BreakpointSignalError { 34 | return vmhost.ErrSignalError 35 | } 36 | if breakpointValue == vmhost.BreakpointOutOfGas { 37 | return vmhost.ErrNotEnoughGas 38 | } 39 | if breakpointValue == vmhost.BreakpointMemoryLimit { 40 | return vmhost.ErrMemoryLimit 41 | } 42 | 43 | return vmhost.ErrUnhandledRuntimeBreakpoint 44 | } 45 | -------------------------------------------------------------------------------- /test/features/basic-features-ei-1-3/scenarios/count_ones.scen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "count ones", 3 | "comment": "should fail if the processor doesn't support the `count ones` instruction", 4 | "gasSchedule": "v3", 5 | "steps": [ 6 | { 7 | "step": "setState", 8 | "accounts": { 9 | "sc:basic-features": { 10 | "nonce": "0", 11 | "balance": "0", 12 | "code": "mxsc:../output/basic-features.mxsc.json" 13 | }, 14 | "address:an_account": { 15 | "nonce": "0", 16 | "balance": "0" 17 | } 18 | } 19 | }, 20 | { 21 | "step": "scCall", 22 | "id": "1", 23 | "tx": { 24 | "from": "address:an_account", 25 | "to": "sc:basic-features", 26 | "function": "count_ones", 27 | "arguments": [ 28 | "0b010110" 29 | ], 30 | "gasLimit": "50,000,000", 31 | "gasPrice": "0" 32 | }, 33 | "expect": { 34 | "out": [ 35 | "3" 36 | ], 37 | "status": "", 38 | "logs": "*", 39 | "gas": "*", 40 | "refund": "*" 41 | } 42 | } 43 | ] 44 | } 45 | -------------------------------------------------------------------------------- /test/features/basic-features-ei-1-3/scenarios/storage_i64_bad.scen.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "storage", 3 | "gasSchedule": "v3", 4 | "steps": [ 5 | { 6 | "step": "setState", 7 | "accounts": { 8 | "sc:basic-features": { 9 | "nonce": "0", 10 | "balance": "0", 11 | "storage": { 12 | "str:i64": "0x008000000000000000" 13 | }, 14 | "code": "mxsc:../output/basic-features.mxsc.json" 15 | }, 16 | "address:an_account": { 17 | "nonce": "0", 18 | "balance": "0" 19 | } 20 | } 21 | }, 22 | { 23 | "step": "scCall", 24 | "id": "load-val", 25 | "tx": { 26 | "from": "address:an_account", 27 | "to": "sc:basic-features", 28 | "function": "load_i64", 29 | "arguments": [], 30 | "gasLimit": "50,000,000", 31 | "gasPrice": "0" 32 | }, 33 | "expect": { 34 | "out": [], 35 | "status": "*", 36 | "message": "str:storage decode error: input too long", 37 | "logs": "*", 38 | "gas": "*", 39 | "refund": "*" 40 | } 41 | } 42 | ] 43 | } 44 | --------------------------------------------------------------------------------