-
Notifications
You must be signed in to change notification settings - Fork 473
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimise forking when there is only 1 solution (#2527)
* Optimise forking when there is only 1 solution * Update etherum test * Add test for forking on a unique solution * Replace strlen test with dedicated fork test * Fix typo * Fix output filename in test
- Loading branch information
1 parent
49f7ebc
commit 6212a7a
Showing
4 changed files
with
73 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import unittest | ||
import tempfile | ||
from manticore.native import Manticore | ||
from manticore.core.state import Concretize | ||
from pathlib import Path | ||
from glob import glob | ||
|
||
|
||
class TestFork(unittest.TestCase): | ||
def test_fork_unique_solution(self): | ||
binary = str( | ||
Path(__file__).parent.parent.parent.joinpath( | ||
"tests", "native", "binaries", "hello_world" | ||
) | ||
) | ||
tmp_dir = tempfile.TemporaryDirectory(prefix="mcore_test_fork_") | ||
m = Manticore(binary, stdin_size=10, workspace_url=str(tmp_dir.name)) | ||
|
||
@m.hook(0x3E50) # Entrypoint | ||
def concretize_var(state): | ||
# Concretize symbolic var that has only 1 solution | ||
var = BitVecVariable(size=32, name="bar") | ||
state.constrain(var == 5) | ||
raise Concretize(var) | ||
|
||
m.run() | ||
m.finalize() | ||
|
||
# Check that no additional state was created when forking | ||
states = f"{str(m.workspace)}/test_*.pkl" | ||
self.assertEqual(len(glob(states)), 1) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |