示例#1
0
def test_staticness(input):
    # Arrange
    state = get_global_state()
    state.environment.static = True
    state.mstate.stack = []
    instruction = Instruction(input, dynamic_loader=None)

    # Act and Assert
    with pytest.raises(WriteProtection):
        instruction.evaluate(state)
示例#2
0
def test_staticcall(f1):
    # Arrange
    state = get_global_state()
    state.mstate.stack = [10, 10, 10, 10, 10, 10, 10, 10, 0]
    instruction = Instruction("staticcall", dynamic_loader=None)

    # Act and Assert
    with pytest.raises(TransactionStartSignal) as ts:
        instruction.evaluate(state)
    assert ts.value.transaction.static
    assert ts.value.transaction.initial_global_state().environment.static
示例#3
0
def test_staticness_call_symbolic(f1):
    # Arrange
    state = get_global_state()
    state.environment.static = True
    state.mstate.stack = []
    call_value = symbol_factory.BitVecSym("x", 256)
    code = Disassembly(code="616263")
    f1.return_value = ("0", Account(code=code,
                                    address="0x19"), 0, call_value, 0, 0, 0)
    instruction = Instruction("call", dynamic_loader=None)

    # Act and Assert
    with pytest.raises(TransactionStartSignal) as ts:
        instruction.evaluate(state)

    assert ts.value.transaction.static
    assert ts.value.global_state.mstate.constraints[-1] == (call_value == 0)
示例#4
0
def test_staticness_call_concrete(f1, input, success):
    # Arrange
    state = get_global_state()
    state.environment.static = True
    state.mstate.stack = []
    code = Disassembly(code="616263")
    f1.return_value = ("0", Account(code=code,
                                    address="0x19"), 0, input, 0, 0, 0)
    instruction = Instruction("call", dynamic_loader=None)

    # Act and Assert
    if success:
        with pytest.raises(TransactionStartSignal) as ts:
            instruction.evaluate(state)
        assert ts.value.transaction.static
    else:
        with pytest.raises(WriteProtection):
            instruction.evaluate(state)
示例#5
0
def test_concrete_shr(val1, val2, expected):
    state = get_state()
    state.mstate.stack = [BVV(int(val1, 16), 256), BVV(int(val2, 16), 256)]
    expected = BVV(int(expected, 16), 256)
    instruction = Instruction("shr", dynamic_loader=None)

    # Act
    new_state = instruction.evaluate(state)[0]

    # Assert
    assert simplify(new_state.mstate.stack[-1]) == expected
示例#6
0
def test_shr(inputs, output):
    # Arrange
    state = get_state()

    state.mstate.stack = inputs
    instruction = Instruction("shr", dynamic_loader=None)

    # Act
    new_state = instruction.evaluate(state)[0]

    # Assert
    assert simplify(new_state.mstate.stack[-1]) == output
示例#7
0
def test_codecopy_concrete():
    # Arrange
    active_account = Account("0x0", code=Disassembly("60606040"))
    environment = Environment(active_account, None, None, None, None, None)
    og_state = GlobalState(None, environment, None, MachineState(gas=10000000))

    og_state.mstate.stack = [2, 2, 2]
    instruction = Instruction("codecopy", dynamic_loader=None)

    # Act
    new_state = instruction.evaluate(og_state)[0]

    # Assert
    assert new_state.mstate.memory[2] == 96
    assert new_state.mstate.memory[3] == 64
def test_codecopy_concrete():
    # Arrange
    active_account = Account("0x0", code=Disassembly("60606040"))
    environment = Environment(active_account, None, None, None, None, None)
    og_state = GlobalState(None, environment, None,
                           MachineState(gas_limit=8000000))
    og_state.transaction_stack.append(
        (MessageCallTransaction(world_state=WorldState(),
                                gas_limit=8000000), None))

    og_state.mstate.stack = [2, 2, 2]
    instruction = Instruction("codecopy", dynamic_loader=None)

    # Act
    new_state = instruction.evaluate(og_state)[0]

    # Assert
    assert new_state.mstate.memory[2] == 96
    assert new_state.mstate.memory[3] == 64
示例#9
0
def test_extcodecopy_fail():
    # Arrange
    new_world_state = WorldState()
    new_account = new_world_state.create_account(balance=10, address=101)
    new_account.code = Disassembly("60616240")
    new_environment = Environment(new_account, None, None, None, None, None)
    state = GlobalState(
        new_world_state, new_environment, None, MachineState(gas_limit=8000000)
    )
    state.transaction_stack.append(
        (MessageCallTransaction(world_state=WorldState(), gas_limit=8000000), None)
    )

    state.mstate.stack = [2, 2, 2, symbol_factory.BitVecSym("FAIL", 256)]
    instruction = Instruction("extcodecopy", dynamic_loader=None)

    # Act
    new_state = instruction.evaluate(state)[0]

    # Assert
    assert new_state.mstate.stack == []
    assert new_state.mstate.memory._memory == state.mstate.memory._memory
示例#10
0
def test_extcodecopy():
    # Arrange
    new_world_state = WorldState()
    new_account = new_world_state.create_account(balance=10, address=101)
    new_account.code = Disassembly("60616240")
    ext_account = new_world_state.create_account(balance=1000, address=121)
    ext_account.code = Disassembly("6040404040")

    new_environment = Environment(new_account, None, None, None, None, None)
    state = GlobalState(
        new_world_state, new_environment, None, MachineState(gas_limit=8000000)
    )
    state.transaction_stack.append(
        (MessageCallTransaction(world_state=WorldState(), gas_limit=8000000), None)
    )

    state.mstate.stack = [3, 0, 0, 121]
    instruction = Instruction("extcodecopy", dynamic_loader=None)

    # Act
    new_state = instruction.evaluate(state)[0]
    # Assert
    assert new_state.mstate.memory[0:3] == [96, 64, 64]