-
-
Notifications
You must be signed in to change notification settings - Fork 812
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat[venom]: add effects to instructions (#4264)
this commit adds an `effects.py` file to venom, which describes the effects of opcodes. this is useful for several ongoing efforts, including CSE elimination and DFT pass improvements. --------- Co-authored-by: Harry Kalogirou <harkal@nlogn.eu> Co-authored-by: HodanPlodky <36966616+HodanPlodky@users.noreply.github.com>
- Loading branch information
1 parent
ebe3c0c
commit 02f8654
Showing
2 changed files
with
92 additions
and
0 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,85 @@ | ||
from enum import Flag, auto | ||
|
||
|
||
class Effects(Flag): | ||
STORAGE = auto() | ||
TRANSIENT = auto() | ||
MEMORY = auto() | ||
MSIZE = auto() | ||
IMMUTABLES = auto() | ||
RETURNDATA = auto() | ||
LOG = auto() | ||
BALANCE = auto() | ||
EXTCODE = auto() | ||
|
||
|
||
EMPTY = Effects(0) | ||
ALL = ~EMPTY | ||
STORAGE = Effects.STORAGE | ||
TRANSIENT = Effects.TRANSIENT | ||
MEMORY = Effects.MEMORY | ||
MSIZE = Effects.MSIZE | ||
IMMUTABLES = Effects.IMMUTABLES | ||
RETURNDATA = Effects.RETURNDATA | ||
LOG = Effects.LOG | ||
BALANCE = Effects.BALANCE | ||
EXTCODE = Effects.EXTCODE | ||
|
||
|
||
_writes = { | ||
"sstore": STORAGE, | ||
"tstore": TRANSIENT, | ||
"mstore": MEMORY, | ||
"istore": IMMUTABLES, | ||
"call": ALL ^ IMMUTABLES, | ||
"delegatecall": ALL ^ IMMUTABLES, | ||
"staticcall": MEMORY | RETURNDATA, | ||
"create": ALL ^ (MEMORY | IMMUTABLES), | ||
"create2": ALL ^ (MEMORY | IMMUTABLES), | ||
"invoke": ALL, # could be smarter, look up the effects of the invoked function | ||
"log": LOG, | ||
"dloadbytes": MEMORY, | ||
"returndatacopy": MEMORY, | ||
"calldatacopy": MEMORY, | ||
"codecopy": MEMORY, | ||
"extcodecopy": MEMORY, | ||
"mcopy": MEMORY, | ||
} | ||
|
||
_reads = { | ||
"sload": STORAGE, | ||
"tload": TRANSIENT, | ||
"iload": IMMUTABLES, | ||
"mload": MEMORY, | ||
"mcopy": MEMORY, | ||
"call": ALL, | ||
"delegatecall": ALL, | ||
"staticcall": ALL, | ||
"create": ALL, | ||
"create2": ALL, | ||
"invoke": ALL, | ||
"returndatasize": RETURNDATA, | ||
"returndatacopy": RETURNDATA, | ||
"balance": BALANCE, | ||
"selfbalance": BALANCE, | ||
"extcodecopy": EXTCODE, | ||
"selfdestruct": BALANCE, # may modify code, but after the transaction | ||
"log": MEMORY, | ||
"revert": MEMORY, | ||
"return": MEMORY, | ||
"sha3": MEMORY, | ||
"msize": MSIZE, | ||
} | ||
|
||
reads = _reads.copy() | ||
writes = _writes.copy() | ||
|
||
for k, v in reads.items(): | ||
if MEMORY in v: | ||
if k not in writes: | ||
writes[k] = EMPTY | ||
writes[k] |= MSIZE | ||
|
||
for k, v in writes.items(): | ||
if MEMORY in v: | ||
writes[k] |= MSIZE |