-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #477 from crytic/fix/compile-libraries-validation
Allow 20 byte address for --compile-libraries and raise error if argument is invalid
- Loading branch information
Showing
3 changed files
with
75 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
library NeedsLinkingA { | ||
function testA() external pure returns (uint) { | ||
return type(uint).max; | ||
} | ||
} | ||
library NeedsLinkingB { | ||
function testB() external pure returns (uint) { | ||
return type(uint).min; | ||
} | ||
} | ||
contract TestLibraryLinking { | ||
function test() external { | ||
NeedsLinkingA.testA(); | ||
NeedsLinkingB.testB(); | ||
} | ||
} |
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,54 @@ | ||
""" | ||
Test library linking | ||
""" | ||
import re | ||
from pathlib import Path | ||
import pytest | ||
from crytic_compile.crytic_compile import CryticCompile | ||
|
||
TEST_DIR = Path(__file__).resolve().parent | ||
|
||
LIBRARY_PLACEHOLDER_REGEX = r"__.{36}__" | ||
|
||
|
||
def test_library_linking() -> None: | ||
"""Test that the placeholder is not present in the bytecode when the libraries are provided""" | ||
cc = CryticCompile( | ||
Path(TEST_DIR / "library_linking.sol").as_posix(), | ||
compile_libraries="(NeedsLinkingA, 0xdead),(NeedsLinkingB, 0x000000000000000000000000000000000000beef)", | ||
) | ||
for compilation_unit in cc.compilation_units.values(): | ||
for source_unit in compilation_unit.source_units.values(): | ||
assert ( | ||
len(re.findall(r"__.{36}__", source_unit.bytecode_init("TestLibraryLinking"))) == 2 | ||
) | ||
assert ( | ||
len(re.findall(r"__.{36}__", source_unit.bytecode_runtime("TestLibraryLinking"))) | ||
== 2 | ||
) | ||
libraries = compilation_unit.crytic_compile.libraries | ||
assert ( | ||
len( | ||
re.findall( | ||
r"__.{36}__", source_unit.bytecode_init("TestLibraryLinking", libraries) | ||
) | ||
) | ||
== 0 | ||
) | ||
assert ( | ||
len( | ||
re.findall( | ||
r"__.{36}__", source_unit.bytecode_runtime("TestLibraryLinking", libraries) | ||
) | ||
) | ||
== 0 | ||
) | ||
|
||
|
||
def test_library_linking_validation() -> None: | ||
"""Test that invalid compile libraries argument raises an error""" | ||
with pytest.raises(ValueError): | ||
CryticCompile( | ||
Path(TEST_DIR / "library_linking.sol").as_posix(), | ||
compile_libraries="(NeedsLinkingA, 0x)", | ||
) |