vm.push(imm_opcode_val)
    vm.pushinsnimm()
    vm.halt()
    vm.set_label(arb.ast.AVMLabel("base_error_handler"))
    vm.push(arb.value.ERROR_CODE_POINT)
    vm.errset()
    vm.error()


tests = [
    ["opcodetestmath", test_arithmetic],
    ["opcodetestlogic", test_logic],
    ["opcodetesthash", test_hash, 4],
    ["opcodetestethhash2", test_ethhash2],
    ["opcodeteststack", test_stack],
    ["opcodetestdup", test_dup],
    ["opcodetesttuple", test_tuple],
    ["opcodetestarbgas", test_arbgas],
    ["opcodetestecrecover", test_ecrecover],
    ["opcodetestcode", test_code],
]

for vm_test in tests:
    code = arb.compile_block(vm_test[1])
    vm = arb.compile_program(arb.ast.BlockStatement([]), code)
    if len(vm_test) > 2:
        vm.static = vm_test[2]
    with open("../arb-avm-cpp/tests/machine-cases/" + vm_test[0] + ".mexe",
              "w") as f:
        json.dump(arb.marshall.marshall_vm_json(vm), f)
示例#2
0
def makeAoFile(func, filepath):
    code = arb.compile_block(func)
    vm = arb.compile_program(arb.ast.BlockStatement([]), code)
    vm.static = 4
    with open(filepath, "wb") as f:
        arb.marshall.marshall_vm(vm, f)
示例#3
0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import arbitrum as arb


def test(vm):
    for i in range(10000):
        vm.push(i)
    for _ in range(9999):
        vm.add()
    vm.push(5)
    vm.push(arb.value.Tuple([1, 2, 3, 4]))
    vm.tsetn(1)
    vm.tgetn(3)
    vm.halt()


code = arb.compile_block(test)
vm = arb.compile_program(arb.ast.BlockStatement([]), code)
# print(vm.code)
with open("test.ao", "wb") as f:
    arb.marshall.marshall_vm(vm, f)

# vm2 = arb.VM()
# test(vm2)
# print(vm2.stack[:])
示例#4
0
    vm.gettime()
    # INBOX
    # TODO add inbox test
    # ERROR
    # TODO add error test
    # HALT
    # TODO add halt test
    #
    vm.halt()
    vm.set_label(arb.ast.AVMLabel("base_error_handler"))
    vm.push(arb.value.AVMCodePoint(0, 0, b"\0" * 32))
    vm.errset()
    vm.error()


code = arb.compile_block(test_arithmetic)
vm = arb.compile_program(arb.ast.BlockStatement([]), code)
vm.static = 4
print("math ", len(vm.code), " codepoints")
# print(vm.code)
with open("../arb-validator/proofmachine/opcodetestmath.ao", "wb") as f:
    arb.marshall.marshall_vm(vm, f)
code = arb.compile_block(test_logic)
vm = arb.compile_program(arb.ast.BlockStatement([]), code)
vm.static = 4
print("logic ", len(vm.code), " codepoints")
with open("../arb-validator/proofmachine/opcodetestlogic.ao", "wb") as f:
    arb.marshall.marshall_vm(vm, f)
code = arb.compile_block(test_hash)
vm = arb.compile_program(arb.ast.BlockStatement([]), code)
vm.static = 4