core/vm: Rename + updated doc on jumpdest analysis

This commit is contained in:
Martin Holst Swende 2017-09-08 12:47:44 +02:00
parent 54b1de67e2
commit d6681ed360
2 changed files with 5 additions and 5 deletions

@ -38,7 +38,7 @@ func (d destinations) has(codehash common.Hash, code []byte, dest *big.Int) bool
m, analysed := d[codehash] m, analysed := d[codehash]
if !analysed { if !analysed {
m = jumpdests(code) m = codeBitmap(code)
d[codehash] = m d[codehash] = m
} }
return OpCode(code[udest]) == JUMPDEST && m.codeSegment(udest) return OpCode(code[udest]) == JUMPDEST && m.codeSegment(udest)
@ -61,9 +61,9 @@ func (bits *bitvec) codeSegment(pos uint64) bool {
return ((*bits)[pos/8] & (0x80 >> (pos % 8))) == 0 return ((*bits)[pos/8] & (0x80 >> (pos % 8))) == 0
} }
// jumpdests creates a map that contains an entry for each // jumpdests creates a bitmap of the code, where 1 represents a DATA-segment,
// PC location that is a JUMPDEST instruction. // and 0 represents code-segment
func jumpdests(code []byte) []byte { func codeBitmap(code []byte) []byte {
//The map is 4 bytes longer than necessary, in case the code //The map is 4 bytes longer than necessary, in case the code
// ends with a PUSH32, the algorithm will push zeroes onto the // ends with a PUSH32, the algorithm will push zeroes onto the
// bitvector outside the bounds of the actual code. // bitvector outside the bounds of the actual code.

@ -28,7 +28,7 @@ func TestJumpDestAnalysis(t *testing.T) {
{[]byte{byte(PUSH32)}, 0xFF, 2}, {[]byte{byte(PUSH32)}, 0xFF, 2},
} }
for _, test := range tests { for _, test := range tests {
ret := jumpdests(test.code) ret := codeBitmap(test.code)
if ret[test.which] != test.exp { if ret[test.which] != test.exp {
t.Fatalf("expected %x, got %02x", test.exp, ret[test.which]) t.Fatalf("expected %x, got %02x", test.exp, ret[test.which])
} }