@@ -23,7 +23,7 @@ import (
23
23
)
24
24
25
25
// Contract represents an ethereum contract in the state database. It contains
26
- // the contract code, calling arguments. Contract implements ContractRef
26
+ // the contract code, calling arguments.
27
27
type Contract struct {
28
28
// caller is the result of the caller which initialised this
29
29
// contract. However, when the "call method" is delegated this
@@ -44,6 +44,8 @@ type Contract struct {
44
44
45
45
Gas uint64
46
46
value * uint256.Int
47
+
48
+ isPrecompile bool
47
49
}
48
50
49
51
// NewContract returns a new contract environment for the execution of EVM.
@@ -61,7 +63,30 @@ func NewContract(caller common.Address, address common.Address, value *uint256.I
61
63
}
62
64
}
63
65
66
+ // NewPrecompile returns a new instance of a precompiled contract environment for the execution of EVM.
67
+ func NewPrecompile (caller common.Address , address common.Address , value * uint256.Int , gas uint64 ) * Contract {
68
+ c := & Contract {
69
+ caller : caller ,
70
+ address : address ,
71
+ isPrecompile : true ,
72
+ }
73
+
74
+ c .Gas = gas
75
+ c .value = value
76
+
77
+ return c
78
+ }
79
+
80
+ // IsPrecompile returns true if the contract is a precompiled contract environment
81
+ func (c Contract ) IsPrecompile () bool {
82
+ return c .isPrecompile
83
+ }
84
+
64
85
func (c * Contract ) validJumpdest (dest * uint256.Int ) bool {
86
+ if c .isPrecompile {
87
+ return false
88
+ }
89
+
65
90
udest , overflow := dest .Uint64WithOverflow ()
66
91
// PC cannot go beyond len(code) and certainly can't be bigger than 63bits.
67
92
// Don't bother checking for JUMPDEST in that case.
@@ -78,6 +103,10 @@ func (c *Contract) validJumpdest(dest *uint256.Int) bool {
78
103
// isCode returns true if the provided PC location is an actual opcode, as
79
104
// opposed to a data-segment following a PUSHN operation.
80
105
func (c * Contract ) isCode (udest uint64 ) bool {
106
+ if c .isPrecompile {
107
+ return false
108
+ }
109
+
81
110
// Do we already have an analysis laying around?
82
111
if c .analysis != nil {
83
112
return c .analysis .codeSegment (udest )
0 commit comments