|
97 | 97 | ) |
98 | 98 |
|
99 | 99 | func gasSStore(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) { |
| 100 | + if evm.readOnly { |
| 101 | + return 0, ErrWriteProtection |
| 102 | + } |
100 | 103 | var ( |
101 | 104 | y, x = stack.Back(1), stack.Back(0) |
102 | 105 | current, original = evm.StateDB.GetStateAndCommittedState(contract.Address(), x.Bytes32()) |
@@ -181,6 +184,9 @@ func gasSStore(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySi |
181 | 184 | // (2.2.2.1.) If original value is 0, add SSTORE_SET_GAS - SLOAD_GAS to refund counter. |
182 | 185 | // (2.2.2.2.) Otherwise, add SSTORE_RESET_GAS - SLOAD_GAS gas to refund counter. |
183 | 186 | func gasSStoreEIP2200(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) { |
| 187 | + if evm.readOnly { |
| 188 | + return 0, ErrWriteProtection |
| 189 | + } |
184 | 190 | // If we fail the minimum gas availability invariant, fail (0) |
185 | 191 | if contract.Gas <= params.SstoreSentryGasEIP2200 { |
186 | 192 | return 0, errors.New("not enough gas for reentrancy sentry") |
@@ -374,6 +380,10 @@ func gasCall(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize |
374 | 380 | transfersValue = !stack.Back(2).IsZero() |
375 | 381 | address = common.Address(stack.Back(1).Bytes20()) |
376 | 382 | ) |
| 383 | + if evm.readOnly && transfersValue { |
| 384 | + return 0, ErrWriteProtection |
| 385 | + } |
| 386 | + |
377 | 387 | if evm.chainRules.IsEIP158 { |
378 | 388 | if transfersValue && evm.StateDB.Empty(address) { |
379 | 389 | gas += params.CallNewAccountGas |
@@ -462,6 +472,10 @@ func gasStaticCall(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memo |
462 | 472 | } |
463 | 473 |
|
464 | 474 | func gasSelfdestruct(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) { |
| 475 | + if evm.readOnly { |
| 476 | + return 0, ErrWriteProtection |
| 477 | + } |
| 478 | + |
465 | 479 | var gas uint64 |
466 | 480 | // EIP150 homestead gas reprice fork: |
467 | 481 | if evm.chainRules.IsEIP150 { |
|
0 commit comments