@@ -120,6 +120,7 @@ type statefulPrecompileOutput struct {
120
120
func (o statefulPrecompileOutput ) String () string {
121
121
var lines []string
122
122
out := reflect .ValueOf (o )
123
+ FieldLoop:
123
124
for i , n := 0 , out .NumField (); i < n ; i ++ {
124
125
name := out .Type ().Field (i ).Name
125
126
fld := out .Field (i ).Interface ()
@@ -129,7 +130,12 @@ func (o statefulPrecompileOutput) String() string {
129
130
case []byte :
130
131
verb = "%#x"
131
132
case * libevm.AddressContext :
132
- verb = "%+v"
133
+ lines = append (
134
+ lines ,
135
+ fmt .Sprintf ("EVMSemantic addresses: %+v" , o .Addresses .EVMSemantic ),
136
+ fmt .Sprintf ("Raw addresses: %+v" , o .Addresses .Raw ),
137
+ )
138
+ continue FieldLoop
133
139
case vm.CallType :
134
140
verb = "%d (%[2]q)"
135
141
}
@@ -211,6 +217,13 @@ func TestNewStatefulPrecompile(t *testing.T) {
211
217
state .SetBalance (caller , new (uint256.Int ).Not (uint256 .NewInt (0 )))
212
218
evm .Origin = eoa
213
219
220
+ // By definition, the raw caller and self are the same, regardless of the
221
+ // incoming call type.
222
+ rawAddresses := & libevm.CallerAndSelf {
223
+ Caller : caller ,
224
+ Self : precompile ,
225
+ }
226
+
214
227
tests := []struct {
215
228
name string
216
229
call func () ([]byte , uint64 , error )
@@ -232,6 +245,7 @@ func TestNewStatefulPrecompile(t *testing.T) {
232
245
Caller : caller ,
233
246
Self : precompile ,
234
247
},
248
+ Raw : rawAddresses ,
235
249
},
236
250
wantReadOnly : false ,
237
251
wantTransferValue : transferValue ,
@@ -248,6 +262,7 @@ func TestNewStatefulPrecompile(t *testing.T) {
248
262
Caller : caller ,
249
263
Self : caller ,
250
264
},
265
+ Raw : rawAddresses ,
251
266
},
252
267
wantReadOnly : false ,
253
268
wantTransferValue : transferValue ,
@@ -264,6 +279,7 @@ func TestNewStatefulPrecompile(t *testing.T) {
264
279
Caller : eoa , // inherited from caller
265
280
Self : caller ,
266
281
},
282
+ Raw : rawAddresses ,
267
283
},
268
284
wantReadOnly : false ,
269
285
wantTransferValue : uint256 .NewInt (0 ),
@@ -280,6 +296,7 @@ func TestNewStatefulPrecompile(t *testing.T) {
280
296
Caller : caller ,
281
297
Self : precompile ,
282
298
},
299
+ Raw : rawAddresses ,
283
300
},
284
301
wantReadOnly : true ,
285
302
wantTransferValue : uint256 .NewInt (0 ),
@@ -570,6 +587,7 @@ func TestCanCreateContract(t *testing.T) {
570
587
Caller : caller ,
571
588
Self : create ,
572
589
},
590
+ // `Raw` is documented as always being nil.
573
591
},
574
592
value ,
575
593
),
@@ -586,6 +604,7 @@ func TestCanCreateContract(t *testing.T) {
586
604
Caller : caller ,
587
605
Self : create2 ,
588
606
},
607
+ // As above re `Raw` always being nil.
589
608
},
590
609
value ,
591
610
),
@@ -656,7 +675,10 @@ func TestPrecompileMakeCall(t *testing.T) {
656
675
if bytes .Equal (input , unsafeCallerProxyOptSentinel ) {
657
676
opts = append (opts , vm .WithUNSAFECallerAddressProxying ())
658
677
}
659
- // We are ultimately testing env.Call(), hence why this is the SUT.
678
+ // We are ultimately testing env.Call(), hence why this is the
679
+ // SUT. If this is ever extended to include DELEGATECALL or
680
+ // CALLCODE then the expected [libevm.AddressContext.Raw] values
681
+ // of the tests cases also need to change.
660
682
return env .Call (dest , precompileCallData , env .Gas (), uint256 .NewInt (0 ), opts ... )
661
683
}),
662
684
dest : vm .NewStatefulPrecompile (func (env vm.PrecompileEnvironment , input []byte ) (ret []byte , err error ) {
@@ -802,6 +824,9 @@ func TestPrecompileMakeCall(t *testing.T) {
802
824
803
825
for _ , tt := range tests {
804
826
t .Run (tt .incomingCallType .String (), func (t * testing.T ) {
827
+ // From the perspective of `dest` after a CALL.
828
+ tt .want .Addresses .Raw = & tt .want .Addresses .EVMSemantic
829
+
805
830
t .Logf ("calldata = %q" , tt .eoaTxCallData )
806
831
state , evm := ethtest .NewZeroEVM (t )
807
832
evm .Origin = eoa
0 commit comments