Merge pull request #8856 from ethereum/implicitConstructorCallvalueCheck

Implicit constructor callvalue check
This commit is contained in:
Daniel Kirchner
2020-05-11 18:50:36 +02:00
committed by GitHub
8 changed files with 169 additions and 4 deletions
@@ -0,0 +1,40 @@
contract A1 { constructor() public {} }
contract B1 is A1 {}
contract A2 { constructor() public payable {} }
contract B2 is A2 {}
contract B3 {}
contract B4 { constructor() public {} }
contract C {
function createWithValue(bytes memory c, uint256 value) public payable returns (bool) {
uint256 y = 0;
assembly { y := create(value, add(c, 0x20), mload(c)) }
return y != 0;
}
function f(uint256 value) public payable returns (bool) {
return createWithValue(type(B1).creationCode, value);
}
function g(uint256 value) public payable returns (bool) {
return createWithValue(type(B2).creationCode, value);
}
function h(uint256 value) public payable returns (bool) {
return createWithValue(type(B3).creationCode, value);
}
function i(uint256 value) public payable returns (bool) {
return createWithValue(type(B4).creationCode, value);
}
}
// ====
// EVMVersion: >homestead
// ----
// f(uint256), 2000 ether: 0 -> true
// f(uint256), 2000 ether: 100 -> false
// g(uint256), 2000 ether: 0 -> true
// g(uint256), 2000 ether: 100 -> false
// h(uint256), 2000 ether: 0 -> true
// h(uint256), 2000 ether: 100 -> false
// i(uint256), 2000 ether: 0 -> true
// i(uint256), 2000 ether: 100 -> false
@@ -0,0 +1,21 @@
contract A1 {}
contract B1 is A1 { constructor() public payable {} }
contract A2 { constructor() public {} }
contract B2 is A2 { constructor() public payable {} }
contract B3 { constructor() public payable {} }
contract C {
function f() public payable returns (bool) {
// Make sure none of these revert.
new B1{value: 10}();
new B2{value: 10}();
new B3{value: 10}();
return true;
}
}
// ====
// compileViaYul: also
// ----
// f(), 2000 ether -> true