Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions crytic_compile/platform/vyper.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,11 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
].replace("0x", "")
# Vyper does not provide the source mapping for the init bytecode
source_unit.srcmaps_init[contract_name] = []
source_unit.srcmaps_runtime[contract_name] = contract_metadata["evm"][
"deployedBytecode"
]["sourceMap"].split(";")
srcmap_runtime = contract_metadata["evm"]["deployedBytecode"]["sourceMap"]
# vyper >= 0.4 returns an object; the solc-style string is `pc_pos_map_compressed`
if isinstance(srcmap_runtime, dict):
srcmap_runtime = srcmap_runtime["pc_pos_map_compressed"]
source_unit.srcmaps_runtime[contract_name] = srcmap_runtime.split(";")
source_unit.bytecodes_runtime[contract_name] = contract_metadata["evm"][
"deployedBytecode"
]["object"].replace("0x", "")
Expand Down
42 changes: 42 additions & 0 deletions tests/test_vyper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""Tests for the vyper platform."""

import crytic_compile.platform.vyper as vyper_platform
from crytic_compile import CryticCompile

_VYPER_04_ARTIFACTS = {
"compiler": "vyper-0.4.3",
"contracts": {
"t.vy": {
"t": {
"abi": [],
"userdoc": {},
"devdoc": {},
"evm": {
"bytecode": {"object": "0x6000"},
"deployedBytecode": {
"object": "0x6000",
"sourceMap": {
"pc_pos_map_compressed": "0:152:0:-;-1:-1:-1",
"pc_pos_map": {},
"pc_jump_map": {},
},
},
},
}
}
},
"sources": {"t.vy": {"ast": {}, "id": 0}},
}


def test_object_source_map_from_vyper_04(tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)
target = tmp_path / "t.vy"
target.write_text("x: public(uint256)\n", encoding="utf-8")
monkeypatch.setattr(
vyper_platform, "_run_vyper_standard_json", lambda *a, **k: _VYPER_04_ARTIFACTS
)
cc = CryticCompile("t.vy")
(unit,) = cc.compilation_units.values()
(source_unit,) = unit.source_units.values()
assert source_unit.srcmaps_runtime["t"] == ["0:152:0:-", "-1:-1:-1"]