From 31371a97a376d3145acb48fe9a41f5c69bb997a2 Mon Sep 17 00:00:00 2001 From: dustinxie Date: Fri, 2 Dec 2022 14:59:41 -0600 Subject: [PATCH] =?UTF-8?q?[evm]=20manually=20correct=20gas=20refund=20in?= =?UTF-8?q?=20case=20opcode=20execution=20returns=20Er=E2=80=A6=20(#3690)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: millken --- action/protocol/execution/evm/evm.go | 19 ++-- .../execution/evm/evmstatedbadapter.go | 23 ++--- action/protocol/execution/protocol_test.go | 31 +++++++ .../write-protection-001.json | 47 ++++++++++ .../write-protection-001.sol | 59 +++++++++++++ .../write-protection-002.json | 47 ++++++++++ .../write-protection-002.sol | 47 ++++++++++ .../write-protection-003.json | 47 ++++++++++ .../write-protection-003.sol | 86 +++++++++++++++++++ .../write-protection-004.json | 47 ++++++++++ .../write-protection-004.sol | 83 ++++++++++++++++++ .../write-protection-005.json | 47 ++++++++++ .../write-protection-005.sol | 56 ++++++++++++ .../write-protection-006.json | 47 ++++++++++ .../write-protection-006.sol | 65 ++++++++++++++ .../write-protection-007.json | 47 ++++++++++ .../write-protection-007.sol | 58 +++++++++++++ .../testdata-istanbul/write-protection.json | 47 ++++++++++ .../testdata-istanbul/write-protection.sol | 72 ++++++++++++++++ go.mod | 4 +- go.sum | 7 +- 21 files changed, 956 insertions(+), 30 deletions(-) create mode 100644 action/protocol/execution/testdata-istanbul/write-protection-001.json create mode 100644 action/protocol/execution/testdata-istanbul/write-protection-001.sol create mode 100644 action/protocol/execution/testdata-istanbul/write-protection-002.json create mode 100644 action/protocol/execution/testdata-istanbul/write-protection-002.sol create mode 100644 action/protocol/execution/testdata-istanbul/write-protection-003.json create mode 100644 action/protocol/execution/testdata-istanbul/write-protection-003.sol create mode 100644 action/protocol/execution/testdata-istanbul/write-protection-004.json create mode 100644 action/protocol/execution/testdata-istanbul/write-protection-004.sol create mode 100644 action/protocol/execution/testdata-istanbul/write-protection-005.json create mode 100644 action/protocol/execution/testdata-istanbul/write-protection-005.sol create mode 100644 action/protocol/execution/testdata-istanbul/write-protection-006.json create mode 100644 action/protocol/execution/testdata-istanbul/write-protection-006.sol create mode 100644 action/protocol/execution/testdata-istanbul/write-protection-007.json create mode 100644 action/protocol/execution/testdata-istanbul/write-protection-007.sol create mode 100644 action/protocol/execution/testdata-istanbul/write-protection.json create mode 100644 action/protocol/execution/testdata-istanbul/write-protection.sol diff --git a/action/protocol/execution/evm/evm.go b/action/protocol/execution/evm/evm.go index a8491d0cca..adead10579 100644 --- a/action/protocol/execution/evm/evm.go +++ b/action/protocol/execution/evm/evm.go @@ -319,7 +319,7 @@ func prepareStateDB(ctx context.Context, sm protocol.StateManager) (*StateDBAdap opts = append(opts, NotCheckPutStateErrorOption()) } if !featureCtx.CorrectGasRefund { - opts = append(opts, NotCorrectGasRefundOption()) + opts = append(opts, ManualCorrectGasRefundOption()) } return NewStateDBAdapter( @@ -422,17 +422,18 @@ func executeInEVM(ctx context.Context, evmParams *Params, stateDB *StateDBAdapte // After EIP-3529: refunds are capped to gasUsed / 5 refund = (evmParams.gas - remainingGas) / params.RefundQuotientEIP3529 } - // adjust refund due to dynamicGas + // before London EVM activation (at Okhotsk height), in certain cases dynamicGas + // has caused gas refund to change, which needs to be manually adjusted after + // the tx is reverted. After Okhotsk height, it is fixed inside RevertToSnapshot() var ( - refundLastSnapshot = stateDB.RefundAtLastSnapshot() - currentRefund = stateDB.GetRefund() - featureCtx = protocol.MustGetFeatureCtx(ctx) + deltaRefundByDynamicGas = evm.DeltaRefundByDynamicGas + featureCtx = protocol.MustGetFeatureCtx(ctx) ) - if evmErr != nil && !featureCtx.CorrectGasRefund && refundLastSnapshot > 0 && refundLastSnapshot != currentRefund { - if refundLastSnapshot > currentRefund { - stateDB.AddRefund(refundLastSnapshot - currentRefund) + if !featureCtx.CorrectGasRefund && deltaRefundByDynamicGas != 0 { + if deltaRefundByDynamicGas > 0 { + stateDB.SubRefund(uint64(deltaRefundByDynamicGas)) } else { - stateDB.SubRefund(currentRefund - refundLastSnapshot) + stateDB.AddRefund(uint64(-deltaRefundByDynamicGas)) } } if refund > stateDB.GetRefund() { diff --git a/action/protocol/execution/evm/evmstatedbadapter.go b/action/protocol/execution/evm/evmstatedbadapter.go index 5e8a74467d..cadfcb2d99 100644 --- a/action/protocol/execution/evm/evmstatedbadapter.go +++ b/action/protocol/execution/evm/evmstatedbadapter.go @@ -56,7 +56,6 @@ type ( blockHeight uint64 executionHash hash.Hash256 refund uint64 - refundAtLastSnapshot uint64 refundSnapshot map[int]uint64 cachedContract contractMap contractSnapshot map[int]contractMap // snapshots of contracts @@ -76,7 +75,7 @@ type ( fixSnapshotOrder bool revertLog bool notCheckPutStateError bool - notCorrectGasRefund bool + manualCorrectGasRefund bool } ) @@ -147,10 +146,13 @@ func NotCheckPutStateErrorOption() StateDBAdapterOption { } } -// NotCorrectGasRefundOption set correctGasRefund as true -func NotCorrectGasRefundOption() StateDBAdapterOption { +// ManualCorrectGasRefundOption set manualCorrectGasRefund as true +func ManualCorrectGasRefundOption() StateDBAdapterOption { return func(adapter *StateDBAdapter) error { - adapter.notCorrectGasRefund = true + // before London EVM activation (at Okhotsk height), in certain cases dynamicGas + // has caused gas refund to change, which needs to be manually adjusted after + // the tx is reverted. After Okhotsk height, it is fixed inside RevertToSnapshot() + adapter.manualCorrectGasRefund = true return nil } } @@ -553,10 +555,7 @@ func (stateDB *StateDBAdapter) RevertToSnapshot(snapshot int) { return } // restore gas refund - if stateDB.notCorrectGasRefund { - // check if refund has changed from last snapshot (due to dynamicGas) - stateDB.refundAtLastSnapshot = stateDB.refundSnapshot[snapshot] - } else { + if !stateDB.manualCorrectGasRefund { stateDB.refund = stateDB.refundSnapshot[snapshot] } // restore logs and txLogs @@ -641,11 +640,6 @@ func (stateDB *StateDBAdapter) RevertToSnapshot(snapshot int) { } } -// RefundAtLastSnapshot returns refund at last snapshot -func (stateDB *StateDBAdapter) RefundAtLastSnapshot() uint64 { - return stateDB.refundAtLastSnapshot -} - func (stateDB *StateDBAdapter) cachedContractAddrs() []hash.Hash160 { addrs := make([]hash.Hash160, 0, len(stateDB.cachedContract)) for addr := range stateDB.cachedContract { @@ -1036,7 +1030,6 @@ func (stateDB *StateDBAdapter) getNewContract(addr hash.Hash160) (Contract, erro // clear clears local changes func (stateDB *StateDBAdapter) clear() { - stateDB.refundAtLastSnapshot = 0 stateDB.refundSnapshot = make(map[int]uint64) stateDB.cachedContract = make(contractMap) stateDB.contractSnapshot = make(map[int]contractMap) diff --git a/action/protocol/execution/protocol_test.go b/action/protocol/execution/protocol_test.go index bdc996b6c5..12ac72bed9 100644 --- a/action/protocol/execution/protocol_test.go +++ b/action/protocol/execution/protocol_test.go @@ -1048,6 +1048,37 @@ func TestIstanbulEVM(t *testing.T) { t.Run("CVE-2021-39137-attack-replay", func(t *testing.T) { NewSmartContractTest(t, "testdata/CVE-2021-39137-attack-replay.json") }) + t.Run("err-write-protection", func(t *testing.T) { + NewSmartContractTest(t, "testdata-istanbul/write-protection.json") + }) + t.Run("err-write-protection-twice-delta-0", func(t *testing.T) { + // hit errWriteProtection 2 times, delta is 0 + NewSmartContractTest(t, "testdata-istanbul/write-protection-001.json") + }) + t.Run("err-write-protection-once-delta-0", func(t *testing.T) { + // hit errWriteProtection 1 times, delta is 0 + NewSmartContractTest(t, "testdata-istanbul/write-protection-002.json") + }) + t.Run("err-write-protection-twice-delta-0-0", func(t *testing.T) { + // hit errWriteProtection twice, delta is not 0 + NewSmartContractTest(t, "testdata-istanbul/write-protection-003.json") + }) + t.Run("err-write-protection-twice-delta-0-1", func(t *testing.T) { + // hit errWriteProtection twice, first delta is not 0, second delta is 0 + NewSmartContractTest(t, "testdata-istanbul/write-protection-004.json") + }) + t.Run("err-write-protection-once-delta-1", func(t *testing.T) { + // hit errWriteProtection once, delta is not 0,but no revert + NewSmartContractTest(t, "testdata-istanbul/write-protection-005.json") + }) + t.Run("err-write-protection-twice-delta-1-1", func(t *testing.T) { + // hit errWriteProtection twice,, first delta is not 0, second delta is not 0, no revert + NewSmartContractTest(t, "testdata-istanbul/write-protection-006.json") + }) + t.Run("err-write-protection-twice-delta-0-1", func(t *testing.T) { + // hit errWriteProtection twice,, first delta is 0, second delta is not 0, no revert + NewSmartContractTest(t, "testdata-istanbul/write-protection-007.json") + }) } func TestLondonEVM(t *testing.T) { diff --git a/action/protocol/execution/testdata-istanbul/write-protection-001.json b/action/protocol/execution/testdata-istanbul/write-protection-001.json new file mode 100644 index 0000000000..d9084f501d --- /dev/null +++ b/action/protocol/execution/testdata-istanbul/write-protection-001.json @@ -0,0 +1,47 @@ +{ + "initGenesis": { + "isBering" : true, + "isIceland" : true + }, + "initBalances": [{ + "account": "io1mflp9m6hcgm2qcghchsdqj3z3eccrnekx9p0ms", + "rawBalance": "1000000000000000000000000000" + }], + "deployments": [{ + "rawByteCode": "608060405234801561001057600080fd5b50610800806100206000396000f3fe608060405234801561001057600080fd5b50600436106100625760003560e01c8063167517ce146100675780633fa4f245146100b55780634e70b1dc146100d357806367e404ce146100f1578063c6dad08214610125578063d1e0f3081461012f575b600080fd5b6100b36004803603604081101561007d57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610191565b005b6100bd610346565b6040518082815260200191505060405180910390f35b6100db61034c565b6040518082815260200191505060405180910390f35b6100f9610352565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b61012d610378565b005b61017b6004803603604081101561014557600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610431565b6040518082815260200191505060405180910390f35b60008114156101b3576004600060018152602001908152602001600020600090555b600060608373ffffffffffffffffffffffffffffffffffffffff1683604051602401808281526020019150506040516020818303038152906040527f6466414b000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506040518082805190602001908083835b6020831061028f578051825260208201915060208101905060208303925061026c565b6001836020036101000a038019825116818451168082178552505050505050905001915050600060405180830381855afa9150503d80600081146102ef576040519150601f19603f3d011682016040523d82523d6000602084013e6102f4565b606091505b50915091507f3b0a8ddef325df2bfdfa6b430ae4c8421841cd135bfa8fb5e432f200787520bb8260405180821515815260200191505060405180910390a1600083141561034057600080fd5b50505050565b60025481565b60005481565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b604051610384906105ae565b604051809103906000f0801580156103a0573d6000803e3d6000fd5b50600360006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550600160046000600181526020019081526020016000208190555060026004600060028152602001908152602001600020819055506003600460006003815260200190815260200160002081905550565b60008073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16141561048d57600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1692505b3073ffffffffffffffffffffffffffffffffffffffff1663167517ce8460006040518363ffffffff1660e01b8152600401808373ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050600060405180830381600087803b1580156104ff57600080fd5b505af1925050508015610510575060015b6105a3573073ffffffffffffffffffffffffffffffffffffffff1663167517ce8460016040518363ffffffff1660e01b8152600401808373ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050600060405180830381600087803b15801561058657600080fd5b505af115801561059a573d6000803e3d6000fd5b505050506105a4565b5b6001905092915050565b61020f806105bc8339019056fe608060405234801561001057600080fd5b506101ef806100206000396000f3fe60806040526004361061003f5760003560e01c80633fa4f245146100445780634e70b1dc1461006f5780636466414b1461009a57806367e404ce146100c8575b600080fd5b34801561005057600080fd5b50610059610109565b6040518082815260200191505060405180910390f35b34801561007b57600080fd5b5061008461010f565b6040518082815260200191505060405180910390f35b6100c6600480360360208110156100b057600080fd5b8101908080359060200190929190505050610115565b005b3480156100d457600080fd5b506100dd610193565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b60025481565b60005481565b8060008190555033600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550346002819055507f9f9fb434574749b74458e0ddc3cf5fd5bdb1b009c8615e825606b53724576f3560405160405180910390a150565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168156fea2646970667358221220dc7b79728e1a021337a246ea4100bea60a986cd86fb67c31ebc34b868a7c5b4064736f6c634300060c0033a264697066735822122014ab730ff529680b3b79508b582c7f724ec58dce75085f480e9dd74864f849d664736f6c634300060c0033", + "rawPrivateKey": "cfa6ef757dee2e50351620dca002d32b9c090cfda55fb81f37f1d26b273743f1", + "rawAmount": "0", + "rawGasLimit": 5000000, + "rawGasPrice": "0", + "rawExpectedGasConsumed": 628043, + "expectedStatus": 1, + "expectedBalances": [], + "comment": "deploy write protection contract" + }], + "executions": [{ + "rawPrivateKey": "cfa6ef757dee2e50351620dca002d32b9c090cfda55fb81f37f1d26b273743f1", + "rawByteCode": "c6dad082", + "rawAmount": "0", + "rawGasLimit": 1000000, + "rawGasPrice": "0", + "rawAccessList": [], + "rawExpectedGasConsumed": 223105, + "expectedStatus": 1, + "hasReturnValue": true, + "rawReturnValue": "", + "comment": "call make" + }, { + "rawPrivateKey": "cfa6ef757dee2e50351620dca002d32b9c090cfda55fb81f37f1d26b273743f1", + "rawByteCode": "d1e0f30800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000084", + "rawAmount": "0", + "rawGasLimit": 6000000, + "rawGasPrice": "0", + "rawAccessList": [], + "rawExpectedGasConsumed": 5980648, + "expectedStatus": 1, + "expectedLogs": [{},{}], + "hasReturnValue": true, + "rawReturnValue": "", + "comment": "call setVars" + }] +} \ No newline at end of file diff --git a/action/protocol/execution/testdata-istanbul/write-protection-001.sol b/action/protocol/execution/testdata-istanbul/write-protection-001.sol new file mode 100644 index 0000000000..4e8f2da017 --- /dev/null +++ b/action/protocol/execution/testdata-istanbul/write-protection-001.sol @@ -0,0 +1,59 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.6.6; + +// NOTE: Deploy this contract first +contract B { + // NOTE: storage layout must be the same as contract A + uint public num; + address public sender; + uint public value; + event Done(); + + function setVars(uint _num) public payable { + num = _num; + sender = msg.sender; + value = msg.value; + emit Done(); + } +} + +contract A { + uint public num; + address public sender; + uint public value; + address private c; + mapping(uint => uint) private _a; + event Success(bool); + + function make() public { + c = address(new B()); + _a[1] = 1; + _a[2] = 2; + _a[3] = 3; + } + + function callStatic(address _contract,uint _num) public { + if (_num == 0) { + delete _a[1]; + } + (bool success, bytes memory _) = _contract.staticcall( + abi.encodeWithSignature("setVars(uint256)", _num) + ); + emit Success(success); + if (_num == 0) { + revert(); + } + } + + function setVars(address _contract, uint _num) public returns (uint256) { + if (_contract == address(0)) { + _contract = c; + } + try this.callStatic(_contract,0) { + } catch { + this.callStatic(_contract,1); + } + + return 1; + } +} \ No newline at end of file diff --git a/action/protocol/execution/testdata-istanbul/write-protection-002.json b/action/protocol/execution/testdata-istanbul/write-protection-002.json new file mode 100644 index 0000000000..3b2f30a670 --- /dev/null +++ b/action/protocol/execution/testdata-istanbul/write-protection-002.json @@ -0,0 +1,47 @@ +{ + "initGenesis": { + "isBering" : true, + "isIceland" : true + }, + "initBalances": [{ + "account": "io1mflp9m6hcgm2qcghchsdqj3z3eccrnekx9p0ms", + "rawBalance": "1000000000000000000000000000" + }], + "deployments": [{ + "rawByteCode": "608060405234801561001057600080fd5b50610674806100206000396000f3fe608060405234801561001057600080fd5b50600436106100575760003560e01c80633fa4f2451461005c5780634e70b1dc1461007a57806367e404ce14610098578063c6dad082146100cc578063d1e0f308146100d6575b600080fd5b610064610138565b6040518082815260200191505060405180910390f35b61008261013e565b6040518082815260200191505060405180910390f35b6100a0610144565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6100d461016a565b005b610122600480360360408110156100ec57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610223565b6040518082815260200191505060405180910390f35b60025481565b60005481565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60405161017690610422565b604051809103906000f080158015610192573d6000803e3d6000fd5b50600360006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550600160046000600181526020019081526020016000208190555060026004600060028152602001908152602001600020819055506003600460006003815260200190815260200160002081905550565b60008073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16141561027f57600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1692505b600460006001815260200190815260200160002060009055600060608473ffffffffffffffffffffffffffffffffffffffff1684604051602401808281526020019150506040516020818303038152906040527f6466414b000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506040518082805190602001908083835b602083106103735780518252602082019150602081019050602083039250610350565b6001836020036101000a038019825116818451168082178552505050505050905001915050600060405180830381855afa9150503d80600081146103d3576040519150601f19603f3d011682016040523d82523d6000602084013e6103d8565b606091505b50915091507f3b0a8ddef325df2bfdfa6b430ae4c8421841cd135bfa8fb5e432f200787520bb8260405180821515815260200191505060405180910390a160019250505092915050565b61020f806104308339019056fe608060405234801561001057600080fd5b506101ef806100206000396000f3fe60806040526004361061003f5760003560e01c80633fa4f245146100445780634e70b1dc1461006f5780636466414b1461009a57806367e404ce146100c8575b600080fd5b34801561005057600080fd5b50610059610109565b6040518082815260200191505060405180910390f35b34801561007b57600080fd5b5061008461010f565b6040518082815260200191505060405180910390f35b6100c6600480360360208110156100b057600080fd5b8101908080359060200190929190505050610115565b005b3480156100d457600080fd5b506100dd610193565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b60025481565b60005481565b8060008190555033600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550346002819055507f9f9fb434574749b74458e0ddc3cf5fd5bdb1b009c8615e825606b53724576f3560405160405180910390a150565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168156fea2646970667358221220767a39a75f6558c8cd67a6a7d5f3c563c41b8b525a636bd0bf208f54cbb050d464736f6c634300060c0033a2646970667358221220d8c4080ef0ef989fb44d95667c95127f088ee79c32c18be82d378ea8fe4fbc7c64736f6c634300060c0033", + "rawPrivateKey": "cfa6ef757dee2e50351620dca002d32b9c090cfda55fb81f37f1d26b273743f1", + "rawAmount": "0", + "rawGasLimit": 5000000, + "rawGasPrice": "0", + "rawExpectedGasConsumed": 509168, + "expectedStatus": 1, + "expectedBalances": [], + "comment": "deploy write protection contract" + }], + "executions": [{ + "rawPrivateKey": "cfa6ef757dee2e50351620dca002d32b9c090cfda55fb81f37f1d26b273743f1", + "rawByteCode": "c6dad082", + "rawAmount": "0", + "rawGasLimit": 1000000, + "rawGasPrice": "0", + "rawAccessList": [], + "rawExpectedGasConsumed": 223083, + "expectedStatus": 1, + "hasReturnValue": true, + "rawReturnValue": "", + "comment": "call make" + }, { + "rawPrivateKey": "cfa6ef757dee2e50351620dca002d32b9c090cfda55fb81f37f1d26b273743f1", + "rawByteCode": "d1e0f30800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000084", + "rawAmount": "0", + "rawGasLimit": 6000000, + "rawGasPrice": "0", + "rawAccessList": [], + "rawExpectedGasConsumed": 5892833, + "expectedStatus": 1, + "expectedLogs": [{}], + "hasReturnValue": true, + "rawReturnValue": "", + "comment": "call setVars" + }] +} \ No newline at end of file diff --git a/action/protocol/execution/testdata-istanbul/write-protection-002.sol b/action/protocol/execution/testdata-istanbul/write-protection-002.sol new file mode 100644 index 0000000000..c0dd960ddf --- /dev/null +++ b/action/protocol/execution/testdata-istanbul/write-protection-002.sol @@ -0,0 +1,47 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.6.6; + +// NOTE: Deploy this contract first +contract B { + // NOTE: storage layout must be the same as contract A + uint public num; + address public sender; + uint public value; + event Done(); + + function setVars(uint _num) public payable { + num = _num; + sender = msg.sender; + value = msg.value; + emit Done(); + } +} + +contract A { + uint public num; + address public sender; + uint public value; + address private c; + mapping(uint => uint) private _a; + event Success(bool); + + function make() public { + c = address(new B()); + _a[1] = 1; + _a[2] = 2; + _a[3] = 3; + } + + function setVars(address _contract, uint _num) public returns (uint256) { + if (_contract == address(0)) { + _contract = c; + } + delete _a[1]; + (bool success, bytes memory _) = _contract.staticcall( + abi.encodeWithSignature("setVars(uint256)", _num) + ); + emit Success(success); + + return 1; + } +} \ No newline at end of file diff --git a/action/protocol/execution/testdata-istanbul/write-protection-003.json b/action/protocol/execution/testdata-istanbul/write-protection-003.json new file mode 100644 index 0000000000..6cf6204040 --- /dev/null +++ b/action/protocol/execution/testdata-istanbul/write-protection-003.json @@ -0,0 +1,47 @@ +{ + "initGenesis": { + "isBering" : true, + "isIceland" : true + }, + "initBalances": [{ + "account": "io1mflp9m6hcgm2qcghchsdqj3z3eccrnekx9p0ms", + "rawBalance": "1000000000000000000000000000" + }], + "deployments": [{ + "rawByteCode": "608060405234801561001057600080fd5b50610a3d806100206000396000f3fe608060405234801561001057600080fd5b50600436106100625760003560e01c8063167517ce146100675780633fa4f245146100b55780634e70b1dc146100d357806367e404ce146100f1578063c6dad08214610125578063d1e0f3081461012f575b600080fd5b6100b36004803603604081101561007d57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610191565b005b6100bd6104da565b6040518082815260200191505060405180910390f35b6100db6104e0565b6040518082815260200191505060405180910390f35b6100f96104e6565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b61012d61050c565b005b61017b6004803603604081101561014557600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506105c5565b6040518082815260200191505060405180910390f35b6000811415610302578173ffffffffffffffffffffffffffffffffffffffff166040516024016040516020818303038152906040527fef2d5a06000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506040518082805190602001908083835b602083106102675780518252602082019150602081019050602083039250610244565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d80600081146102c9576040519150601f19603f3d011682016040523d82523d6000602084013e6102ce565b606091505b5050506004600060018152602001908152602001600020600090556004600060028152602001908152602001600020600090555b6001811415610324576004600060038152602001908152602001600020600090555b600060608373ffffffffffffffffffffffffffffffffffffffff1683604051602401808281526020019150506040516020818303038152906040527f6466414b000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506040518082805190602001908083835b6020831061040057805182526020820191506020810190506020830392506103dd565b6001836020036101000a038019825116818451168082178552505050505050905001915050600060405180830381855afa9150503d8060008114610460576040519150601f19603f3d011682016040523d82523d6000602084013e610465565b606091505b50915091507f3b0a8ddef325df2bfdfa6b430ae4c8421841cd135bfa8fb5e432f200787520bb8260405180821515815260200191505060405180910390a160008314156104b157600080fd5b60018314156104d457600073ffffffffffffffffffffffffffffffffffffffff16ff5b50505050565b60025481565b60005481565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60405161051890610742565b604051809103906000f080158015610534573d6000803e3d6000fd5b50600360006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550600160046000600181526020019081526020016000208190555060026004600060028152602001908152602001600020819055506003600460006003815260200190815260200160002081905550565b60008073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16141561062157600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1692505b3073ffffffffffffffffffffffffffffffffffffffff1663167517ce8460006040518363ffffffff1660e01b8152600401808373ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050600060405180830381600087803b15801561069357600080fd5b505af19250505080156106a4575060015b610737573073ffffffffffffffffffffffffffffffffffffffff1663167517ce8460016040518363ffffffff1660e01b8152600401808373ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050600060405180830381600087803b15801561071a57600080fd5b505af115801561072e573d6000803e3d6000fd5b50505050610738565b5b6001905092915050565b6102b8806107508339019056fe608060405234801561001057600080fd5b50600160036000600181526020019081526020016000208190555060026003600060028152602001908152602001600020819055506003806000600381526020019081526020016000208190555061024b8061006d6000396000f3fe60806040526004361061003f5760003560e01c80633fa4f245146100445780634e70b1dc1461006f5780636466414b1461009a57806367e404ce146100c8575b600080fd5b34801561005057600080fd5b50610059610109565b6040518082815260200191505060405180910390f35b34801561007b57600080fd5b5061008461010f565b6040518082815260200191505060405180910390f35b6100c6600480360360208110156100b057600080fd5b8101908080359060200190929190505050610115565b005b3480156100d457600080fd5b506100dd6101ef565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b60025481565b60005481565b600081141561014f576003600060018152602001908152602001600020600090556003600060028152602001908152602001600020600090555b6001811415610171576003600060038152602001908152602001600020600090555b8060008190555033600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550346002819055507f9f9fb434574749b74458e0ddc3cf5fd5bdb1b009c8615e825606b53724576f3560405160405180910390a150565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168156fea264697066735822122092a13109d811cfe7f039465f8d848dff0ab184919769d4a7ef85c56798edf07264736f6c634300060c0033a26469706673582212200d799fd8d03cbe9eca8764933c074843c208fb358ba5fa6d599d47116ab396f364736f6c634300060c0033", + "rawPrivateKey": "cfa6ef757dee2e50351620dca002d32b9c090cfda55fb81f37f1d26b273743f1", + "rawAmount": "0", + "rawGasLimit": 5000000, + "rawGasPrice": "0", + "rawExpectedGasConsumed": 800056, + "expectedStatus": 1, + "expectedBalances": [], + "comment": "deploy write protection contract" + }], + "executions": [{ + "rawPrivateKey": "cfa6ef757dee2e50351620dca002d32b9c090cfda55fb81f37f1d26b273743f1", + "rawByteCode": "c6dad082", + "rawAmount": "0", + "rawGasLimit": 1000000, + "rawGasPrice": "0", + "rawAccessList": [], + "rawExpectedGasConsumed": 301830, + "expectedStatus": 1, + "hasReturnValue": true, + "rawReturnValue": "", + "comment": "call make" + }, { + "rawPrivateKey": "cfa6ef757dee2e50351620dca002d32b9c090cfda55fb81f37f1d26b273743f1", + "rawByteCode": "d1e0f30800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000084", + "rawAmount": "0", + "rawGasLimit": 6000000, + "rawGasPrice": "0", + "rawAccessList": [], + "rawExpectedGasConsumed": 5928187, + "expectedStatus": 106, + "expectedLogs": [{}], + "hasReturnValue": true, + "rawReturnValue": "", + "comment": "call setVars" + }] +} \ No newline at end of file diff --git a/action/protocol/execution/testdata-istanbul/write-protection-003.sol b/action/protocol/execution/testdata-istanbul/write-protection-003.sol new file mode 100644 index 0000000000..00c0d6eff1 --- /dev/null +++ b/action/protocol/execution/testdata-istanbul/write-protection-003.sol @@ -0,0 +1,86 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.6.6; + +// NOTE: Deploy this contract first +contract B { + // NOTE: storage layout must be the same as contract A + uint public num; + address public sender; + uint public value; + mapping(uint => uint) private _a; + event Done(); + + constructor() public { + _a[1] = 1; + _a[2] = 2; + _a[3] = 3; + } + + function setVars(uint _num) public payable { + if (_num == 0) { + delete _a[1]; + delete _a[2]; + } + if (_num == 1) { + delete _a[3]; + } + num = _num; + sender = msg.sender; + value = msg.value; + emit Done(); + } +} + +contract A { + uint public num; + address public sender; + uint public value; + address private c; + mapping(uint => uint) private _a; + event Success(bool); + + function make() public { + c = address(new B()); + _a[1] = 1; + _a[2] = 2; + _a[3] = 3; + } + + function callStatic(address _contract,uint _num) public { + if (_num == 0) { + _contract.call( + abi.encodeWithSignature("notfund()") + ); + delete _a[1]; + delete _a[2]; + } + if (_num == 1) { + delete _a[3]; + } + (bool success, bytes memory _) = _contract.staticcall( + abi.encodeWithSignature("setVars(uint256)", _num) + ); + emit Success(success); + if (_num == 0) { + revert(); + } + if (_num == 1) { + selfdestruct(address(0)); + } + // 0x0000000000000000000000000000000000000000.call( + // abi.encodeWithSignature("notfund()") + // ); + } + + function setVars(address _contract, uint _num) public returns (uint256) { + if (_contract == address(0)) { + _contract = c; + } + try this.callStatic(_contract,0) { + } catch { + this.callStatic(_contract,1); + } + + return 1; + } +} \ No newline at end of file diff --git a/action/protocol/execution/testdata-istanbul/write-protection-004.json b/action/protocol/execution/testdata-istanbul/write-protection-004.json new file mode 100644 index 0000000000..1ee5e63848 --- /dev/null +++ b/action/protocol/execution/testdata-istanbul/write-protection-004.json @@ -0,0 +1,47 @@ +{ + "initGenesis": { + "isBering" : true, + "isIceland" : true + }, + "initBalances": [{ + "account": "io1mflp9m6hcgm2qcghchsdqj3z3eccrnekx9p0ms", + "rawBalance": "1000000000000000000000000000" + }], + "deployments": [{ + "rawByteCode": "608060405234801561001057600080fd5b50610a1b806100206000396000f3fe608060405234801561001057600080fd5b50600436106100625760003560e01c8063167517ce146100675780633fa4f245146100b55780634e70b1dc146100d357806367e404ce146100f1578063c6dad08214610125578063d1e0f3081461012f575b600080fd5b6100b36004803603604081101561007d57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610191565b005b6100bd6104da565b6040518082815260200191505060405180910390f35b6100db6104e0565b6040518082815260200191505060405180910390f35b6100f96104e6565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b61012d61050c565b005b61017b6004803603604081101561014557600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506105c5565b6040518082815260200191505060405180910390f35b6000811415610302578173ffffffffffffffffffffffffffffffffffffffff166040516024016040516020818303038152906040527fef2d5a06000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506040518082805190602001908083835b602083106102675780518252602082019150602081019050602083039250610244565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d80600081146102c9576040519150601f19603f3d011682016040523d82523d6000602084013e6102ce565b606091505b5050506004600060018152602001908152602001600020600090556004600060028152602001908152602001600020600090555b6001811415610324576004600060038152602001908152602001600020600090555b600060608373ffffffffffffffffffffffffffffffffffffffff1683604051602401808281526020019150506040516020818303038152906040527f6466414b000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506040518082805190602001908083835b6020831061040057805182526020820191506020810190506020830392506103dd565b6001836020036101000a038019825116818451168082178552505050505050905001915050600060405180830381855afa9150503d8060008114610460576040519150601f19603f3d011682016040523d82523d6000602084013e610465565b606091505b50915091507f3b0a8ddef325df2bfdfa6b430ae4c8421841cd135bfa8fb5e432f200787520bb8260405180821515815260200191505060405180910390a160008314156104b157600080fd5b60018314156104d457600073ffffffffffffffffffffffffffffffffffffffff16ff5b50505050565b60025481565b60005481565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60405161051890610742565b604051809103906000f080158015610534573d6000803e3d6000fd5b50600360006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550600160046000600181526020019081526020016000208190555060026004600060028152602001908152602001600020819055506003600460006003815260200190815260200160002081905550565b60008073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16141561062157600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1692505b3073ffffffffffffffffffffffffffffffffffffffff1663167517ce8460006040518363ffffffff1660e01b8152600401808373ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050600060405180830381600087803b15801561069357600080fd5b505af19250505080156106a4575060015b610737573073ffffffffffffffffffffffffffffffffffffffff1663167517ce8460016040518363ffffffff1660e01b8152600401808373ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050600060405180830381600087803b15801561071a57600080fd5b505af115801561072e573d6000803e3d6000fd5b50505050610738565b5b6001905092915050565b610296806107508339019056fe608060405234801561001057600080fd5b5060016003600060018152602001908152602001600020819055506002600360006002815260200190815260200160002081905550600380600060038152602001908152602001600020819055506102298061006d6000396000f3fe60806040526004361061003f5760003560e01c80633fa4f245146100445780634e70b1dc1461006f5780636466414b1461009a57806367e404ce146100c8575b600080fd5b34801561005057600080fd5b50610059610109565b6040518082815260200191505060405180910390f35b34801561007b57600080fd5b5061008461010f565b6040518082815260200191505060405180910390f35b6100c6600480360360208110156100b057600080fd5b8101908080359060200190929190505050610115565b005b3480156100d457600080fd5b506100dd6101cd565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b60025481565b60005481565b600081141561014f576003600060018152602001908152602001600020600090556003600060028152602001908152602001600020600090555b8060008190555033600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550346002819055507f9f9fb434574749b74458e0ddc3cf5fd5bdb1b009c8615e825606b53724576f3560405160405180910390a150565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168156fea264697066735822122070982edea97f75ff827d96e420c00dd3ac8b008fd31923e9d3bca87122ac8cd764736f6c634300060c0033a26469706673582212204971692d2677e0efc5a02b21573f778345d568a514c8526ac897b376bc8da09b64736f6c634300060c0033", + "rawPrivateKey": "cfa6ef757dee2e50351620dca002d32b9c090cfda55fb81f37f1d26b273743f1", + "rawAmount": "0", + "rawGasLimit": 5000000, + "rawGasPrice": "0", + "rawExpectedGasConsumed": 789849, + "expectedStatus": 1, + "expectedBalances": [], + "comment": "deploy write protection contract" + }], + "executions": [{ + "rawPrivateKey": "cfa6ef757dee2e50351620dca002d32b9c090cfda55fb81f37f1d26b273743f1", + "rawByteCode": "c6dad082", + "rawAmount": "0", + "rawGasLimit": 1000000, + "rawGasPrice": "0", + "rawAccessList": [], + "rawExpectedGasConsumed": 295018, + "expectedStatus": 1, + "hasReturnValue": true, + "rawReturnValue": "", + "comment": "call make" + }, { + "rawPrivateKey": "cfa6ef757dee2e50351620dca002d32b9c090cfda55fb81f37f1d26b273743f1", + "rawByteCode": "d1e0f30800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000084", + "rawAmount": "0", + "rawGasLimit": 6000000, + "rawGasPrice": "0", + "rawAccessList": [], + "rawExpectedGasConsumed": 5928187, + "expectedStatus": 106, + "expectedLogs": [{}], + "hasReturnValue": true, + "rawReturnValue": "", + "comment": "call setVars" + }] +} \ No newline at end of file diff --git a/action/protocol/execution/testdata-istanbul/write-protection-004.sol b/action/protocol/execution/testdata-istanbul/write-protection-004.sol new file mode 100644 index 0000000000..215038dac6 --- /dev/null +++ b/action/protocol/execution/testdata-istanbul/write-protection-004.sol @@ -0,0 +1,83 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.6.6; + +// NOTE: Deploy this contract first +contract B { + // NOTE: storage layout must be the same as contract A + uint public num; + address public sender; + uint public value; + mapping(uint => uint) private _a; + event Done(); + + constructor() public { + _a[1] = 1; + _a[2] = 2; + _a[3] = 3; + } + + function setVars(uint _num) public payable { + if (_num == 0) { + delete _a[1]; + delete _a[2]; + } + num = _num; + sender = msg.sender; + value = msg.value; + emit Done(); + } +} + +contract A { + uint public num; + address public sender; + uint public value; + address private c; + mapping(uint => uint) private _a; + event Success(bool); + + function make() public { + c = address(new B()); + _a[1] = 1; + _a[2] = 2; + _a[3] = 3; + } + + function callStatic(address _contract,uint _num) public { + if (_num == 0) { + _contract.call( + abi.encodeWithSignature("notfund()") + ); + delete _a[1]; + delete _a[2]; + } + if (_num == 1) { + delete _a[3]; + } + (bool success, bytes memory _) = _contract.staticcall( + abi.encodeWithSignature("setVars(uint256)", _num) + ); + emit Success(success); + if (_num == 0) { + revert(); + } + if (_num == 1) { + selfdestruct(address(0)); + } + // 0x0000000000000000000000000000000000000000.call( + // abi.encodeWithSignature("notfund()") + // ); + } + + function setVars(address _contract, uint _num) public returns (uint256) { + if (_contract == address(0)) { + _contract = c; + } + try this.callStatic(_contract,0) { + } catch { + this.callStatic(_contract,1); + } + + return 1; + } +} \ No newline at end of file diff --git a/action/protocol/execution/testdata-istanbul/write-protection-005.json b/action/protocol/execution/testdata-istanbul/write-protection-005.json new file mode 100644 index 0000000000..c7a5bcd9ae --- /dev/null +++ b/action/protocol/execution/testdata-istanbul/write-protection-005.json @@ -0,0 +1,47 @@ +{ + "initGenesis": { + "isBering" : true, + "isIceland" : true + }, + "initBalances": [{ + "account": "io1mflp9m6hcgm2qcghchsdqj3z3eccrnekx9p0ms", + "rawBalance": "1000000000000000000000000000" + }], + "deployments": [{ + "rawByteCode": "608060405234801561001057600080fd5b506106f1806100206000396000f3fe608060405234801561001057600080fd5b50600436106100575760003560e01c80633fa4f2451461005c5780634e70b1dc1461007a57806367e404ce14610098578063c6dad082146100cc578063d1e0f308146100d6575b600080fd5b610064610138565b6040518082815260200191505060405180910390f35b61008261013e565b6040518082815260200191505060405180910390f35b6100a0610144565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6100d461016a565b005b610122600480360360408110156100ec57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610223565b6040518082815260200191505060405180910390f35b60025481565b60005481565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60405161017690610422565b604051809103906000f080158015610192573d6000803e3d6000fd5b50600360006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550600160046000600181526020019081526020016000208190555060026004600060028152602001908152602001600020819055506003600460006003815260200190815260200160002081905550565b60008073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16141561027f57600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1692505b600460006001815260200190815260200160002060009055600060608473ffffffffffffffffffffffffffffffffffffffff1684604051602401808281526020019150506040516020818303038152906040527f6466414b000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506040518082805190602001908083835b602083106103735780518252602082019150602081019050602083039250610350565b6001836020036101000a038019825116818451168082178552505050505050905001915050600060405180830381855afa9150503d80600081146103d3576040519150601f19603f3d011682016040523d82523d6000602084013e6103d8565b606091505b50915091507f3b0a8ddef325df2bfdfa6b430ae4c8421841cd135bfa8fb5e432f200787520bb8260405180821515815260200191505060405180910390a160019250505092915050565b61028c806104308339019056fe608060405234801561001057600080fd5b50600160036000600181526020019081526020016000208190555060026003600060028152602001908152602001600020819055506003806000600381526020019081526020016000208190555061021f8061006d6000396000f3fe60806040526004361061003f5760003560e01c80633fa4f245146100445780634e70b1dc1461006f5780636466414b1461009a57806367e404ce146100c8575b600080fd5b34801561005057600080fd5b50610059610109565b6040518082815260200191505060405180910390f35b34801561007b57600080fd5b5061008461010f565b6040518082815260200191505060405180910390f35b6100c6600480360360208110156100b057600080fd5b8101908080359060200190929190505050610115565b005b3480156100d457600080fd5b506100dd6101c3565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b60025481565b60005481565b6003600060018152602001908152602001600020600090556003600060028152602001908152602001600020600090558060008190555033600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550346002819055507f9f9fb434574749b74458e0ddc3cf5fd5bdb1b009c8615e825606b53724576f3560405160405180910390a150565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168156fea2646970667358221220f58d7104493b90766d5c7f2cffb0d12ce8897fc09da9126fc0258d0effe10a4064736f6c634300060c0033a2646970667358221220269c0d6922a2e0db333a4808e77366b9a5b1af6d530442dc386abd2df68ba5a964736f6c634300060c0033", + "rawPrivateKey": "cfa6ef757dee2e50351620dca002d32b9c090cfda55fb81f37f1d26b273743f1", + "rawAmount": "0", + "rawGasLimit": 5000000, + "rawGasPrice": "0", + "rawExpectedGasConsumed": 546693, + "expectedStatus": 1, + "expectedBalances": [], + "comment": "deploy write protection contract" + }], + "executions": [{ + "rawPrivateKey": "cfa6ef757dee2e50351620dca002d32b9c090cfda55fb81f37f1d26b273743f1", + "rawByteCode": "c6dad082", + "rawAmount": "0", + "rawGasLimit": 1000000, + "rawGasPrice": "0", + "rawAccessList": [], + "rawExpectedGasConsumed": 292990, + "expectedStatus": 1, + "hasReturnValue": true, + "rawReturnValue": "", + "comment": "call make" + }, { + "rawPrivateKey": "cfa6ef757dee2e50351620dca002d32b9c090cfda55fb81f37f1d26b273743f1", + "rawByteCode": "d1e0f30800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000084", + "rawAmount": "0", + "rawGasLimit": 6000000, + "rawGasPrice": "0", + "rawAccessList": [], + "rawExpectedGasConsumed": 5892833, + "expectedStatus": 1, + "expectedLogs": [{}], + "hasReturnValue": true, + "rawReturnValue": "", + "comment": "call setVars" + }] +} \ No newline at end of file diff --git a/action/protocol/execution/testdata-istanbul/write-protection-005.sol b/action/protocol/execution/testdata-istanbul/write-protection-005.sol new file mode 100644 index 0000000000..03793b947d --- /dev/null +++ b/action/protocol/execution/testdata-istanbul/write-protection-005.sol @@ -0,0 +1,56 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.6.6; + +// NOTE: Deploy this contract first +contract B { + // NOTE: storage layout must be the same as contract A + uint public num; + address public sender; + uint public value; + mapping(uint => uint) private _a; + event Done(); + + constructor() public { + _a[1] = 1; + _a[2] = 2; + _a[3] = 3; + } + + function setVars(uint _num) public payable { + delete _a[1]; + delete _a[2]; + num = _num; + sender = msg.sender; + value = msg.value; + emit Done(); + } +} + +contract A { + uint public num; + address public sender; + uint public value; + address private c; + mapping(uint => uint) private _a; + event Success(bool); + + function make() public { + c = address(new B()); + _a[1] = 1; + _a[2] = 2; + _a[3] = 3; + } + + function setVars(address _contract, uint _num) public returns (uint256) { + if (_contract == address(0)) { + _contract = c; + } + delete _a[1]; + (bool success, bytes memory _) = _contract.staticcall( + abi.encodeWithSignature("setVars(uint256)", _num) + ); + emit Success(success); + + return 1; + } +} \ No newline at end of file diff --git a/action/protocol/execution/testdata-istanbul/write-protection-006.json b/action/protocol/execution/testdata-istanbul/write-protection-006.json new file mode 100644 index 0000000000..f41e411d7f --- /dev/null +++ b/action/protocol/execution/testdata-istanbul/write-protection-006.json @@ -0,0 +1,47 @@ +{ + "initGenesis": { + "isBering" : true, + "isIceland" : true + }, + "initBalances": [{ + "account": "io1mflp9m6hcgm2qcghchsdqj3z3eccrnekx9p0ms", + "rawBalance": "1000000000000000000000000000" + }], + "deployments": [{ + "rawByteCode": "608060405234801561001057600080fd5b5061085f806100206000396000f3fe608060405234801561001057600080fd5b50600436106100575760003560e01c80633fa4f2451461005c5780634e70b1dc1461007a57806367e404ce14610098578063c6dad082146100cc578063d1e0f308146100d6575b600080fd5b610064610138565b6040518082815260200191505060405180910390f35b61008261013e565b6040518082815260200191505060405180910390f35b6100a0610144565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6100d461016a565b005b610122600480360360408110156100ec57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610223565b6040518082815260200191505060405180910390f35b60025481565b60005481565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60405161017690610564565b604051809103906000f080158015610192573d6000803e3d6000fd5b50600360006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550600160046000600181526020019081526020016000208190555060026004600060028152602001908152602001600020819055506003600460006003815260200190815260200160002081905550565b60008073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16141561027f57600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1692505b600460006001815260200190815260200160002060009055600060608473ffffffffffffffffffffffffffffffffffffffff166000604051602401808281526020019150506040516020818303038152906040527f6466414b000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506040518082805190602001908083835b602083106103745780518252602082019150602081019050602083039250610351565b6001836020036101000a038019825116818451168082178552505050505050905001915050600060405180830381855afa9150503d80600081146103d4576040519150601f19603f3d011682016040523d82523d6000602084013e6103d9565b606091505b50915091508473ffffffffffffffffffffffffffffffffffffffff166001604051602401808281526020019150506040516020818303038152906040527f6466414b000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506040518082805190602001908083835b602083106104b75780518252602082019150602081019050602083039250610494565b6001836020036101000a038019825116818451168082178552505050505050905001915050600060405180830381855afa9150503d8060008114610517576040519150601f19603f3d011682016040523d82523d6000602084013e61051c565b606091505b5050507f3b0a8ddef325df2bfdfa6b430ae4c8421841cd135bfa8fb5e432f200787520bb8260405180821515815260200191505060405180910390a160019250505092915050565b6102b8806105728339019056fe608060405234801561001057600080fd5b50600160036000600181526020019081526020016000208190555060026003600060028152602001908152602001600020819055506003806000600381526020019081526020016000208190555061024b8061006d6000396000f3fe60806040526004361061003f5760003560e01c80633fa4f245146100445780634e70b1dc1461006f5780636466414b1461009a57806367e404ce146100c8575b600080fd5b34801561005057600080fd5b50610059610109565b6040518082815260200191505060405180910390f35b34801561007b57600080fd5b5061008461010f565b6040518082815260200191505060405180910390f35b6100c6600480360360208110156100b057600080fd5b8101908080359060200190929190505050610115565b005b3480156100d457600080fd5b506100dd6101ef565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b60025481565b60005481565b6000811415610137576003600060018152602001908152602001600020600090555b6001811415610171576003600060028152602001908152602001600020600090556003600060038152602001908152602001600020600090555b8060008190555033600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550346002819055507f9f9fb434574749b74458e0ddc3cf5fd5bdb1b009c8615e825606b53724576f3560405160405180910390a150565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168156fea264697066735822122009b5ec84302a1938719a08f09339ac7d557b8b290809ec858ce9990a981a150264736f6c634300060c0033a26469706673582212208d071608c49282e25d608344746485c98fa372cb26b171d2a3306030ba1ebdf964736f6c634300060c0033", + "rawPrivateKey": "cfa6ef757dee2e50351620dca002d32b9c090cfda55fb81f37f1d26b273743f1", + "rawAmount": "0", + "rawGasLimit": 5000000, + "rawGasPrice": "0", + "rawExpectedGasConsumed": 656561, + "expectedStatus": 1, + "expectedBalances": [], + "comment": "deploy write protection contract" + }], + "executions": [{ + "rawPrivateKey": "cfa6ef757dee2e50351620dca002d32b9c090cfda55fb81f37f1d26b273743f1", + "rawByteCode": "c6dad082", + "rawAmount": "0", + "rawGasLimit": 1000000, + "rawGasPrice": "0", + "rawAccessList": [], + "rawExpectedGasConsumed": 301808, + "expectedStatus": 1, + "hasReturnValue": true, + "rawReturnValue": "", + "comment": "call make" + }, { + "rawPrivateKey": "cfa6ef757dee2e50351620dca002d32b9c090cfda55fb81f37f1d26b273743f1", + "rawByteCode": "d1e0f30800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000084", + "rawAmount": "0", + "rawGasLimit": 6000000, + "rawGasPrice": "0", + "rawAccessList": [], + "rawExpectedGasConsumed": 5984758, + "expectedStatus": 1, + "expectedLogs": [{}], + "hasReturnValue": true, + "rawReturnValue": "", + "comment": "call setVars" + }] +} \ No newline at end of file diff --git a/action/protocol/execution/testdata-istanbul/write-protection-006.sol b/action/protocol/execution/testdata-istanbul/write-protection-006.sol new file mode 100644 index 0000000000..788b4129ba --- /dev/null +++ b/action/protocol/execution/testdata-istanbul/write-protection-006.sol @@ -0,0 +1,65 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.6.6; + +// NOTE: Deploy this contract first +contract B { + // NOTE: storage layout must be the same as contract A + uint public num; + address public sender; + uint public value; + mapping(uint => uint) private _a; + event Done(); + + constructor() public { + _a[1] = 1; + _a[2] = 2; + _a[3] = 3; + } + + function setVars(uint _num) public payable { + if (_num == 0) { + delete _a[1]; + } + if (_num == 1) { + delete _a[2]; + delete _a[3]; + } + num = _num; + sender = msg.sender; + value = msg.value; + emit Done(); + } +} + +contract A { + uint public num; + address public sender; + uint public value; + address private c; + mapping(uint => uint) private _a; + event Success(bool); + + function make() public { + c = address(new B()); + _a[1] = 1; + _a[2] = 2; + _a[3] = 3; + } + + function setVars(address _contract, uint _num) public returns (uint256) { + if (_contract == address(0)) { + _contract = c; + } + delete _a[1]; + (bool success, bytes memory _) = _contract.staticcall( + abi.encodeWithSignature("setVars(uint256)", 0) + ); + _contract.staticcall( + abi.encodeWithSignature("setVars(uint256)", 1) + ); + + emit Success(success); + + return 1; + } +} \ No newline at end of file diff --git a/action/protocol/execution/testdata-istanbul/write-protection-007.json b/action/protocol/execution/testdata-istanbul/write-protection-007.json new file mode 100644 index 0000000000..ecc1a74244 --- /dev/null +++ b/action/protocol/execution/testdata-istanbul/write-protection-007.json @@ -0,0 +1,47 @@ +{ + "initGenesis": { + "isBering" : true, + "isIceland" : true + }, + "initBalances": [{ + "account": "io1mflp9m6hcgm2qcghchsdqj3z3eccrnekx9p0ms", + "rawBalance": "1000000000000000000000000000" + }], + "deployments": [{ + "rawByteCode": "608060405234801561001057600080fd5b506107ef806100206000396000f3fe608060405234801561001057600080fd5b50600436106100575760003560e01c80633fa4f2451461005c5780634e70b1dc1461007a57806367e404ce14610098578063c6dad082146100cc578063d1e0f308146100d6575b600080fd5b610064610138565b6040518082815260200191505060405180910390f35b61008261013e565b6040518082815260200191505060405180910390f35b6100a0610144565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6100d461016a565b005b610122600480360360408110156100ec57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506101d5565b6040518082815260200191505060405180910390f35b60025481565b60005481565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b604051610176906104fe565b604051809103906000f080158015610192573d6000803e3d6000fd5b50600360006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b60008073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16141561023157600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1692505b8273ffffffffffffffffffffffffffffffffffffffff166000604051602401808281526020019150506040516020818303038152906040527f6466414b000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506040518082805190602001908083835b6020831061030a57805182526020820191506020810190506020830392506102e7565b6001836020036101000a038019825116818451168082178552505050505050905001915050600060405180830381855afa9150503d806000811461036a576040519150601f19603f3d011682016040523d82523d6000602084013e61036f565b606091505b505050600060608473ffffffffffffffffffffffffffffffffffffffff166001604051602401808281526020019150506040516020818303038152906040527f6466414b000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506040518082805190602001908083835b6020831061044f578051825260208201915060208101905060208303925061042c565b6001836020036101000a038019825116818451168082178552505050505050905001915050600060405180830381855afa9150503d80600081146104af576040519150601f19603f3d011682016040523d82523d6000602084013e6104b4565b606091505b50915091507f3b0a8ddef325df2bfdfa6b430ae4c8421841cd135bfa8fb5e432f200787520bb8260405180821515815260200191505060405180910390a160019250505092915050565b6102ae8061050c8339019056fe608060405234801561001057600080fd5b5060016003600060018152602001908152602001600020819055506002600360006002815260200190815260200160002081905550600380600060038152602001908152602001600020819055506102418061006d6000396000f3fe60806040526004361061003f5760003560e01c80633fa4f245146100445780634e70b1dc1461006f5780636466414b1461009a57806367e404ce146100c8575b600080fd5b34801561005057600080fd5b50610059610109565b6040518082815260200191505060405180910390f35b34801561007b57600080fd5b5061008461010f565b6040518082815260200191505060405180910390f35b6100c6600480360360208110156100b057600080fd5b8101908080359060200190929190505050610115565b005b3480156100d457600080fd5b506100dd6101e5565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b60025481565b60005481565b6001811415610167576003600060018152602001908152602001600020600090556003600060028152602001908152602001600020600090556003600060038152602001908152602001600020600090555b8060008190555033600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550346002819055507f9f9fb434574749b74458e0ddc3cf5fd5bdb1b009c8615e825606b53724576f3560405160405180910390a150565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168156fea2646970667358221220f2d48bf08b7f12e65e149a3df51a95281e5a3c338fce925b3c1ec23ea4b6f70064736f6c634300060c0033a264697066735822122001f8b9b6577392a0576c69f38e752f1ad7a8d2529223ab724158f4fa99a3a44664736f6c634300060c0033", + "rawPrivateKey": "cfa6ef757dee2e50351620dca002d32b9c090cfda55fb81f37f1d26b273743f1", + "rawAmount": "0", + "rawGasLimit": 5000000, + "rawGasPrice": "0", + "rawExpectedGasConsumed": 622943, + "expectedStatus": 1, + "expectedBalances": [], + "comment": "deploy write protection contract" + }], + "executions": [{ + "rawPrivateKey": "cfa6ef757dee2e50351620dca002d32b9c090cfda55fb81f37f1d26b273743f1", + "rawByteCode": "c6dad082", + "rawAmount": "0", + "rawGasLimit": 1000000, + "rawGasPrice": "0", + "rawAccessList": [], + "rawExpectedGasConsumed": 239532, + "expectedStatus": 1, + "hasReturnValue": true, + "rawReturnValue": "", + "comment": "call make" + }, { + "rawPrivateKey": "cfa6ef757dee2e50351620dca002d32b9c090cfda55fb81f37f1d26b273743f1", + "rawByteCode": "d1e0f30800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000084", + "rawAmount": "0", + "rawGasLimit": 6000000, + "rawGasPrice": "0", + "rawAccessList": [], + "rawExpectedGasConsumed": 5999763, + "expectedStatus": 1, + "expectedLogs": [{}], + "hasReturnValue": true, + "rawReturnValue": "", + "comment": "call setVars" + }] +} \ No newline at end of file diff --git a/action/protocol/execution/testdata-istanbul/write-protection-007.sol b/action/protocol/execution/testdata-istanbul/write-protection-007.sol new file mode 100644 index 0000000000..9ca58a903a --- /dev/null +++ b/action/protocol/execution/testdata-istanbul/write-protection-007.sol @@ -0,0 +1,58 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.6.6; + +// NOTE: Deploy this contract first +contract B { + // NOTE: storage layout must be the same as contract A + uint public num; + address public sender; + uint public value; + mapping(uint => uint) private _a; + event Done(); + + constructor() public { + _a[1] = 1; + _a[2] = 2; + _a[3] = 3; + } + + function setVars(uint _num) public payable { + if (_num == 1) { + delete _a[1]; + delete _a[2]; + delete _a[3]; + } + num = _num; + sender = msg.sender; + value = msg.value; + emit Done(); + } +} + +contract A { + uint public num; + address public sender; + uint public value; + address private c; + event Success(bool); + + function make() public { + c = address(new B()); + } + + function setVars(address _contract, uint _num) public returns (uint256) { + if (_contract == address(0)) { + _contract = c; + } + _contract.staticcall( + abi.encodeWithSignature("setVars(uint256)", 0) + ); + (bool success, bytes memory _) = _contract.staticcall( + abi.encodeWithSignature("setVars(uint256)", 1) + ); + + emit Success(success); + + return 1; + } +} \ No newline at end of file diff --git a/action/protocol/execution/testdata-istanbul/write-protection.json b/action/protocol/execution/testdata-istanbul/write-protection.json new file mode 100644 index 0000000000..1f9486df1c --- /dev/null +++ b/action/protocol/execution/testdata-istanbul/write-protection.json @@ -0,0 +1,47 @@ +{ + "initGenesis": { + "isBering" : true, + "isIceland" : true + }, + "initBalances": [{ + "account": "io1mflp9m6hcgm2qcghchsdqj3z3eccrnekx9p0ms", + "rawBalance": "1000000000000000000000000000" + }], + "deployments": [{ + "rawByteCode": "608060405234801561001057600080fd5b506109ee806100206000396000f3fe608060405234801561001057600080fd5b50600436106100625760003560e01c8063167517ce146100675780633fa4f245146100b55780634e70b1dc146100d357806367e404ce146100f1578063c6dad0821461013b578063d1e0f30814610145575b600080fd5b6100b36004803603604081101561007d57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506101a7565b005b6100bd6104f2565b6040518082815260200191505060405180910390f35b6100db6104f8565b6040518082815260200191505060405180910390f35b6100f96104fe565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b610143610524565b005b6101916004803603604081101561015b57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506105dd565b6040518082815260200191505060405180910390f35b6000811415610318578173ffffffffffffffffffffffffffffffffffffffff166040516024016040516020818303038152906040527fef2d5a06000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506040518082805190602001908083835b6020831061027d578051825260208201915060208101905060208303925061025a565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d80600081146102df576040519150601f19603f3d011682016040523d82523d6000602084013e6102e4565b606091505b5050506004600060018152602001908152602001600020600090556004600060028152602001908152602001600020600090555b600181141561033a576004600060038152602001908152602001600020600090555b600060608373ffffffffffffffffffffffffffffffffffffffff1683604051602401808281526020019150506040516020818303038152906040527f6466414b000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506040518082805190602001908083835b6020831061041657805182526020820191506020810190506020830392506103f3565b6001836020036101000a038019825116818451168082178552505050505050905001915050600060405180830381855afa9150503d8060008114610476576040519150601f19603f3d011682016040523d82523d6000602084013e61047b565b606091505b50915091507f3b0a8ddef325df2bfdfa6b430ae4c8421841cd135bfa8fb5e432f200787520bb82604051808215151515815260200191505060405180910390a160008314156104c957600080fd5b60018314156104ec57600073ffffffffffffffffffffffffffffffffffffffff16ff5b50505050565b60025481565b60005481565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60405161053090610786565b604051809103906000f08015801561054c573d6000803e3d6000fd5b50600360006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550600160046000600181526020019081526020016000208190555060026004600060028152602001908152602001600020819055506003600460006003815260200190815260200160002081905550565b60008073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16141561063957600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1692505b3073ffffffffffffffffffffffffffffffffffffffff1663167517ce8460006040518363ffffffff1660e01b8152600401808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050600060405180830381600087803b1580156106c157600080fd5b505af19250505080156106d2575060015b61077b573073ffffffffffffffffffffffffffffffffffffffff1663167517ce8460016040518363ffffffff1660e01b8152600401808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050600060405180830381600087803b15801561075e57600080fd5b505af1158015610772573d6000803e3d6000fd5b5050505061077c565b5b6001905092915050565b610225806107948339019056fe608060405234801561001057600080fd5b50610205806100206000396000f3fe60806040526004361061003f5760003560e01c80633fa4f245146100445780634e70b1dc1461006f5780636466414b1461009a57806367e404ce146100c8575b600080fd5b34801561005057600080fd5b5061005961011f565b6040518082815260200191505060405180910390f35b34801561007b57600080fd5b50610084610125565b6040518082815260200191505060405180910390f35b6100c6600480360360208110156100b057600080fd5b810190808035906020019092919050505061012b565b005b3480156100d457600080fd5b506100dd6101a9565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b60025481565b60005481565b8060008190555033600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550346002819055507f9f9fb434574749b74458e0ddc3cf5fd5bdb1b009c8615e825606b53724576f3560405160405180910390a150565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168156fea26469706673582212202e67af82318b53375dfe61da156020a65f6cb401451253654bc9ca6a926020a264736f6c634300060b0033a264697066735822122080b9539d179f05ecca679f9cb77ab1c2276b5fb07502ce342f76cb84d2111aa564736f6c634300060b0033", + "rawPrivateKey": "cfa6ef757dee2e50351620dca002d32b9c090cfda55fb81f37f1d26b273743f1", + "rawAmount": "0", + "rawGasLimit": 5000000, + "rawGasPrice": "0", + "rawExpectedGasConsumed": 776343, + "expectedStatus": 1, + "expectedBalances": [], + "comment": "deploy write protection contract" + }], + "executions": [{ + "rawPrivateKey": "cfa6ef757dee2e50351620dca002d32b9c090cfda55fb81f37f1d26b273743f1", + "rawByteCode": "c6dad082", + "rawAmount": "0", + "rawGasLimit": 1000000, + "rawGasPrice": "0", + "rawAccessList": [], + "rawExpectedGasConsumed": 227517, + "expectedStatus": 1, + "hasReturnValue": true, + "rawReturnValue": "", + "comment": "call make" + }, { + "rawPrivateKey": "cfa6ef757dee2e50351620dca002d32b9c090cfda55fb81f37f1d26b273743f1", + "rawByteCode": "d1e0f30800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000084", + "rawAmount": "0", + "rawGasLimit": 6000000, + "rawGasPrice": "0", + "rawAccessList": [], + "rawExpectedGasConsumed": 5928188, + "expectedStatus": 106, + "expectedLogs": [{},{}], + "hasReturnValue": true, + "rawReturnValue": "", + "comment": "call make" + }] +} \ No newline at end of file diff --git a/action/protocol/execution/testdata-istanbul/write-protection.sol b/action/protocol/execution/testdata-istanbul/write-protection.sol new file mode 100644 index 0000000000..c20f3f719e --- /dev/null +++ b/action/protocol/execution/testdata-istanbul/write-protection.sol @@ -0,0 +1,72 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.6.6; + +// NOTE: Deploy this contract first +contract B { + // NOTE: storage layout must be the same as contract A + uint public num; + address public sender; + uint public value; + event Done(); + + function setVars(uint _num) public payable { + num = _num; + sender = msg.sender; + value = msg.value; + emit Done(); + } +} + +contract A { + uint public num; + address public sender; + uint public value; + address private c; + mapping(uint => uint) private _a; + event Success(bool); + + function make() public { + c = address(new B()); + _a[1] = 1; + _a[2] = 2; + _a[3] = 3; + } + + function callStatic(address _contract,uint _num) public { + if (_num == 0) { + _contract.call( + abi.encodeWithSignature("notfund()") + ); + delete _a[1]; + delete _a[2]; + } + if (_num == 1) { + delete _a[3]; + } + (bool success, bytes memory _) = _contract.staticcall( + abi.encodeWithSignature("setVars(uint256)", _num) + ); + emit Success(success); + if (_num == 0) { + revert(); + } + if (_num == 1) { + selfdestruct(address(0)); + } + // 0x0000000000000000000000000000000000000000.call( + // abi.encodeWithSignature("notfund()") + // ); + } + + function setVars(address _contract, uint _num) public returns (uint256) { + if (_contract == address(0)) { + _contract = c; + } + try this.callStatic(_contract,0) { + } catch { + this.callStatic(_contract,1); + } + + return 1; + } +} \ No newline at end of file diff --git a/go.mod b/go.mod index 4a6d0f71ba..0f618a277b 100644 --- a/go.mod +++ b/go.mod @@ -65,7 +65,7 @@ require ( github.com/benbjohnson/clock v1.0.3 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/btcsuite/btcd v0.21.0-beta // indirect - github.com/btcsuite/btcd/btcec/v2 v2.2.0 // indirect + github.com/btcsuite/btcd/btcec/v2 v2.1.2 // indirect github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce // indirect github.com/cespare/xxhash/v2 v2.1.2 // indirect github.com/davecgh/go-spew v1.1.1 // indirect @@ -200,6 +200,6 @@ require ( gopkg.in/yaml.v3 v3.0.1 // indirect ) -replace github.com/ethereum/go-ethereum => github.com/iotexproject/go-ethereum v0.4.1 +replace github.com/ethereum/go-ethereum => github.com/iotexproject/go-ethereum v1.7.4-0.20221123031803-9e576f7b3e4b replace golang.org/x/xerrors => golang.org/x/xerrors v0.0.0-20190212162355-a5947ffaace3 diff --git a/go.sum b/go.sum index 395fc7b1a3..d7afac391c 100644 --- a/go.sum +++ b/go.sum @@ -103,9 +103,8 @@ github.com/btcsuite/btcd v0.0.0-20190824003749-130ea5bddde3/go.mod h1:3J08xEfcug github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ= github.com/btcsuite/btcd v0.21.0-beta h1:At9hIZdJW0s9E/fAz28nrz6AmcNlSVucCH796ZteX1M= github.com/btcsuite/btcd v0.21.0-beta/go.mod h1:ZSWyehm27aAuS9bvkATT+Xte3hjHZ+MRgMY/8NJ7K94= +github.com/btcsuite/btcd/btcec/v2 v2.1.2 h1:YoYoC9J0jwfukodSBMzZYUVQ8PTiYg4BnOWiJVzTmLs= github.com/btcsuite/btcd/btcec/v2 v2.1.2/go.mod h1:ctjw4H1kknNJmRN4iP1R7bTQ+v3GJkZBd6mui8ZsAZE= -github.com/btcsuite/btcd/btcec/v2 v2.2.0 h1:fzn1qaOt32TuLjFlkzYSsBC35Q3KUjT1SwPxiMSCF5k= -github.com/btcsuite/btcd/btcec/v2 v2.2.0/go.mod h1:U7MHm051Al6XmscBQ0BoNydpOTsFAn707034b5nY8zU= github.com/btcsuite/btcd/chaincfg/chainhash v1.0.0/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc= github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA= github.com/btcsuite/btcutil v0.0.0-20190207003914-4c204d697803/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg= @@ -487,8 +486,8 @@ github.com/influxdata/promql/v2 v2.12.0/go.mod h1:fxOPu+DY0bqCTCECchSRtWfc+0X19y github.com/influxdata/roaring v0.4.13-0.20180809181101-fc520f41fab6/go.mod h1:bSgUQ7q5ZLSO+bKBGqJiCBGAl+9DxyW63zLTujjUlOE= github.com/influxdata/tdigest v0.0.0-20181121200506-bf2b5ad3c0a9/go.mod h1:Js0mqiSBE6Ffsg94weZZ2c+v/ciT8QRHFOap7EKDrR0= github.com/influxdata/usage-client v0.0.0-20160829180054-6d3895376368/go.mod h1:Wbbw6tYNvwa5dlB6304Sd+82Z3f7PmVZHVKU637d4po= -github.com/iotexproject/go-ethereum v0.4.1 h1:8IdCOiMsuJQJl39ipBha0P+NMA60sqxAeYNiQVeshT4= -github.com/iotexproject/go-ethereum v0.4.1/go.mod h1:Lt5WzjM07XlXc95YzrhosmR4J9Ahd6X2wyEV2SvGhk0= +github.com/iotexproject/go-ethereum v1.7.4-0.20221123031803-9e576f7b3e4b h1:ImtTdFM8yaH8mYL4sd4idxHiV5J0r12B1SYiyBezdCs= +github.com/iotexproject/go-ethereum v1.7.4-0.20221123031803-9e576f7b3e4b/go.mod h1:Lt5WzjM07XlXc95YzrhosmR4J9Ahd6X2wyEV2SvGhk0= github.com/iotexproject/go-fsm v1.0.0 h1:Zrg9JnNDUZg4Anpj6oa0Tk4+sXbHTpJzI0v5/Cj5N6A= github.com/iotexproject/go-fsm v1.0.0/go.mod h1:t3aYXtCCcQxyS7oduQZyuUpPnVI4ddFTwbAagHN7fT0= github.com/iotexproject/go-p2p v0.3.5 h1:F71XxYQtR25youD+dCXnMgtfiCKGUFh8KDIqU7u5xOk=