mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #10605 from ethereum/develop
Merge develop into breaking.
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
pragma abicoder v2;
|
||||
contract Test {
|
||||
function f(uint256[] calldata c) internal returns (uint a, uint b) {
|
||||
return (c.length, c[0]);
|
||||
}
|
||||
|
||||
function g(uint256[] calldata c) external returns (uint a, uint b) {
|
||||
return f(c);
|
||||
}
|
||||
|
||||
function h(uint256[] calldata c, uint start, uint end) external returns (uint a, uint b) {
|
||||
return f(c[start: end]);
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// g(uint256[]): 0x20, 4, 1, 2, 3, 4 -> 4, 1
|
||||
// h(uint256[], uint256, uint256): 0x60, 1, 3, 4, 1, 2, 3, 4 -> 2, 2
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
contract C {
|
||||
function f1(bytes calldata c1, uint256 s, uint256 e, bytes calldata c2) public returns (bool) {
|
||||
return keccak256(c1[s:e]) == keccak256(c2);
|
||||
}
|
||||
|
||||
function f2(bytes calldata c, uint256 s) public returns (uint256, bytes memory) {
|
||||
return abi.decode(c[s:], (uint256, bytes));
|
||||
}
|
||||
|
||||
function f3(bytes calldata c1, uint256 s, uint256 e, bytes calldata c2) public returns (bool) {
|
||||
bytes memory a = abi.encode(c1[s:e]);
|
||||
bytes memory b = abi.encode(c2);
|
||||
if (a.length != b.length) { return false; }
|
||||
for (uint256 i = 0; i < a.length; i++) {
|
||||
if (a[i] != b[i]) { return false; }
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function f4(bytes calldata c1, uint256 s, uint256 e, bytes calldata c2) public returns (bool) {
|
||||
bytes memory a = abi.encodePacked(c1[s:e]);
|
||||
bytes memory b = abi.encodePacked(c2);
|
||||
if (a.length != b.length) { return false; }
|
||||
for (uint256 i = 0; i < a.length; i++) {
|
||||
if (a[i] != b[i]) { return false; }
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f1(bytes,uint256,uint256,bytes): 0x80, 1, 5, 0xC0, 8, "abcdefgh", 4, "bcde" -> true
|
||||
// f1(bytes,uint256,uint256,bytes): 0x80, 1, 5, 0xC0, 8, "abcdefgh", 4, "bcdf" -> false
|
||||
// f2(bytes,uint256): 0x40, 0, 0x80, 0x21, 0x40, 0x7, "abcdefg" -> 0x21, 0x40, 0x7, "abcdefg"
|
||||
// f3(bytes,uint256,uint256,bytes): 0x80, 1, 5, 0xC0, 8, "abcdefgh", 4, "bcde" -> true
|
||||
// f3(bytes,uint256,uint256,bytes): 0x80, 1, 5, 0xC0, 8, "abcdefgh", 4, "bcdf" -> false
|
||||
// f4(bytes,uint256,uint256,bytes): 0x80, 1, 5, 0xC0, 8, "abcdefgh", 4, "bcde" -> true
|
||||
// f4(bytes,uint256,uint256,bytes): 0x80, 1, 5, 0xC0, 8, "abcdefgh", 4, "bcdf" -> false
|
||||
@@ -0,0 +1,27 @@
|
||||
pragma abicoder v2;
|
||||
|
||||
contract C {
|
||||
struct S {
|
||||
uint128 p1;
|
||||
uint256[3] a;
|
||||
uint32 p2;
|
||||
}
|
||||
function f(S[] calldata c) internal returns (S[] memory) {
|
||||
return c;
|
||||
}
|
||||
function g(S[] calldata c, uint256 s, uint256 e) public returns (S[] memory) {
|
||||
return f(c[s:e]);
|
||||
}
|
||||
|
||||
function f1(uint256[3][] calldata c) internal returns (uint256[3][] memory) {
|
||||
return c;
|
||||
}
|
||||
function g1(uint256[3][] calldata c, uint256 s, uint256 e) public returns (uint256[3][] memory) {
|
||||
return f1(c[s:e]);
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// g((uint128, uint256[3], uint32)[], uint256, uint256): 0x60, 1, 3, 4, 55, 1, 2, 3, 66, 66, 2, 3, 4, 77, 77, 3, 4, 5, 88, 88, 4, 5, 6, 99 -> 0x20, 2, 66, 2, 3, 4, 77, 77, 3, 4, 5, 88
|
||||
// g1(uint256[3][], uint256, uint256): 0x60, 1, 3, 4, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 -> 0x20, 2, 4, 5, 6, 7, 8, 9
|
||||
@@ -0,0 +1,29 @@
|
||||
contract C {
|
||||
function f(int[] calldata b, uint256 start, uint256 end) public returns (int) {
|
||||
int[] memory m = b[start:end];
|
||||
uint len = end - start;
|
||||
assert(len == m.length);
|
||||
for (uint i = 0; i < len; i++) {
|
||||
assert(b[start:end][i] == m[i]);
|
||||
}
|
||||
return [b[start:end]][0][0];
|
||||
}
|
||||
|
||||
function g(int[] calldata b, uint256 start, uint256 end) public returns (int[] memory) {
|
||||
return b[start:end];
|
||||
}
|
||||
|
||||
function h1(int[] memory b) internal returns (int[] memory) {
|
||||
return b;
|
||||
}
|
||||
|
||||
function h(int[] calldata b, uint256 start, uint256 end) public returns (int[] memory) {
|
||||
return h1(b[start:end]);
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f(int256[], uint256, uint256): 0x60, 1, 3, 4, 1, 2, 3, 4 -> 2
|
||||
// g(int256[], uint256, uint256): 0x60, 1, 3, 4, 1, 2, 3, 4 -> 0x20, 2, 2, 3
|
||||
// h(int256[], uint256, uint256): 0x60, 1, 3, 4, 1, 2, 3, 4 -> 0x20, 2, 2, 3
|
||||
@@ -0,0 +1,16 @@
|
||||
contract C {
|
||||
int[] s;
|
||||
function f(int[] calldata b, uint256 start, uint256 end) public returns (int) {
|
||||
s = b[start:end];
|
||||
uint len = end - start;
|
||||
assert(len == s.length);
|
||||
for (uint i = 0; i < len; i++) {
|
||||
assert(b[start:end][i] == s[i]);
|
||||
}
|
||||
return s[0];
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f(int256[], uint256, uint256): 0x60, 1, 3, 4, 1, 2, 3, 4 -> 2
|
||||
@@ -0,0 +1,16 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
bytes b;
|
||||
function f() public {
|
||||
b.push() = b.push();
|
||||
uint length = b.length;
|
||||
assert(length >= 2);
|
||||
assert(b[length - 1] == 0);
|
||||
assert(b[length - 1] == b[length - 2]);
|
||||
// Fails
|
||||
assert(b[length - 1] == byte(uint8(1)));
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning 6328: (236-275): CHC: Assertion violation happens here.\nCounterexample:\nb = [0, 0]\n\n\n\nTransaction trace:\nconstructor()\nState: b = []\nf()
|
||||
@@ -0,0 +1,22 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
bytes b;
|
||||
|
||||
function f() public {
|
||||
require(b.length == 0);
|
||||
b.push() = byte(uint8(1));
|
||||
assert(b[0] == byte(uint8(1)));
|
||||
}
|
||||
|
||||
function g() public {
|
||||
byte one = byte(uint8(1));
|
||||
b.push() = one;
|
||||
assert(b[b.length - 1] == one);
|
||||
// Fails
|
||||
assert(b[b.length - 1] == byte(uint8(100)));
|
||||
}
|
||||
|
||||
}
|
||||
// ----
|
||||
// Warning 6328: (290-333): CHC: Assertion violation happens here.\nCounterexample:\nb = [1]\n\n\n\nTransaction trace:\nconstructor()\nState: b = []\ng()
|
||||
@@ -0,0 +1,26 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
bytes[] c;
|
||||
|
||||
function f() public {
|
||||
bytes1 val = bytes1(uint8(2));
|
||||
require(c.length == 0);
|
||||
c.push().push() = val;
|
||||
assert(c.length == 1);
|
||||
assert(c[0].length == 1);
|
||||
assert(c[0][0] == val);
|
||||
}
|
||||
|
||||
function g() public {
|
||||
bytes1 val = bytes1(uint8(2));
|
||||
c.push().push() = val;
|
||||
assert(c.length > 0);
|
||||
assert(c[c.length - 1].length == 1);
|
||||
assert(c[c.length - 1][c[c.length - 1].length - 1] == val);
|
||||
// Fails
|
||||
assert(c[c.length - 1][c[c.length - 1].length - 1] == bytes1(uint8(100)));
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning 6328: (468-541): CHC: Assertion violation happens here.\nCounterexample:\nc = [[2]]\n\n\n\nTransaction trace:\nconstructor()\nState: c = []\ng()
|
||||
@@ -0,0 +1,15 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
uint x;
|
||||
function f() public {
|
||||
x = 0;
|
||||
((inc))();
|
||||
assert(x == 1); // should hold
|
||||
}
|
||||
|
||||
function inc() internal returns (uint) {
|
||||
require(x < 100);
|
||||
return ++x;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
library L {
|
||||
struct S {
|
||||
uint256[] data;
|
||||
}
|
||||
function f(S memory _s) internal pure returns (uint256) {
|
||||
require(_s.data.length > 0);
|
||||
return 42;
|
||||
}
|
||||
}
|
||||
|
||||
contract C {
|
||||
using L for L.S;
|
||||
function f() public pure returns (uint256 y) {
|
||||
L.S memory x;
|
||||
y = (x.f)();
|
||||
assert(y == 42); // should hold
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning 6031: (289-292): Internal error: Expression undefined for SMT solver.
|
||||
// Warning 6031: (289-292): Internal error: Expression undefined for SMT solver.
|
||||
@@ -0,0 +1,6 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
abstract contract A {
|
||||
function f() public mod {}
|
||||
modifier mod virtual;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
pragma experimental SMTChecker;
|
||||
contract C {
|
||||
uint[] x;
|
||||
function f() public {
|
||||
require(x.length == 0);
|
||||
++x.push();
|
||||
assert(x.length == 1);
|
||||
assert(x[0] == 1); // should hold
|
||||
assert(x[0] == 42); // should fail
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning 6328: (182-200): CHC: Assertion violation happens here.\nCounterexample:\nx = [1]\n\n\n\nTransaction trace:\nconstructor()\nState: x = []\nf()
|
||||
@@ -0,0 +1,11 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
struct S {
|
||||
int[][] d;
|
||||
}
|
||||
S[] data;
|
||||
function f() public {
|
||||
++data[1].d[3].push();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
pragma experimental SMTChecker;
|
||||
contract Test {
|
||||
struct RecursiveStruct {
|
||||
RecursiveStruct[] vals;
|
||||
}
|
||||
function func() public pure {
|
||||
RecursiveStruct[1] memory val = [ RecursiveStruct(new RecursiveStruct[](42)) ];
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning 2072: (136-165): Unused local variable.
|
||||
// Warning 8364: (170-212): Assertion checker does not yet implement type struct Test.RecursiveStruct memory
|
||||
// Warning 8364: (170-212): Assertion checker does not yet implement type struct Test.RecursiveStruct memory
|
||||
@@ -0,0 +1,21 @@
|
||||
pragma experimental SMTChecker;
|
||||
contract Test {
|
||||
struct RecursiveStruct {
|
||||
uint x;
|
||||
RecursiveStruct[] vals;
|
||||
}
|
||||
function func() public pure {
|
||||
RecursiveStruct memory val = RecursiveStruct(1, new RecursiveStruct[](42));
|
||||
assert(val.x == 1);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning 8115: (146-172): Assertion checker does not yet support the type of this variable.
|
||||
// Warning 8364: (175-220): Assertion checker does not yet implement type struct Test.RecursiveStruct memory
|
||||
// Warning 7650: (231-236): Assertion checker does not yet support this expression.
|
||||
// Warning 8364: (231-234): Assertion checker does not yet implement type struct Test.RecursiveStruct memory
|
||||
// Warning 6328: (224-242): CHC: Assertion violation happens here.\nCounterexample:\n\n\n\n\nTransaction trace:\nconstructor()\nfunc()
|
||||
// Warning 8115: (146-172): Assertion checker does not yet support the type of this variable.
|
||||
// Warning 8364: (175-220): Assertion checker does not yet implement type struct Test.RecursiveStruct memory
|
||||
// Warning 7650: (231-236): Assertion checker does not yet support this expression.
|
||||
// Warning 8364: (231-234): Assertion checker does not yet implement type struct Test.RecursiveStruct memory
|
||||
@@ -5,4 +5,3 @@ contract c {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 7407: (63-74): Type bytes calldata slice is not implicitly convertible to expected type bytes storage ref.
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
contract C {
|
||||
function f(bytes calldata x) external {
|
||||
bytes memory y = x[1:2];
|
||||
function f(bytes calldata x) external pure returns (bytes memory) {
|
||||
return x[1:2];
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 9574: (65-88): Type bytes calldata slice is not implicitly convertible to expected type bytes memory.
|
||||
}
|
||||
@@ -4,4 +4,3 @@ contract C {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 9553: (79-85): Invalid type for argument in function call. Invalid implicit conversion from bytes calldata slice to bytes memory requested.
|
||||
|
||||
Reference in New Issue
Block a user