@@ -228,8 +228,10 @@ func TestNewStatefulPrecompile(t *testing.T) {
228228 },
229229 wantAddresses : & libevm.AddressContext {
230230 Origin : eoa ,
231- Caller : caller ,
232- Self : precompile ,
231+ EVMSemantic : libevm.CallerAndSelf {
232+ Caller : caller ,
233+ Self : precompile ,
234+ },
233235 },
234236 wantReadOnly : false ,
235237 wantTransferValue : transferValue ,
@@ -242,8 +244,10 @@ func TestNewStatefulPrecompile(t *testing.T) {
242244 },
243245 wantAddresses : & libevm.AddressContext {
244246 Origin : eoa ,
245- Caller : caller ,
246- Self : caller ,
247+ EVMSemantic : libevm.CallerAndSelf {
248+ Caller : caller ,
249+ Self : caller ,
250+ },
247251 },
248252 wantReadOnly : false ,
249253 wantTransferValue : transferValue ,
@@ -256,8 +260,10 @@ func TestNewStatefulPrecompile(t *testing.T) {
256260 },
257261 wantAddresses : & libevm.AddressContext {
258262 Origin : eoa ,
259- Caller : eoa , // inherited from caller
260- Self : caller ,
263+ EVMSemantic : libevm.CallerAndSelf {
264+ Caller : eoa , // inherited from caller
265+ Self : caller ,
266+ },
261267 },
262268 wantReadOnly : false ,
263269 wantTransferValue : uint256 .NewInt (0 ),
@@ -270,8 +276,10 @@ func TestNewStatefulPrecompile(t *testing.T) {
270276 },
271277 wantAddresses : & libevm.AddressContext {
272278 Origin : eoa ,
273- Caller : caller ,
274- Self : precompile ,
279+ EVMSemantic : libevm.CallerAndSelf {
280+ Caller : caller ,
281+ Self : precompile ,
282+ },
275283 },
276284 wantReadOnly : true ,
277285 wantTransferValue : uint256 .NewInt (0 ),
@@ -527,7 +535,7 @@ func TestCanCreateContract(t *testing.T) {
527535 gasUsage := rng .Uint64n (gasLimit )
528536
529537 makeErr := func (cc * libevm.AddressContext , stateVal common.Hash ) error {
530- return fmt .Errorf ("Origin: %v Caller: %v Contract: %v State: %v" , cc .Origin , cc .Caller , cc .Self , stateVal )
538+ return fmt .Errorf ("Origin: %v Caller: %v Contract: %v State: %v" , cc .Origin , cc .EVMSemantic . Caller , cc . EVMSemantic .Self , stateVal )
531539 }
532540 hooks := & hookstest.Stub {
533541 CanCreateContractFn : func (cc * libevm.AddressContext , gas uint64 , s libevm.StateReader ) (uint64 , error ) {
@@ -555,14 +563,32 @@ func TestCanCreateContract(t *testing.T) {
555563 create : func (evm * vm.EVM ) ([]byte , common.Address , uint64 , error ) {
556564 return evm .Create (vm .AccountRef (caller ), code , gasLimit , uint256 .NewInt (0 ))
557565 },
558- wantErr : makeErr (& libevm.AddressContext {Origin : origin , Caller : caller , Self : create }, value ),
566+ wantErr : makeErr (
567+ & libevm.AddressContext {
568+ Origin : origin ,
569+ EVMSemantic : libevm.CallerAndSelf {
570+ Caller : caller ,
571+ Self : create ,
572+ },
573+ },
574+ value ,
575+ ),
559576 },
560577 {
561578 name : "Create2" ,
562579 create : func (evm * vm.EVM ) ([]byte , common.Address , uint64 , error ) {
563580 return evm .Create2 (vm .AccountRef (caller ), code , gasLimit , uint256 .NewInt (0 ), new (uint256.Int ).SetBytes (salt [:]))
564581 },
565- wantErr : makeErr (& libevm.AddressContext {Origin : origin , Caller : caller , Self : create2 }, value ),
582+ wantErr : makeErr (
583+ & libevm.AddressContext {
584+ Origin : origin ,
585+ EVMSemantic : libevm.CallerAndSelf {
586+ Caller : caller ,
587+ Self : create2 ,
588+ },
589+ },
590+ value ,
591+ ),
566592 },
567593 }
568594
@@ -663,8 +689,10 @@ func TestPrecompileMakeCall(t *testing.T) {
663689 want : statefulPrecompileOutput {
664690 Addresses : & libevm.AddressContext {
665691 Origin : eoa ,
666- Caller : sut ,
667- Self : dest ,
692+ EVMSemantic : libevm.CallerAndSelf {
693+ Caller : sut ,
694+ Self : dest ,
695+ },
668696 },
669697 Input : precompileCallData ,
670698 },
@@ -675,8 +703,10 @@ func TestPrecompileMakeCall(t *testing.T) {
675703 want : statefulPrecompileOutput {
676704 Addresses : & libevm.AddressContext {
677705 Origin : eoa ,
678- Caller : caller , // overridden by CallOption
679- Self : dest ,
706+ EVMSemantic : libevm.CallerAndSelf {
707+ Caller : caller , // overridden by CallOption
708+ Self : dest ,
709+ },
680710 },
681711 Input : precompileCallData ,
682712 },
@@ -686,8 +716,10 @@ func TestPrecompileMakeCall(t *testing.T) {
686716 want : statefulPrecompileOutput {
687717 Addresses : & libevm.AddressContext {
688718 Origin : eoa ,
689- Caller : caller , // SUT runs as its own caller because of CALLCODE
690- Self : dest ,
719+ EVMSemantic : libevm.CallerAndSelf {
720+ Caller : caller , // SUT runs as its own caller because of CALLCODE
721+ Self : dest ,
722+ },
691723 },
692724 Input : precompileCallData ,
693725 },
@@ -698,8 +730,10 @@ func TestPrecompileMakeCall(t *testing.T) {
698730 want : statefulPrecompileOutput {
699731 Addresses : & libevm.AddressContext {
700732 Origin : eoa ,
701- Caller : caller , // CallOption is a NOOP
702- Self : dest ,
733+ EVMSemantic : libevm.CallerAndSelf {
734+ Caller : caller , // CallOption is a NOOP
735+ Self : dest ,
736+ },
703737 },
704738 Input : precompileCallData ,
705739 },
@@ -709,8 +743,10 @@ func TestPrecompileMakeCall(t *testing.T) {
709743 want : statefulPrecompileOutput {
710744 Addresses : & libevm.AddressContext {
711745 Origin : eoa ,
712- Caller : caller , // as with CALLCODE
713- Self : dest ,
746+ EVMSemantic : libevm.CallerAndSelf {
747+ Caller : caller , // as with CALLCODE
748+ Self : dest ,
749+ },
714750 },
715751 Input : precompileCallData ,
716752 },
@@ -721,8 +757,10 @@ func TestPrecompileMakeCall(t *testing.T) {
721757 want : statefulPrecompileOutput {
722758 Addresses : & libevm.AddressContext {
723759 Origin : eoa ,
724- Caller : caller , // CallOption is a NOOP
725- Self : dest ,
760+ EVMSemantic : libevm.CallerAndSelf {
761+ Caller : caller , // CallOption is a NOOP
762+ Self : dest ,
763+ },
726764 },
727765 Input : precompileCallData ,
728766 },
@@ -732,8 +770,10 @@ func TestPrecompileMakeCall(t *testing.T) {
732770 want : statefulPrecompileOutput {
733771 Addresses : & libevm.AddressContext {
734772 Origin : eoa ,
735- Caller : sut ,
736- Self : dest ,
773+ EVMSemantic : libevm.CallerAndSelf {
774+ Caller : sut ,
775+ Self : dest ,
776+ },
737777 },
738778 Input : precompileCallData ,
739779 // This demonstrates that even though the precompile makes a
@@ -749,8 +789,10 @@ func TestPrecompileMakeCall(t *testing.T) {
749789 want : statefulPrecompileOutput {
750790 Addresses : & libevm.AddressContext {
751791 Origin : eoa ,
752- Caller : caller , // overridden by CallOption
753- Self : dest ,
792+ EVMSemantic : libevm.CallerAndSelf {
793+ Caller : caller , // overridden by CallOption
794+ Self : dest ,
795+ },
754796 },
755797 Input : precompileCallData ,
756798 ReadOnly : true ,
@@ -816,26 +858,3 @@ func TestPrecompileCallWithTracer(t *testing.T) {
816858 require .NoErrorf (t , json .Unmarshal (gotJSON , & got ), "json.Unmarshal(%T.GetResult(), %T)" , tracer , & got )
817859 require .Equal (t , value , got [contract ].Storage [zeroHash ], "value loaded with SLOAD" )
818860}
819-
820- //nolint:testableexamples // Including output would only make the example more complicated and hide the true intent
821- func ExamplePrecompileEnvironment () {
822- // To determine the actual caller of a precompile, as against the effective
823- // caller (under EVM rules, as exposed by `Addresses().Caller`):
824- actualCaller := func (env vm.PrecompileEnvironment ) common.Address {
825- if env .IncomingCallType () == vm .DelegateCall {
826- // DelegateCall acts as if it were its own caller.
827- return env .Addresses ().Self
828- }
829- // CallCode could return either `Self` or `Caller` as it acts as its
830- // caller but doesn't inherit the caller's caller as DelegateCall does.
831- // Having it handled here is arbitrary from a behavioural perspective
832- // and is done only to simplify the code.
833- //
834- // Call and StaticCall don't affect self/caller semantics in any way.
835- return env .Addresses ().Caller
836- }
837-
838- // actualCaller would typically be a top-level function. It's only a
839- // variable to include it in this example function.
840- _ = actualCaller
841- }
0 commit comments