@@ -22,39 +22,20 @@ import (
22
22
"github.com/holiman/uint256"
23
23
)
24
24
25
- // ContractRef is a reference to the contract's backing object
26
- type ContractRef interface {
27
- Address () common.Address
28
- }
29
-
30
- // AccountRef implements ContractRef.
31
- //
32
- // Account references are used during EVM initialisation and
33
- // its primary use is to fetch addresses. Removing this object
34
- // proves difficult because of the cached jump destinations which
35
- // are fetched from the parent contract (i.e. the caller), which
36
- // is a ContractRef.
37
- type AccountRef common.Address
38
-
39
- // Address casts AccountRef to an Address
40
- func (ar AccountRef ) Address () common.Address { return (common .Address )(ar ) }
41
-
42
25
// Contract represents an ethereum contract in the state database. It contains
43
26
// the contract code, calling arguments. Contract implements ContractRef
44
27
type Contract struct {
45
- // CallerAddress is the result of the caller which initialised this
46
- // contract. However when the "call method" is delegated this value
47
- // needs to be initialised to that of the caller's caller.
48
- CallerAddress common.Address
49
- caller ContractRef
50
- self ContractRef
28
+ // caller is the result of the caller which initialised this
29
+ // contract. However, when the "call method" is delegated this
30
+ // value needs to be initialised to that of the caller's caller.
31
+ caller common.Address
32
+ address common.Address
51
33
52
34
jumpdests map [common.Hash ]bitvec // Aggregated result of JUMPDEST analysis.
53
35
analysis bitvec // Locally cached result of JUMPDEST analysis
54
36
55
37
Code []byte
56
38
CodeHash common.Hash
57
- CodeAddr * common.Address
58
39
Input []byte
59
40
60
41
// is the execution frame represented by this object a contract deployment
@@ -66,23 +47,18 @@ type Contract struct {
66
47
}
67
48
68
49
// NewContract returns a new contract environment for the execution of EVM.
69
- func NewContract (caller ContractRef , object ContractRef , value * uint256.Int , gas uint64 ) * Contract {
70
- c := & Contract {CallerAddress : caller .Address (), caller : caller , self : object }
71
-
72
- if parent , ok := caller .(* Contract ); ok {
73
- // Reuse JUMPDEST analysis from parent context if available.
74
- c .jumpdests = parent .jumpdests
75
- } else {
76
- c .jumpdests = make (map [common.Hash ]bitvec )
50
+ func NewContract (caller common.Address , address common.Address , value * uint256.Int , gas uint64 , jumpDests map [common.Hash ]bitvec ) * Contract {
51
+ // Initialize the jump analysis map if it's nil, mostly for tests
52
+ if jumpDests == nil {
53
+ jumpDests = make (map [common.Hash ]bitvec )
54
+ }
55
+ return & Contract {
56
+ caller : caller ,
57
+ address : address ,
58
+ jumpdests : jumpDests ,
59
+ Gas : gas ,
60
+ value : value ,
77
61
}
78
-
79
- // Gas should be a pointer so it can safely be reduced through the run
80
- // This pointer will be off the state transition
81
- c .Gas = gas
82
- // ensures a value is set
83
- c .value = value
84
-
85
- return c
86
62
}
87
63
88
64
func (c * Contract ) validJumpdest (dest * uint256.Int ) bool {
@@ -132,18 +108,6 @@ func (c *Contract) isCode(udest uint64) bool {
132
108
return c .analysis .codeSegment (udest )
133
109
}
134
110
135
- // AsDelegate sets the contract to be a delegate call and returns the current
136
- // contract (for chaining calls)
137
- func (c * Contract ) AsDelegate () * Contract {
138
- // NOTE: caller must, at all times be a contract. It should never happen
139
- // that caller is something other than a Contract.
140
- parent := c .caller .(* Contract )
141
- c .CallerAddress = parent .CallerAddress
142
- c .value = parent .value
143
-
144
- return c
145
- }
146
-
147
111
// GetOp returns the n'th element in the contract's byte array
148
112
func (c * Contract ) GetOp (n uint64 ) OpCode {
149
113
if n < uint64 (len (c .Code )) {
@@ -158,7 +122,7 @@ func (c *Contract) GetOp(n uint64) OpCode {
158
122
// Caller will recursively call caller when the contract is a delegate
159
123
// call, including that of caller's caller.
160
124
func (c * Contract ) Caller () common.Address {
161
- return c .CallerAddress
125
+ return c .caller
162
126
}
163
127
164
128
// UseGas attempts the use gas and subtracts it and returns true on success
@@ -186,26 +150,16 @@ func (c *Contract) RefundGas(gas uint64, logger *tracing.Hooks, reason tracing.G
186
150
187
151
// Address returns the contracts address
188
152
func (c * Contract ) Address () common.Address {
189
- return c .self . Address ()
153
+ return c .address
190
154
}
191
155
192
156
// Value returns the contract's value (sent to it from it's caller)
193
157
func (c * Contract ) Value () * uint256.Int {
194
158
return c .value
195
159
}
196
160
197
- // SetCallCode sets the code of the contract and address of the backing data
198
- // object
199
- func (c * Contract ) SetCallCode (addr * common.Address , hash common.Hash , code []byte ) {
161
+ // SetCallCode sets the code of the contract,
162
+ func (c * Contract ) SetCallCode (hash common.Hash , code []byte ) {
200
163
c .Code = code
201
164
c .CodeHash = hash
202
- c .CodeAddr = addr
203
- }
204
-
205
- // SetCodeOptionalHash can be used to provide code, but it's optional to provide hash.
206
- // In case hash is not provided, the jumpdest analysis will not be saved to the parent context
207
- func (c * Contract ) SetCodeOptionalHash (addr * common.Address , codeAndHash * codeAndHash ) {
208
- c .Code = codeAndHash .code
209
- c .CodeHash = codeAndHash .hash
210
- c .CodeAddr = addr
211
165
}
0 commit comments