@@ -108,7 +108,7 @@ type statefulPrecompileOutput struct {
108108 Addresses * libevm.AddressContext
109109 StateValue common.Hash
110110 ValueReceived * uint256.Int
111- ReadOnly bool
111+ Mutability vm. StateMutability
112112 BlockNumber , Difficulty * big.Int
113113 BlockTime uint64
114114 Input []byte
@@ -149,8 +149,8 @@ func TestNewStatefulPrecompile(t *testing.T) {
149149 gasCost := rng .Uint64n (gasLimit )
150150
151151 run := func (env vm.PrecompileEnvironment , input []byte , suppliedGas uint64 ) ([]byte , uint64 , error ) {
152- if got , want := env .StateDB () != nil , ! env .ReadOnly () ; got != want {
153- return nil , 0 , fmt .Errorf ("PrecompileEnvironment().StateDB() must be non-nil i.f.f. not read-only ; got non-nil? %t; want %t" , got , want )
152+ if got , want := env .StateDB () != nil , env .StateMutability () == vm . MutableState ; got != want {
153+ return nil , 0 , fmt .Errorf ("PrecompileEnvironment().StateDB() must be non-nil i.f.f. state is mutable ; got non-nil? %t; want %t" , got , want )
154154 }
155155 hdr , err := env .BlockHeader ()
156156 if err != nil {
@@ -162,7 +162,7 @@ func TestNewStatefulPrecompile(t *testing.T) {
162162 Addresses : env .Addresses (),
163163 StateValue : env .ReadOnlyState ().GetState (precompile , slot ),
164164 ValueReceived : env .Value (),
165- ReadOnly : env .ReadOnly (),
165+ Mutability : env .StateMutability (),
166166 BlockNumber : env .BlockNumber (),
167167 BlockTime : env .BlockTime (),
168168 Difficulty : hdr .Difficulty ,
@@ -216,8 +216,8 @@ func TestNewStatefulPrecompile(t *testing.T) {
216216 wantTransferValue * uint256.Int
217217 // Note that this only covers evm.readOnly being true because of the
218218 // precompile's call. See TestInheritReadOnly for alternate case.
219- wantReadOnly bool
220- wantCallType vm.CallType
219+ wantMutability vm. StateMutability
220+ wantCallType vm.CallType
221221 }{
222222 {
223223 name : "EVM.Call()" ,
@@ -229,7 +229,7 @@ func TestNewStatefulPrecompile(t *testing.T) {
229229 Caller : caller ,
230230 Self : precompile ,
231231 },
232- wantReadOnly : false ,
232+ wantMutability : vm . MutableState ,
233233 wantTransferValue : transferValue ,
234234 wantCallType : vm .Call ,
235235 },
@@ -243,7 +243,7 @@ func TestNewStatefulPrecompile(t *testing.T) {
243243 Caller : caller ,
244244 Self : caller ,
245245 },
246- wantReadOnly : false ,
246+ wantMutability : vm . MutableState ,
247247 wantTransferValue : transferValue ,
248248 wantCallType : vm .CallCode ,
249249 },
@@ -257,7 +257,7 @@ func TestNewStatefulPrecompile(t *testing.T) {
257257 Caller : eoa , // inherited from caller
258258 Self : caller ,
259259 },
260- wantReadOnly : false ,
260+ wantMutability : vm . MutableState ,
261261 wantTransferValue : uint256 .NewInt (0 ),
262262 wantCallType : vm .DelegateCall ,
263263 },
@@ -271,7 +271,7 @@ func TestNewStatefulPrecompile(t *testing.T) {
271271 Caller : caller ,
272272 Self : precompile ,
273273 },
274- wantReadOnly : true ,
274+ wantMutability : vm . ReadOnlyState ,
275275 wantTransferValue : uint256 .NewInt (0 ),
276276 wantCallType : vm .StaticCall ,
277277 },
@@ -284,7 +284,7 @@ func TestNewStatefulPrecompile(t *testing.T) {
284284 Addresses : tt .wantAddresses ,
285285 StateValue : stateValue ,
286286 ValueReceived : tt .wantTransferValue ,
287- ReadOnly : tt .wantReadOnly ,
287+ Mutability : tt .wantMutability ,
288288 BlockNumber : header .Number ,
289289 BlockTime : header .Time ,
290290 Difficulty : header .Difficulty ,
@@ -334,7 +334,7 @@ func TestInheritReadOnly(t *testing.T) {
334334 PrecompileOverrides : map [common.Address ]libevm.PrecompiledContract {
335335 precompile : vm .NewStatefulPrecompile (
336336 func (env vm.PrecompileEnvironment , input []byte ) ([]byte , error ) {
337- if env .ReadOnly () {
337+ if env .StateMutability () != vm . MutableState {
338338 return []byte {ifReadOnly }, nil
339339 }
340340 return []byte {ifNotReadOnly }, nil
@@ -560,9 +560,9 @@ func TestPrecompileMakeCall(t *testing.T) {
560560 }),
561561 dest : vm .NewStatefulPrecompile (func (env vm.PrecompileEnvironment , input []byte ) (ret []byte , err error ) {
562562 out := & statefulPrecompileOutput {
563- Addresses : env .Addresses (),
564- ReadOnly : env .ReadOnly (),
565- Input : input , // expected to be callData
563+ Addresses : env .Addresses (),
564+ Mutability : env .StateMutability (),
565+ Input : input , // expected to be callData
566566 }
567567 return out .Bytes (), nil
568568 }),
@@ -591,7 +591,8 @@ func TestPrecompileMakeCall(t *testing.T) {
591591 Caller : sut ,
592592 Self : dest ,
593593 },
594- Input : precompileCallData ,
594+ Input : precompileCallData ,
595+ Mutability : vm .MutableState ,
595596 },
596597 },
597598 {
@@ -603,7 +604,8 @@ func TestPrecompileMakeCall(t *testing.T) {
603604 Caller : caller , // overridden by CallOption
604605 Self : dest ,
605606 },
606- Input : precompileCallData ,
607+ Input : precompileCallData ,
608+ Mutability : vm .MutableState ,
607609 },
608610 },
609611 {
@@ -614,7 +616,8 @@ func TestPrecompileMakeCall(t *testing.T) {
614616 Caller : caller , // SUT runs as its own caller because of CALLCODE
615617 Self : dest ,
616618 },
617- Input : precompileCallData ,
619+ Input : precompileCallData ,
620+ Mutability : vm .MutableState ,
618621 },
619622 },
620623 {
@@ -626,7 +629,8 @@ func TestPrecompileMakeCall(t *testing.T) {
626629 Caller : caller , // CallOption is a NOOP
627630 Self : dest ,
628631 },
629- Input : precompileCallData ,
632+ Input : precompileCallData ,
633+ Mutability : vm .MutableState ,
630634 },
631635 },
632636 {
@@ -637,7 +641,8 @@ func TestPrecompileMakeCall(t *testing.T) {
637641 Caller : caller , // as with CALLCODE
638642 Self : dest ,
639643 },
640- Input : precompileCallData ,
644+ Input : precompileCallData ,
645+ Mutability : vm .MutableState ,
641646 },
642647 },
643648 {
@@ -649,7 +654,8 @@ func TestPrecompileMakeCall(t *testing.T) {
649654 Caller : caller , // CallOption is a NOOP
650655 Self : dest ,
651656 },
652- Input : precompileCallData ,
657+ Input : precompileCallData ,
658+ Mutability : vm .MutableState ,
653659 },
654660 },
655661 {
@@ -665,7 +671,7 @@ func TestPrecompileMakeCall(t *testing.T) {
665671 // (non-static) CALL, the read-only state is inherited. Yes,
666672 // this is _another_ way to get a read-only state, different to
667673 // the other tests.
668- ReadOnly : true ,
674+ Mutability : vm . ReadOnlyState ,
669675 },
670676 },
671677 {
@@ -677,8 +683,8 @@ func TestPrecompileMakeCall(t *testing.T) {
677683 Caller : caller , // overridden by CallOption
678684 Self : dest ,
679685 },
680- Input : precompileCallData ,
681- ReadOnly : true ,
686+ Input : precompileCallData ,
687+ Mutability : vm . ReadOnlyState ,
682688 },
683689 },
684690 }
0 commit comments