def test_concrete_calldata_calldatasize(): # Arrange calldata = ConcreteCalldata(0, [1, 4, 7, 3, 7, 2, 9]) solver = Solver() # Act solver.check() model = solver.model() result = model.eval(calldata.calldatasize.raw) # Assert assert result == 7
def test_as_long(): # Arrange solver = Solver() x = symbol_factory.BitVecSym("x", 256) expression = x == symbol_factory.BitVecVal(2, 256) # Act solver.add(expression) result = solver.check() model = solver.model() x_concrete = model.eval(x.raw).as_long() # Assert assert z3.sat == result assert 2 == x_concrete
def test_decls(): # Arrange solver = Solver() x = symbol_factory.BitVecSym("x", 256) expression = x == symbol_factory.BitVecVal(2, 256) # Act solver.add(expression) result = solver.check() model = solver.model() decls = model.decls() # Assert assert z3.sat == result assert x.raw.decl() in decls
def test_get_item(): # Arrange solver = Solver() x = symbol_factory.BitVecSym("x", 256) expression = x == symbol_factory.BitVecVal(2, 256) # Act solver.add(expression) result = solver.check() model = solver.model() x_concrete = model[x.raw.decl()] # Assert assert z3.sat == result assert 2 == x_concrete
def test_bitvecfunc_find_input(): # Arrange s = Solver() input1 = symbol_factory.BitVecSym("input1", 256) input2 = symbol_factory.BitVecSym("input2", 256) bvf1 = symbol_factory.BitVecFuncSym("bvf1", "sha3", 256, input_=input1) bvf2 = symbol_factory.BitVecFuncSym("bvf3", "sha3", 256, input_=input2) # Act s.add(input1 == symbol_factory.BitVecVal(1, 256)) s.add(bvf1 == bvf2) # Assert assert s.check() == z3.sat assert s.model()[input2.raw] == 1
def test_bitvecfunc_bitvecfuncval_comparison(): # Arrange s = Solver() input1 = symbol_factory.BitVecSym("input1", 256) input2 = symbol_factory.BitVecVal(1337, 256) bvf1 = symbol_factory.BitVecFuncSym("bvf1", "sha3", 256, input_=input1) bvf2 = symbol_factory.BitVecFuncVal(12345678910, "sha3", 256, input_=input2) # Act s.add(bvf1 == bvf2) # Assert assert s.check() == z3.sat assert s.model().eval(input2.raw) == 1337