Merge remote-tracking branch 'origin/develop' into HEAD

This commit is contained in:
chriseth
2020-02-27 15:06:36 +01:00
671 changed files with 19686 additions and 9996 deletions
@@ -0,0 +1,17 @@
pragma solidity >= 0.6.0;
contract C {
function h(uint[4] memory n) public pure returns (uint) {
return n[0] + n[1] + n[2] + n[3];
}
function i(uint[4] memory n) public view returns (uint) {
return this.h(n) * 2;
}
}
// ====
// compileViaYul: also
// ----
// h(uint256[4]): 1, 2, 3, 4 -> 10
// i(uint256[4]): 1, 2, 3, 4 -> 20
@@ -2,5 +2,6 @@ contract test {
}
// ====
// compileViaYul: also
// allowNonExistingFunctions: true
// ----
// i_am_not_there() -> FAILURE
@@ -0,0 +1,17 @@
pragma solidity >= 0.6.0;
contract C {
function g(uint n) external pure returns (uint) {
return n + 1;
}
function f(uint n) public view returns (uint) {
return this.g(2 * n);
}
}
// ====
// compileViaYul: also
// ----
// g(uint256): 4 -> 5
// f(uint256): 2 -> 5
@@ -0,0 +1,24 @@
pragma solidity >= 0.6.0;
contract C {
function d(uint n) external pure returns (uint[] memory) {
uint[] memory data = new uint[](n);
for (uint i = 0; i < data.length; ++i)
data[i] = i;
return data;
}
function dt(uint n) public view returns (uint) {
uint[] memory data = this.d(n);
uint sum = 0;
for (uint i = 0; i < data.length; ++i)
sum += data[i];
return sum;
}
}
// ====
// compileViaYul: also
// EVMVersion: >=byzantium
// ----
// dt(uint256): 4 -> 6
@@ -0,0 +1,23 @@
contract test {
uint256 public data;
bytes6 public name;
bytes32 public a_hash;
address public an_address;
constructor() public {
data = 8;
name = "Celina";
a_hash = keccak256("\x7b");
an_address = address(0x1337);
super_secret_data = 42;
}
uint256 super_secret_data;
}
// ====
// allowNonExistingFunctions: true
// compileViaYul: also
// ----
// data() -> 8
// name() -> "Celina"
// a_hash() -> 0xa91eddf639b0b768929589c1a9fd21dcb0107199bdd82e55c5348018a1572f52
// an_address() -> 0x1337
// super_secret_data() -> FAILURE
@@ -4,6 +4,8 @@ contract test {
function c() public returns(uint n) { return 2; }
function f() public returns(uint n) { return 3; }
}
// ====
// allowNonExistingFunctions: true
// ----
// a() -> 0
// b() -> 1
@@ -0,0 +1,8 @@
contract C {
function f() public payable returns (uint) {
return msg.value;
}
}
// ----
// f(), 1 ether -> 1000000000000000000
// f(), 1 wei -> 1
@@ -9,4 +9,4 @@ contract C {
// EVMVersion: >=istanbul
// compileViaYul: also
// ----
// f(), 254 ether -> 254
// f(), 254 wei -> 254
@@ -0,0 +1,33 @@
contract C {
struct S {
uint a;
uint b;
}
mapping(uint => S) public mappingAccess;
function data() internal view returns (S storage _data) {
// We need to assign it from somewhere, otherwise we would
// get an "uninitialized access" error.
_data = mappingAccess[20];
bytes32 slot = keccak256(abi.encode(uint(1), uint(0)));
assembly {
_data_slot := slot
}
}
function set(uint x) public {
data().a = x;
}
function get() public view returns (uint) {
return data().a;
}
}
// ----
// get() -> 0
// mappingAccess(uint256): 1 -> 0, 0
// set(uint256): 4
// get() -> 4
// mappingAccess(uint256): 1 -> 4, 0
@@ -0,0 +1,12 @@
contract C {
function f() public returns (uint x, uint y) {
assembly {
x := true
y := false
}
}
}
// ====
// compileViaYul: also
// ----
// f() -> 1, 0
@@ -0,0 +1,39 @@
interface Parent {
function parentFun() external returns (uint256);
}
interface SubA is Parent {
function subAFun() external returns (uint256);
}
interface SubB is Parent {
function subBFun() external returns (uint256);
}
contract Impl is SubA, SubB {
function parentFun() override external returns (uint256) { return 1; }
function subAFun() override external returns (uint256) { return 2; }
function subBFun() override external returns (uint256) { return 3; }
}
contract C {
function convertParent() public returns (uint256) {
Parent p = new Impl();
return p.parentFun();
}
function convertSubA() public returns (uint256, uint256) {
SubA sa = new Impl();
return (sa.parentFun(), sa.subAFun());
}
function convertSubB() public returns (uint256, uint256) {
SubB sb = new Impl();
return (sb.parentFun(), sb.subBFun());
}
}
// ----
// convertParent() -> 1
// convertSubA() -> 1, 2
// convertSubB() -> 1, 3
@@ -6,7 +6,8 @@ contract A {
// x() -> 0
// ()
// x() -> 1
// (), 1 ether
// (), 1 wei
// x() -> 2
// x(), 1 wei -> FAILURE
// (): hex"00" -> FAILURE
// (), 1 ether: hex"00" -> FAILURE
@@ -0,0 +1,11 @@
contract C {
function f(uint256 start, uint256 end, uint256[] calldata arr) external pure {
arr[start:end];
}
}
// ====
// EVMVersion: >=byzantium
// revertStrings: debug
// ----
// f(uint256,uint256,uint256[]): 2, 1, 0x80, 3, 1, 2, 3 -> FAILURE, hex"08c379a0", 0x20, 22, "Slice starts after end"
// f(uint256,uint256,uint256[]): 1, 5, 0x80, 3, 1, 2, 3 -> FAILURE, hex"08c379a0", 0x20, 28, "Slice is greater than length"
@@ -0,0 +1,15 @@
contract A {
function g() public { revert("fail"); }
}
contract C {
A a = new A();
function f() public {
a.g();
}
}
// ====
// EVMVersion: >=byzantium
// revertStrings: debug
// ----
// f() -> FAILURE, hex"08c379a0", 0x20, 4, "fail"
@@ -0,0 +1,11 @@
pragma experimental ABIEncoderV2;
contract C {
function f(uint256[][] calldata a) external returns (uint) {
return 42;
}
}
// ====
// EVMVersion: >=byzantium
// revertStrings: debug
// ----
// f(uint256[][]): 0x20, 1 -> FAILURE, hex"08c379a0", 0x20, 43, "ABI decoding: invalid calldata a", "rray stride"
@@ -0,0 +1,12 @@
pragma experimental ABIEncoderV2;
contract C {
function f(uint256[][2][] calldata x) external returns (uint256) {
x[0];
return 23;
}
}
// ====
// EVMVersion: >=byzantium
// revertStrings: debug
// ----
// f(uint256[][2][]): 0x20, 0x01, 0x20, 0x00 -> FAILURE, hex"08c379a0", 0x20, 28, "Invalid calldata tail offset"
@@ -0,0 +1,14 @@
pragma experimental ABIEncoderV2;
contract C {
function f(uint256[][2][] calldata x) external returns (uint256) {
return 42;
}
function g(uint256[][2][] calldata x) external returns (uint256) {
return this.f(x);
}
}
// ====
// EVMVersion: >=byzantium
// revertStrings: debug
// ----
// g(uint256[][2][]): 0x20, 0x01, 0x20, 0x00 -> FAILURE, hex"08c379a0", 0x20, 30, "Invalid calldata access offset"
@@ -0,0 +1,11 @@
pragma experimental ABIEncoderV2;
contract C {
function f(uint256[][] calldata x) external returns (uint256) {
return x[0].length;
}
}
// ====
// EVMVersion: >=byzantium
// revertStrings: debug
// ----
// f(uint256[][]): 0x20, 1, 0x20, 0x0100000000000000000000 -> FAILURE, hex"08c379a0", 0x20, 28, "Invalid calldata tail length"
@@ -0,0 +1,11 @@
pragma experimental ABIEncoderV2;
contract C {
function f(uint a, uint[] calldata b, uint c) external pure returns (uint) {
return 7;
}
}
// ====
// EVMVersion: >=byzantium
// revertStrings: debug
// ----
// f(uint256,uint256[],uint256): 6, 0x60, 9, 0x1000000000000000000000000000000000000000000000000000000000000002, 1, 2 -> FAILURE, hex"08c379a0", 0x20, 43, "ABI decoding: invalid calldata a", "rray length"
@@ -0,0 +1,11 @@
contract C {
function d(bytes memory _data) public pure returns (uint8) {
return abi.decode(_data, (uint8));
}
}
// ====
// EVMVersion: >=byzantium
// revertStrings: debug
// ABIEncoderV1Only: true
// ----
// d(bytes): 0x20, 0x01, 0x0000000000000000000000000000000000000000000000000000000000000000 -> FAILURE, hex"08c379a0", 0x20, 18, "Calldata too short"
@@ -0,0 +1,12 @@
contract C {
function f() external {}
function g() external {
C c = C(0x0000000000000000000000000000000000000000000000000000000000000000);
c.f();
}
}
// ====
// EVMVersion: >=byzantium
// revertStrings: debug
// ----
// g() -> FAILURE, hex"08c379a0", 0x20, 37, "Target contract does not contain", " code"
@@ -0,0 +1,12 @@
contract C {
enum E {X, Y}
function f(E[] calldata arr) external {
arr[1];
}
}
// ====
// EVMVersion: >=byzantium
// revertStrings: debug
// ABIEncoderV1Only: true
// ----
// f(uint8[]): 0x20, 2, 3, 3 -> FAILURE, hex"08c379a0", 0x20, 17, "Enum out of range"
@@ -0,0 +1,9 @@
contract C {
function f() public {}
}
// ====
// EVMVersion: >=byzantium
// revertStrings: debug
// ----
// f(), 1 ether -> FAILURE, hex"08c379a0", 0x20, 34, "Ether sent to non-payable functi", "on"
// () -> FAILURE, hex"08c379a0", 0x20, 53, "Contract does not have fallback ", "nor receive functions"
@@ -0,0 +1,9 @@
contract C {
function t(uint) public pure {}
}
// ====
// EVMVersion: >=byzantium
// compileViaYul: true
// revertStrings: debug
// ----
// t(uint256) -> FAILURE, hex"08c379a0", 0x20, 34, "ABI decoding: tuple data too sho", "rt"
@@ -0,0 +1,13 @@
contract C {
function d(bytes memory _data) public pure returns (uint8) {
return abi.decode(_data, (uint8));
}
}
// ====
// EVMVersion: >=byzantium
// revertStrings: debug
// ABIEncoderV1Only: true
// ----
// d(bytes): 0x20, 0x20, 0x0000000000000000000000000000000000000000000000000000000000000000 -> 0
// d(bytes): 0x100, 0x20, 0x0000000000000000000000000000000000000000000000000000000000000000 -> FAILURE, hex"08c379a0", 0x20, 43, "ABI calldata decoding: invalid h", "ead pointer"
// d(bytes): 0x20, 0x100, 0x0000000000000000000000000000000000000000000000000000000000000000 -> FAILURE, hex"08c379a0", 0x20, 43, "ABI calldata decoding: invalid d", "ata pointer"
@@ -0,0 +1,20 @@
contract C {
function dyn(uint ptr, uint start, uint x) public returns (bytes memory a) {
assembly {
mstore(0, start)
mstore(start, add(start, 1))
return(ptr, x)
}
}
function f(uint ptr, uint start, uint x) public returns (bool) {
this.dyn(ptr, start, x);
return true;
}
}
// ====
// EVMVersion: >=byzantium
// revertStrings: debug
// ABIEncoderV1Only: true
// ----
// f(uint256,uint256,uint256): 0, 0x200, 0x60 -> FAILURE, hex"08c379a0", 0x20, 39, "ABI memory decoding: invalid dat", "a start"
// f(uint256,uint256,uint256): 0, 0x20, 0x60 -> FAILURE, hex"08c379a0", 0x20, 40, "ABI memory decoding: invalid dat", "a length"
@@ -0,0 +1,16 @@
library L {
function g() external {}
}
contract C {
function f() public returns (bytes memory) {
(bool success, bytes memory result) = address(L).call(abi.encodeWithSignature("g()"));
assert(!success);
return result;
}
}
// ====
// EVMVersion: >=byzantium
// revertStrings: debug
// ----
// library: L
// f() -> 32, 132, 3963877391197344453575983046348115674221700746820753546331534351508065746944, 862718293348820473429344482784628181556388621521298319395315527974912, 1518017211910606845658622928256476421055725129218887721595913401102969, 14649601406562900601407788686537400806574002225747213573947654179243427889152, 0
@@ -0,0 +1,9 @@
pragma experimental ABIEncoderV2;
contract C {
function f(uint[] memory a) public pure returns (uint) { return 7; }
}
// ====
// EVMVersion: >=byzantium
// revertStrings: debug
// ----
// f(uint256[]): 0x20, 1 -> FAILURE, hex"08c379a0", 0x20, 43, "ABI decoding: invalid calldata a", "rray stride"
@@ -0,0 +1,9 @@
pragma experimental ABIEncoderV2;
contract C {
function e(bytes memory a) public pure returns (uint) { return 7; }
}
// ====
// EVMVersion: >=byzantium
// revertStrings: debug
// ----
// e(bytes): 0x20, 7 -> FAILURE, hex"08c379a0", 0x20, 39, "ABI decoding: invalid byte array", " length"
@@ -0,0 +1,27 @@
contract A {
receive() external payable {
revert("no_receive");
}
}
contract C {
A a = new A();
receive() external payable {}
function f() public {
address(a).transfer(1 wei);
}
function h() public {
address(a).transfer(100 ether);
}
function g() public view returns (uint) {
return address(this).balance;
}
}
// ====
// EVMVersion: >=byzantium
// revertStrings: debug
// ----
// (), 10 wei ->
// g() -> 10
// f() -> FAILURE, hex"08c379a0", 0x20, 10, "no_receive"
// h() -> FAILURE
@@ -0,0 +1,8 @@
contract A {
receive () external payable {}
}
// ====
// EVMVersion: >=byzantium
// revertStrings: debug
// ----
// (): hex"00" -> FAILURE, hex"08c379a0", 0x20, 41, "Unknown signature and no fallbac", "k defined"
@@ -0,0 +1,23 @@
contract B
{
}
contract A {
function different_salt() public returns (bool) {
B x = new B{salt: "abc"}();
B y = new B{salt: "abcef"}();
return x != y;
}
function same_salt() public returns (bool) {
B x = new B{salt: "xyz"}();
try new B{salt: "xyz"}() {} catch {
return true;
}
return false;
}
}
// ====
// EVMVersion: >=constantinople
// ----
// different_salt() -> true
// same_salt() -> true
@@ -0,0 +1,23 @@
contract B
{
uint x;
function getBalance() public view returns (uint) {
return address(this).balance * 1000 + x;
}
constructor(uint _x) public payable {
x = _x;
}
}
contract A {
function f() public payable returns (uint, uint, uint) {
B x = new B{salt: "abc", value: 3}(7);
B y = new B{value: 3}{salt: "abc"}(8);
B z = new B{value: 3, salt: "abc"}(9);
return (x.getBalance(), y.getBalance(), z.getBalance());
}
}
// ====
// EVMVersion: >=constantinople
// ----
// f(), 10 ether -> 3007, 3008, 3009
@@ -30,7 +30,8 @@ contract C {
}
// ----
// d() ->
// e(), 1 ether -> 1
// e(), 1 wei -> 1
// e(), 1 ether -> 1000000000000000000
// f(uint256): 3 -> 3, 3
// g() -> 2, 3
// h(uint256,uint256): 1, -2 -> 3
@@ -11,7 +11,7 @@ contract C {
}
}
// ----
// constructor(), 2 ether: 3 ->
// constructor(), 2 wei: 3 ->
// state() -> 3
// balance() -> 2
// update(uint256): 4
@@ -14,6 +14,7 @@ contract C {
}
}
// ====
// allowNonExistingFunctions: true
// EVMVersion: >homestead
// ----
// _() -> FAILURE
@@ -16,8 +16,8 @@ contract A {
// data() -> 2
// externalData() -> 0x20, 2, left(0x42ef)
// balance() -> 0
// (), 1 ether
// (), 1 wei
// balance() -> 1
// (), 2 ether: hex"fefe"
// (), 2 wei: hex"fefe"
// balance() -> 2
// externalData() -> 0x20, 2, left(0xfefe)
@@ -4,6 +4,7 @@ contract C {
}
}
// ====
// allowNonExistingFunctions: true
// compileViaYul: also
// ----
// f(uint256,uint256,uint256,uint256,uint256): 1, 1, 1, 1, 1
@@ -0,0 +1,28 @@
interface A {}
contract test {
mapping(A => uint8) table;
function get(A k) public returns (uint8 v) {
return table[k];
}
function set(A k, uint8 v) public {
table[k] = v;
}
}
// ====
// compileViaYul: also
// ----
// get(address): 0 -> 0
// get(address): 0x01 -> 0
// get(address): 0xa7 -> 0
// set(address,uint8): 0x01, 0xa1 ->
// get(address): 0 -> 0
// get(address): 0x01 -> 0xa1
// get(address): 0xa7 -> 0
// set(address,uint8): 0x00, 0xef ->
// get(address): 0 -> 0xef
// get(address): 0x01 -> 0xa1
// get(address): 0xa7 -> 0
// set(address,uint8): 0x01, 0x05 ->
// get(address): 0 -> 0xef
// get(address): 0x01 -> 0x05
// get(address): 0xa7 -> 0
@@ -0,0 +1,38 @@
interface A {}
contract test {
mapping(A => uint8) public table;
function set(A k, uint8 v) public {
table[k] = v;
}
function get(A k) public returns (uint8) {
return this.table(k);
}
}
// ----
// table(address): 0 -> 0
// table(address): 0x01 -> 0
// table(address): 0xa7 -> 0
// get(address): 0 -> 0
// get(address): 0x01 -> 0
// get(address): 0xa7 -> 0
// set(address,uint8): 0x01, 0xa1 ->
// table(address): 0 -> 0
// table(address): 0x01 -> 0xa1
// table(address): 0xa7 -> 0
// get(address): 0 -> 0
// get(address): 0x01 -> 0xa1
// get(address): 0xa7 -> 0
// set(address,uint8): 0x00, 0xef ->
// table(address): 0 -> 0xef
// table(address): 0x01 -> 0xa1
// table(address): 0xa7 -> 0
// get(address): 0 -> 0xef
// get(address): 0x01 -> 0xa1
// get(address): 0xa7 -> 0
// set(address,uint8): 0x01, 0x05 ->
// table(address): 0 -> 0xef
// table(address): 0x01 -> 0x05
// table(address): 0xa7 -> 0
// get(address): 0 -> 0xef
// get(address): 0x01 -> 0x05
// get(address): 0xa7 -> 0
@@ -0,0 +1,35 @@
interface A {}
library L {
function get(mapping(A => uint8) storage table, A k) external returns (uint8) {
return table[k];
}
function set(mapping(A => uint8) storage table, A k, uint8 v) external {
table[k] = v;
}
}
contract test {
mapping(A => uint8) table;
function get(A k) public returns (uint8 v) {
return L.get(table, k);
}
function set(A k, uint8 v) public {
L.set(table, k, v);
}
}
// ----
// library: L
// get(address): 0 -> 0
// get(address): 0x01 -> 0
// get(address): 0xa7 -> 0
// set(address,uint8): 0x01, 0xa1 ->
// get(address): 0 -> 0
// get(address): 0x01 -> 0xa1
// get(address): 0xa7 -> 0
// set(address,uint8): 0x00, 0xef ->
// get(address): 0 -> 0xef
// get(address): 0x01 -> 0xa1
// get(address): 0xa7 -> 0
// set(address,uint8): 0x01, 0x05 ->
// get(address): 0 -> 0xef
// get(address): 0x01 -> 0x05
// get(address): 0xa7 -> 0
@@ -0,0 +1,30 @@
enum E { A, B, C }
contract test {
mapping(E => uint8) table;
function get(E k) public returns (uint8 v) {
return table[k];
}
function set(E k, uint8 v) public {
table[k] = v;
}
}
// ====
// compileViaYul: also
// ----
// get(uint8): 0 -> 0
// get(uint8): 0x01 -> 0
// get(uint8): 0x02 -> 0
// get(uint8): 0x03 -> FAILURE
// get(uint8): 0xa7 -> FAILURE
// set(uint8,uint8): 0x01, 0xa1 ->
// get(uint8): 0 -> 0
// get(uint8): 0x01 -> 0xa1
// get(uint8): 0xa7 -> FAILURE
// set(uint8,uint8): 0x00, 0xef ->
// get(uint8): 0 -> 0xef
// get(uint8): 0x01 -> 0xa1
// get(uint8): 0xa7 -> FAILURE
// set(uint8,uint8): 0x01, 0x05 ->
// get(uint8): 0 -> 0xef
// get(uint8): 0x01 -> 0x05
// get(uint8): 0xa7 -> FAILURE
@@ -0,0 +1,40 @@
contract test {
enum E { A, B, C }
mapping(E => uint8) public table;
function set(E k, uint8 v) public {
table[k] = v;
}
function get(E k) public returns (uint8) {
return this.table(k);
}
}
// ====
// ABIEncoderV1Only: true
// ----
// table(uint8): 0 -> 0
// table(uint8): 0x01 -> 0
// table(uint8): 0xa7 -> 0
// get(uint8): 0 -> 0
// get(uint8): 0x01 -> 0
// get(uint8): 0xa7 -> FAILURE
// set(uint8,uint8): 0x01, 0xa1 ->
// table(uint8): 0 -> 0
// table(uint8): 0x01 -> 0xa1
// table(uint8): 0xa7 -> 0
// get(uint8): 0 -> 0
// get(uint8): 0x01 -> 0xa1
// get(uint8): 0xa7 -> FAILURE
// set(uint8,uint8): 0x00, 0xef ->
// table(uint8): 0 -> 0xef
// table(uint8): 0x01 -> 0xa1
// table(uint8): 0xa7 -> 0
// get(uint8): 0 -> 0xef
// get(uint8): 0x01 -> 0xa1
// get(uint8): 0xa7 -> FAILURE
// set(uint8,uint8): 0x01, 0x05 ->
// table(uint8): 0 -> 0xef
// table(uint8): 0x01 -> 0x05
// table(uint8): 0xa7 -> 0
// get(uint8): 0 -> 0xef
// get(uint8): 0x01 -> 0x05
// get(uint8): 0xa7 -> FAILURE
@@ -0,0 +1,39 @@
pragma experimental ABIEncoderV2;
contract test {
enum E { A, B, C }
mapping(E => uint8) public table;
function set(E k, uint8 v) public {
table[k] = v;
}
function get(E k) public returns (uint8) {
return this.table(k);
}
}
// ----
// table(uint8): 0 -> 0
// table(uint8): 0x01 -> 0
// table(uint8): 0xa7 -> FAILURE
// get(uint8): 0 -> 0
// get(uint8): 0x01 -> 0
// get(uint8): 0xa7 -> FAILURE
// set(uint8,uint8): 0x01, 0xa1 ->
// table(uint8): 0 -> 0
// table(uint8): 0x01 -> 0xa1
// table(uint8): 0xa7 -> FAILURE
// get(uint8): 0 -> 0
// get(uint8): 0x01 -> 0xa1
// get(uint8): 0xa7 -> FAILURE
// set(uint8,uint8): 0x00, 0xef ->
// table(uint8): 0 -> 0xef
// table(uint8): 0x01 -> 0xa1
// table(uint8): 0xa7 -> FAILURE
// get(uint8): 0 -> 0xef
// get(uint8): 0x01 -> 0xa1
// get(uint8): 0xa7 -> FAILURE
// set(uint8,uint8): 0x01, 0x05 ->
// table(uint8): 0 -> 0xef
// table(uint8): 0x01 -> 0x05
// table(uint8): 0xa7 -> FAILURE
// get(uint8): 0 -> 0xef
// get(uint8): 0x01 -> 0x05
// get(uint8): 0xa7 -> FAILURE
@@ -0,0 +1,35 @@
enum E { A, B, C }
library L {
function get(mapping(E => uint8) storage table, E k) external returns (uint8) {
return table[k];
}
function set(mapping(E => uint8) storage table, E k, uint8 v) external {
table[k] = v;
}
}
contract test {
mapping(E => uint8) table;
function get(E k) public returns (uint8 v) {
return L.get(table, k);
}
function set(E k, uint8 v) public {
L.set(table, k, v);
}
}
// ----
// library: L
// get(uint8): 0 -> 0
// get(uint8): 0x01 -> 0
// get(uint8): 0xa7 -> FAILURE
// set(uint8,uint8): 0x01, 0xa1 ->
// get(uint8): 0 -> 0
// get(uint8): 0x01 -> 0xa1
// get(uint8): 0xa7 -> FAILURE
// set(uint8,uint8): 0x00, 0xef ->
// get(uint8): 0 -> 0xef
// get(uint8): 0x01 -> 0xa1
// get(uint8): 0xa7 -> FAILURE
// set(uint8,uint8): 0x01, 0x05 ->
// get(uint8): 0 -> 0xef
// get(uint8): 0x01 -> 0x05
// get(uint8): 0xa7 -> FAILURE
@@ -0,0 +1,27 @@
contract test {
mapping(uint8 => uint8) table;
function get(uint8 k) public returns (uint8 v) {
return table[k];
}
function set(uint8 k, uint8 v) public {
table[k] = v;
}
}
// ====
// compileViaYul: also
// ----
// get(uint8): 0 -> 0
// get(uint8): 0x01 -> 0
// get(uint8): 0xa7 -> 0
// set(uint8,uint8): 0x01, 0xa1 ->
// get(uint8): 0 -> 0
// get(uint8): 0x01 -> 0xa1
// get(uint8): 0xa7 -> 0
// set(uint8,uint8): 0x00, 0xef ->
// get(uint8): 0 -> 0xef
// get(uint8): 0x01 -> 0xa1
// get(uint8): 0xa7 -> 0
// set(uint8,uint8): 0x01, 0x05 ->
// get(uint8): 0 -> 0xef
// get(uint8): 0x01 -> 0x05
// get(uint8): 0xa7 -> 0
@@ -0,0 +1,15 @@
contract test {
function fixedBytes() public returns(bytes32 ret) {
return "abc\x00\xff__";
}
function pipeThrough(bytes2 small, bool one) public returns(bytes16 large, bool oneRet) {
oneRet = one;
large = small;
}
}
// ====
// compileViaYul: also
// ----
// fixedBytes() -> "abc\0\xff__"
// pipeThrough(bytes2, bool): "\0\x02", true -> "\0\x2", true
@@ -0,0 +1,16 @@
contract C {
function f() public pure returns (uint, uint, uint) {
return (1, 2, 3);
}
function g() public pure returns (uint a, uint b, uint c) {
(c, b, a) = f();
}
function h() public pure returns (uint a) {
(,,a) = f();
}
}
// ====
// compileViaYul: also
// ----
// g() -> 3, 2, 1
// h() -> 3
@@ -0,0 +1,20 @@
pragma experimental ABIEncoderV2;
contract C {
function f(uint256[] calldata x, uint256 i) external returns (uint256) {
return x[i];
}
function f(uint256[][] calldata x, uint256 i, uint256 j) external returns (uint256) {
return x[i][j];
}
}
// ====
// compileViaYul: also
// ----
// f(uint256[],uint256): 0x40, 0, 0 -> FAILURE
// f(uint256[],uint256): 0x40, 0, 1, 23 -> 23
// f(uint256[],uint256): 0x40, 1, 1, 23 -> FAILURE
// f(uint256[],uint256): 0x40, 0, 2, 23, 42 -> 23
// f(uint256[],uint256): 0x40, 1, 2, 23, 42 -> 42
// f(uint256[],uint256): 0x40, 2, 2, 23, 42 -> FAILURE
// f(uint256[][],uint256,uint256): 0x60, 0, 0 -> FAILURE
// f(uint256[][],uint256,uint256): 0x60, 0, 0, 1, 0x20, 1, 23 -> 23
@@ -0,0 +1,34 @@
pragma experimental ABIEncoderV2;
contract C {
function f(uint256[] calldata x) external returns (uint256) {
return x.length;
}
function f(uint256[][] calldata x) external returns (uint256 l1, uint256 l2, uint256 l3) {
l1 = x.length;
if (l1 > 0) l2 = x[0].length;
if (l1 > 1) l3 = x[1].length;
}
function f(uint256[2] calldata x) external returns (uint256) {
return x.length;
}
}
// ====
// compileViaYul: also
// ----
// f(uint256[]): 0x20, 0 -> 0
// f(uint256[]): 0x20, 1, 23 -> 1
// f(uint256[]): 0x20, 2, 23, 42 -> 2
// f(uint256[]): 0x20, 3, 23, 42, 17 -> 3
// f(uint256[2]): 23, 42 -> 2
// f(uint256[][]): 0x20, 0 -> 0, 0, 0
// f(uint256[][]): 0x20, 1, 0x20, 0 -> 1, 0, 0
// f(uint256[][]): 0x20, 1, 0x00 -> 1, 0, 0
// f(uint256[][]): 0x20, 1, 0x20, 1, 23 -> 1, 1, 0
// f(uint256[][]): 0x20, 1, 0x20, 2, 23, 42 -> 1, 2, 0
// f(uint256[][]): 0x20, 1, 0x40, 0, 2, 23, 42 -> 1, 2, 0
// f(uint256[][]): 0x20, 1, -32 -> 1, 1, 0
// f(uint256[][]): 0x20, 2, 0x40, 0x40, 2, 23, 42 -> 2, 2, 2
// f(uint256[][]): 0x20, 2, 0x40, 0xa0, 2, 23, 42, 0 -> 2, 2, 0
// f(uint256[][]): 0x20, 2, 0xA0, 0x40, 2, 23, 42, 0 -> 2, 0, 2
// f(uint256[][]): 0x20, 2, 0x40, 0xA0, 2, 23, 42, 1, 17 -> 2, 2, 1
// f(uint256[][]): 0x20, 2, 0x40, 0xA0, 2, 23, 42, 2, 17, 13 -> 2, 2, 2
@@ -0,0 +1,20 @@
pragma experimental ABIEncoderV2;
contract C {
function f(uint256[][2][] calldata x, uint256 i, uint256 j, uint256 k) external returns (uint256 a, uint256 b, uint256 c, uint256 d) {
a = x.length;
b = x[i].length;
c = x[i][j].length;
d = x[i][j][k];
}
}
// ====
// compileViaYul: also
// ----
// f(uint256[][2][],uint256,uint256,uint256): 0x80, 0, 0, 0, 1, 0x20, 0x40, 0x80, 1, 42, 1, 23 -> 1, 2, 1, 42
// f(uint256[][2][],uint256,uint256,uint256): 0x80, 0, 1, 0, 1, 0x20, 0x40, 0x80, 1, 42, 1, 23 -> 1, 2, 1, 23
// f(uint256[][2][],uint256,uint256,uint256): 0x80, 0, 1, 0, 1, 0x20, 0x40, 0x80, 1, 42, 2, 23, 17 -> 1, 2, 2, 23
// f(uint256[][2][],uint256,uint256,uint256): 0x80, 0, 1, 1, 1, 0x20, 0x40, 0x80, 1, 42, 2, 23, 17 -> 1, 2, 2, 17
// f(uint256[][2][],uint256,uint256,uint256): 0x80, 1, 0, 0, 1, 0x20, 0x40, 0x80, 1, 42, 1, 23 -> FAILURE
// f(uint256[][2][],uint256,uint256,uint256): 0x80, 0, 2, 0, 1, 0x20, 0x40, 0x80, 1, 42, 1, 23 -> FAILURE
// f(uint256[][2][],uint256,uint256,uint256): 0x80, 0, 2, 0, 1, 0x20, 0x40, 0x80, 1, 42, 1, 23 -> FAILURE
@@ -0,0 +1,12 @@
pragma experimental ABIEncoderV2;
contract C {
function f(bytes[] calldata a, uint256 i) external returns (uint) {
return uint8(a[0][i]);
}
}
// ====
// compileViaYul: also
// ----
// f(bytes[],uint256): 0x40, 0, 1, 0x20, 2, hex"6162" -> 0x61
// f(bytes[],uint256): 0x40, 1, 1, 0x20, 2, hex"6162" -> 0x62
// f(bytes[],uint256): 0x40, 2, 1, 0x20, 2, hex"6162" -> FAILURE
@@ -0,0 +1,10 @@
contract A {
function f() public pure returns (uint) {
uint x = 3 < 0 ? 2 > 1 ? 2 : 1 : 7 > 2 ? 7 : 6;
return x;
}
}
// ====
// compileViaYul: also
// ----
// f() -> 7
@@ -0,0 +1,11 @@
contract A {
function f() public pure returns (uint) {
uint x = true ? 1 : 0;
uint y = false ? 0 : 1;
return x + y;
}
}
// ====
// compileViaYul: also
// ----
// f() -> 2
@@ -0,0 +1,11 @@
contract A {
function f(bool cond) public pure returns (uint, uint) {
(uint a, uint b) = cond ? (1, 2) : (3, 4);
return (a, b);
}
}
// ====
// compileViaYul: also
// ----
// f(bool): true -> 1, 2
// f(bool): false -> 3, 4
@@ -0,0 +1,13 @@
contract A {
function f() public pure returns (uint, uint, uint, uint) {
uint y1 = 1;
uint y2 = 1;
uint x = 3 < 0 ? y1 = 3 : 6;
uint z = 3 < 10 ? y2 = 5 : 6;
return (x, y1, y2, z);
}
}
// ====
// compileViaYul: also
// ----
// f() -> 6, 1, 5, 5
@@ -0,0 +1,13 @@
contract A {
function f() public pure returns (uint, uint, uint, uint) {
uint x = 3;
uint y = 1;
uint z = (x > y) ? x : y;
uint w = x < y ? x : y;
return (x, y, z, w);
}
}
// ====
// compileViaYul: also
// ----
// f() -> 3, 1, 3, 1
@@ -0,0 +1,18 @@
contract C {
function f() public pure returns (uint, uint, uint) {
return (1, 2, 3);
}
function g() public pure returns (uint x, uint y, uint z) {
(uint c, uint b, uint a) = f();
(x, y, z) = (a, b, c);
}
function h() public pure returns (uint) {
(,,uint a) = f();
return a;
}
}
// ====
// compileViaYul: also
// ----
// g() -> 3, 2, 1
// h() -> 3
@@ -0,0 +1,32 @@
contract C {
uint public x = 17;
function f(uint a1, uint a2) public returns (uint r1, uint r2) {
(uint b1, uint b2) = (a1, a2);
(r1, x, r2) = (b1, b2, b2);
}
function g() public returns (uint a, uint b, uint c) {
uint256[3] memory m;
(m[0], m[1], m[2]) = (1, x, 3);
return (m[2], m[1], m[0]);
}
function h() public returns (uint a, uint b, uint c) {
uint256[3] memory m;
(m[0], m[1], , m[2], m[0]) = (1, x, 3, 4, 42);
return (m[2], m[1], m[0]);
}
function i() public returns (uint a, uint b, uint c, uint d) {
(a) = 42;
(((((b))))) = 23;
c = (((17)));
(((d))) = (13);
}
}
// ====
// compileViaYul: also
// ----
// x() -> 17
// f(uint256,uint256): 23, 42 -> 23, 42
// x() -> 42
// g() -> 3, 42, 1
// h() -> 4, 42, 1
// i() -> 42, 23, 17, 13
@@ -0,0 +1,10 @@
contract C {
function f() public pure returns (uint) {
uint x;
return x;
}
}
// ====
// compileViaYul: also
// ----
// f() -> 0
@@ -0,0 +1,26 @@
pragma experimental ABIEncoderV2;
contract test {
enum E { A, B, C }
mapping(E => uint8) public table;
function set(E k, uint8 v) public {
table[k] = v;
}
}
// ====
// compileViaYul: also
// ----
// table(uint8): 0 -> 0
// table(uint8): 0x01 -> 0
// table(uint8): 0xa7 -> FAILURE
// set(uint8,uint8): 0x01, 0xa1 ->
// table(uint8): 0 -> 0
// table(uint8): 0x01 -> 0xa1
// table(uint8): 0xa7 -> FAILURE
// set(uint8,uint8): 0x00, 0xef ->
// table(uint8): 0 -> 0xef
// table(uint8): 0x01 -> 0xa1
// table(uint8): 0xa7 -> FAILURE
// set(uint8,uint8): 0x01, 0x05 ->
// table(uint8): 0 -> 0xef
// table(uint8): 0x01 -> 0x05
// table(uint8): 0xa7 -> FAILURE
@@ -0,0 +1,40 @@
contract test {
mapping(uint256 => uint256) public m1;
mapping(uint256 => mapping(uint256 => uint256)) public m2;
function set(uint256 k, uint256 v) public {
m1[k] = v;
}
function set(uint256 k1, uint256 k2, uint256 v) public {
m2[k1][k2] = v;
}
}
// ====
// compileViaYul: also
// ----
// m1(uint256): 0 -> 0
// m1(uint256): 0x01 -> 0
// m1(uint256): 0xa7 -> 0
// set(uint256,uint256): 0x01, 0xa1 ->
// m1(uint256): 0 -> 0
// m1(uint256): 0x01 -> 0xa1
// m1(uint256): 0xa7 -> 0
// set(uint256,uint256): 0x00, 0xef ->
// m1(uint256): 0 -> 0xef
// m1(uint256): 0x01 -> 0xa1
// m1(uint256): 0xa7 -> 0
// set(uint256,uint256): 0x01, 0x05 ->
// m1(uint256): 0 -> 0xef
// m1(uint256): 0x01 -> 0x05
// m1(uint256): 0xa7 -> 0
// m2(uint256,uint256): 0, 0 -> 0
// m2(uint256,uint256): 0, 0x01 -> 0
// m2(uint256,uint256): 0xa7, 0 -> 0
// m2(uint256,uint256): 0xa7, 0x01 -> 0
// set(uint256,uint256,uint256): 0xa7, 0x01, 0x23
// m2(uint256,uint256): 0, 0x01 -> 0
// m2(uint256,uint256): 0xa7, 0 -> 0
// m2(uint256,uint256): 0xa7, 0x01 -> 0x23
// set(uint256,uint256,uint256): 0, 0x01, 0xef
// m2(uint256,uint256): 0, 0x01 -> 0xef
// m2(uint256,uint256): 0xa7, 0 -> 0
// m2(uint256,uint256): 0xa7, 0x01 -> 0x23
@@ -1,6 +1,7 @@
contract C {
}
// ====
// allowNonExistingFunctions: true
// compileViaYul: true
// ----
// f() -> FAILURE
@@ -0,0 +1,14 @@
contract C {
uint256 x;
uint256 y;
function set(uint256 v) public returns (uint256) { x = v; return v; }
function f() public returns (uint256, uint256) {
(y, y, y) = (set(1), set(2), set(3));
assert(y == 1 && x == 3);
return (x, y);
}
}
// ====
// compileViaYul: also
// ----
// f() -> 3, 1