Merge pull request #8518 from aarlt/extract-more-testcases

[test] Extract 45 more tests from SolidityEndToEndTest.cpp
This commit is contained in:
chriseth 2020-03-26 18:14:58 +01:00 committed by GitHub
commit 95407cbaae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
54 changed files with 1295 additions and 1268 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,11 @@
contract C {
function f(bytes calldata data)
external
pure
returns (uint256, bytes memory r)
{
return abi.decode(data, (uint256, bytes));
}
}
// ----
// f(bytes): 0x20, 0x80, 0x21, 0x40, 0x7, "abcdefg" -> 0x21, 0x40, 0x7, "abcdefg"

View File

@ -0,0 +1,7 @@
contract C {
function f(bytes memory data) public pure returns (uint256, bytes memory) {
return abi.decode(data, (uint256, bytes));
}
}
// ----
// f(bytes): 0x20, 0x80, 0x21, 0x40, 0x7, "abcdefg" -> 0x21, 0x40, 0x7, "abcdefg"

View File

@ -0,0 +1,10 @@
contract C {
bytes data;
function f(bytes memory _data) public returns (uint256, bytes memory) {
data = _data;
return abi.decode(data, (uint256, bytes));
}
}
// ----
// f(bytes): 0x20, 0x80, 0x21, 0x40, 0x7, "abcdefg" -> 0x21, 0x40, 0x7, "abcdefg"

View File

@ -0,0 +1,11 @@
// Tests that this will not end up using a "bytes0" type
// (which would assert)
contract C {
function f() public pure returns (bytes memory, bytes memory) {
return (abi.encode(""), abi.encodePacked(""));
}
}
// ====
// ABIEncoderV1Only: true
// ----
// f() -> 0x40, 0xc0, 0x60, 0x20, 0x0, 0x0, 0x0

View File

@ -0,0 +1,18 @@
contract Test {
uint24[3][] public data;
function set(uint24[3][] memory _data) public returns (uint256) {
data = _data;
return data.length;
}
function get() public returns (uint24[3][] memory) {
return data;
}
}
// ----
// set(uint24[3][]): 0x20, 0x06, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12 -> 0x06
// data(uint256,uint256): 0x02, 0x02 -> 0x09
// data(uint256,uint256): 0x05, 0x01 -> 0x11
// data(uint256,uint256): 0x06, 0x00 -> FAILURE
// get() -> 0x20, 0x06, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12

View File

@ -0,0 +1,13 @@
contract Test {
function set(uint24[3][] memory _data, uint256 a, uint256 b)
public
returns (uint256 l, uint256 e)
{
l = _data.length;
e = _data[a][b];
}
}
// ====
// compileViaYul: also
// ----
// set(uint24[3][],uint256,uint256): 0x60, 0x03, 0x02, 0x06, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12 -> 0x06, 0x0c

View File

@ -0,0 +1,13 @@
contract Test {
function set(bytes memory _data, uint256 i)
public
returns (uint256 l, bytes1 c)
{
l = _data.length;
c = _data[i];
}
}
// ====
// compileViaYul: also
// ----
// set(bytes,uint256): 0x40, 0x03, 0x08, "abcdefgh" -> 0x08, "d"

View File

@ -0,0 +1,45 @@
contract c {
struct Data {
uint256 x;
uint256 y;
}
Data[2**10] data;
uint256[2**10 + 3] ids;
function setIDStatic(uint256 id) public {
ids[2] = id;
}
function setID(uint256 index, uint256 id) public {
ids[index] = id;
}
function setData(uint256 index, uint256 x, uint256 y) public {
data[index].x = x;
data[index].y = y;
}
function getID(uint256 index) public returns (uint256) {
return ids[index];
}
function getData(uint256 index) public returns (uint256 x, uint256 y) {
x = data[index].x;
y = data[index].y;
}
function getLengths() public returns (uint256 l1, uint256 l2) {
l1 = data.length;
l2 = ids.length;
}
}
// ----
// setIDStatic(uint256): 0xb ->
// getID(uint256): 0x2 -> 0xb
// setID(uint256,uint256): 0x7, 0x8 ->
// getID(uint256): 0x7 -> 0x8
// setData(uint256,uint256,uint256): 0x7, 0x8, 0x9 ->
// setData(uint256,uint256,uint256): 0x8, 0xa, 0xb ->
// getData(uint256): 0x7 -> 0x8, 0x9
// getData(uint256): 0x8 -> 0xa, 0xb
// getLengths() -> 0x400, 0x403

View File

@ -0,0 +1,17 @@
contract C {
bytes16[] public data;
function f(bytes32 x) public returns (bytes1) {
return x[2];
}
function g(bytes32 x) public returns (uint256) {
data = [x[0], x[1], x[2]];
data[0] = "12345";
return uint256(uint8(data[0][4]));
}
}
// ----
// f(bytes32): "789" -> "9"
// g(bytes32): "789" -> 0x35
// data(uint256): 0x01 -> "8"

View File

@ -0,0 +1,19 @@
contract Test {
uint24[3][][4] data;
function set(uint24[3][][4] memory x)
internal
returns (uint24[3][][4] memory)
{
x[1][2][2] = 1;
x[1][3][2] = 7;
return x;
}
function f() public returns (uint24[3][] memory) {
while (data[1].length < 4) data[1].push();
return set(data)[1];
}
}
// ----
// f() -> 0x20, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x07

View File

@ -0,0 +1,14 @@
contract Test {
function set(uint24[3][4] memory x) public {
x[2][2] = 1;
x[3][2] = 7;
}
function f() public returns (uint24[3][4] memory) {
uint24[3][4] memory data;
set(data);
return data;
}
}
// ----
// f() -> 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x07

View File

@ -0,0 +1,26 @@
// Invoke some features that use memory and test that they do not interfere with each other.
contract Helper {
uint256 public flag;
constructor(uint256 x) public {
flag = x;
}
}
contract Main {
mapping(uint256 => uint256) map;
function f(uint256 x) public returns (uint256) {
map[x] = x;
return
(new Helper(uint256(keccak256(abi.encodePacked(this.g(map[x]))))))
.flag();
}
function g(uint256 a) public returns (uint256) {
return map[a];
}
}
// ----
// f(uint256): 0x34 -> 0x46bddb1178e94d7f2892ff5f366840eb658911794f2c3a44c450aa2c505186c1

View File

@ -0,0 +1,20 @@
contract Sample {
struct s {
uint16 x;
uint16 y;
string a;
string b;
}
s[2] public p;
constructor() public {
s memory m;
m.x = 0xbbbb;
m.y = 0xcccc;
m.a = "hello";
m.b = "world";
p[0] = m;
}
}
// ----
// p(uint256): 0x0 -> 0xbbbb, 0xcccc, 0x80, 0xc0, 0x05, "hello", 0x05, "world"

View File

@ -0,0 +1,17 @@
contract Test {
string s;
bytes b;
function f(string memory _s, uint256 n) public returns (bytes1) {
b = bytes(_s);
s = string(b);
return bytes(s)[n];
}
function l() public returns (uint256) {
return bytes(s).length;
}
}
// ----
// f(string,uint256): 0x40, 0x02, 0x06, "abcdef" -> "c"
// l() -> 0x06

View File

@ -0,0 +1,35 @@
contract buggystruct {
Buggy public bug;
struct Buggy {
uint256 first;
uint256 second;
uint256 third;
string last;
}
constructor() public {
bug = Buggy(10, 20, 30, "asdfghjkl");
}
function getFirst() public returns (uint256) {
return bug.first;
}
function getSecond() public returns (uint256) {
return bug.second;
}
function getThird() public returns (uint256) {
return bug.third;
}
function getLast() public returns (string memory) {
return bug.last;
}
}
// ----
// getFirst() -> 0x0a
// getSecond() -> 0x14
// getThird() -> 0x1e
// getLast() -> 0x20, 0x09, "asdfghjkl"

View File

@ -0,0 +1,9 @@
contract C {
bytes32 constant x = keccak256("abc");
function f() public returns (bytes32) {
return x;
}
}
// ----
// f() -> 0x4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45

View File

@ -0,0 +1,26 @@
contract C {
uint256 public x;
function f() public pure returns (bytes4) {
return this.f.selector;
}
function g() public returns (bytes4) {
function () pure external returns (bytes4) fun = this.f;
return fun.selector;
}
function h() public returns (bytes4) {
function () pure external returns (bytes4) fun = this.f;
return fun.selector;
}
function i() public pure returns (bytes4) {
return this.x.selector;
}
}
// ----
// f() -> 0x26121ff000000000000000000000000000000000000000000000000000000000
// g() -> 0x26121ff000000000000000000000000000000000000000000000000000000000
// h() -> 0x26121ff000000000000000000000000000000000000000000000000000000000
// i() -> 0x0c55699c00000000000000000000000000000000000000000000000000000000

View File

@ -0,0 +1,12 @@
contract c {
bytes data;
function foo() public returns (bytes32) {
data.push("x");
data.push("y");
data.push("z");
return keccak256(abi.encodePacked("b", keccak256(data), "a"));
}
}
// ----
// foo() -> 0xb338eefce206f9f57b83aa738deecd5326dc4b72dd81ee6a7c621a6facb7acdc

View File

@ -0,0 +1,7 @@
contract c {
function foo(uint256 a, uint256 b, uint256 c) public returns (bytes32 d) {
d = keccak256(abi.encodePacked(a, b, c));
}
}
// ----
// foo(uint256,uint256,uint256): 0xa, 0xc, 0xd -> 0xbc740a98aae5923e8f04c9aa798c9ee82f69e319997699f2782c40828db9fd81

View File

@ -0,0 +1,7 @@
contract c {
function foo(uint256 a, uint16 b) public returns (bytes32 d) {
d = keccak256(abi.encodePacked(a, b, uint8(145)));
}
}
// ----
// foo(uint256,uint16): 0xa, 0xc -> 0x88acd45f75907e7c560318bc1a5249850a0999c4896717b1167d05d116e6dbad

View File

@ -0,0 +1,12 @@
contract c {
function foo() public returns (bytes32 d) {
d = keccak256("foo");
}
function bar(uint256 a, uint16 b) public returns (bytes32 d) {
d = keccak256(abi.encodePacked(a, b, uint8(145), "foo"));
}
}
// ----
// foo() -> 0x41b1a0649752af1b28b3dc29a1556eee781e4a4c3a1f7f53f90fa834de098c4d
// bar(uint256,uint16): 0xa, 0xc -> 0x6990f36476dc412b1c4baa48e2d9f4aa4bb313f61fda367c8fdbbb2232dc6146

View File

@ -0,0 +1,9 @@
contract test {
function foo(uint256 a) public returns (bytes4 value) {
return msg.sig;
}
}
// ====
// compileViaYul: also
// ----
// foo(uint256): 0x0 -> 0x2fbebd3800000000000000000000000000000000000000000000000000000000

View File

@ -0,0 +1,13 @@
contract test {
function boo() public returns (bytes4 value) {
return msg.sig;
}
function foo(uint256 a) public returns (bytes4 value) {
return boo();
}
}
// ====
// compileViaYul: also
// ----
// foo(uint256): 0x0 -> 0x2fbebd3800000000000000000000000000000000000000000000000000000000

View File

@ -0,0 +1,74 @@
pragma experimental ABIEncoderV2;
contract C {
function f1(bytes[1] calldata a)
external
returns (uint256, uint256, uint256, uint256)
{
return (a[0].length, uint8(a[0][0]), uint8(a[0][1]), uint8(a[0][2]));
}
function f2(bytes[1] calldata a, bytes[1] calldata b)
external
returns (uint256, uint256, uint256, uint256, uint256, uint256, uint256)
{
return (
a[0].length,
uint8(a[0][0]),
uint8(a[0][1]),
uint8(a[0][2]),
b[0].length,
uint8(b[0][0]),
uint8(b[0][1])
);
}
function g1(bytes[2] calldata a)
external
returns (
uint256,
uint256,
uint256,
uint256,
uint256,
uint256,
uint256,
uint256
)
{
return (
a[0].length,
uint8(a[0][0]),
uint8(a[0][1]),
uint8(a[0][2]),
a[1].length,
uint8(a[1][0]),
uint8(a[1][1]),
uint8(a[1][2])
);
}
function g2(bytes[] calldata a) external returns (uint256[8] memory) {
return [
a.length,
a[0].length,
uint8(a[0][0]),
uint8(a[0][1]),
a[1].length,
uint8(a[1][0]),
uint8(a[1][1]),
uint8(a[1][2])
];
}
}
// found expectation comments:
// same offset for both arrays @ ABI_CHECK(
// ----
// f1(bytes[1]): 0x20, 0x20, 0x3, hex"0102030000000000000000000000000000000000000000000000000000000000" -> 0x3, 0x1, 0x2, 0x3
// f2(bytes[1],bytes[1]): 0x40, 0xa0, 0x20, 0x3, hex"0102030000000000000000000000000000000000000000000000000000000000", 0x20, 0x2, hex"0102000000000000000000000000000000000000000000000000000000000000" -> 0x3, 0x1, 0x2, 0x3, 0x2, 0x1, 0x2
// g1(bytes[2]): 0x20, 0x40, 0x80, 0x3, hex"0102030000000000000000000000000000000000000000000000000000000000", 0x3, hex"0405060000000000000000000000000000000000000000000000000000000000" -> 0x3, 0x1, 0x2, 0x3, 0x3, 0x4, 0x5, 0x6
// g1(bytes[2]): 0x20, 0x40, 0x40, 0x3, hex"0102030000000000000000000000000000000000000000000000000000000000" -> 0x3, 0x1, 0x2, 0x3, 0x3, 0x1, 0x2, 0x3
// g2(bytes[]): 0x20, 0x2, 0x40, 0x80, 0x2, hex"0102000000000000000000000000000000000000000000000000000000000000", 0x3, hex"0405060000000000000000000000000000000000000000000000000000000000" -> 0x2, 0x2, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6

View File

@ -0,0 +1,18 @@
pragma experimental ABIEncoderV2;
contract C {
function f(bytes[] calldata a)
external
returns (uint256, uint256, bytes memory)
{
bytes memory m = a[0];
return (a.length, m.length, m);
}
}
// ----
// f(bytes[]): 0x20, 0x1, 0x20, 0x2, hex"6162000000000000000000000000000000000000000000000000000000000000" -> 0x1, 0x2, 0x60, 0x2, hex"6162000000000000000000000000000000000000000000000000000000000000"
// f(bytes[]): 0x20, 0x1, 0x20, 0x20, hex"7878787878787878787878787878787878787878787878787878787878787878" -> 0x1, 0x20, 0x60, 0x20, hex"7878787878787878787878787878787878787878787878787878787878787878"
// f(bytes[]): 0x20, 0x1, 0x20, 0x20, hex"7800000000000000000000000000000000000000000000000000000000000061" -> 0x1, 0x20, 0x60, 0x20, hex"7800000000000000000000000000000000000000000000000000000000000061"
// f(bytes[]): 0x20, 0x1, 0x20, 0x20, hex"6100000000000000000000000000000000000000000000000000000000000078" -> 0x1, 0x20, 0x60, 0x20, hex"6100000000000000000000000000000000000000000000000000000000000078"
// f(bytes[]): 0x20, 0x1, 0x20, 0x20, hex"616d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d78" -> 0x1, 0x20, 0x60, 0x20, hex"616d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d6d78"

View File

@ -0,0 +1,15 @@
pragma experimental ABIEncoderV2;
contract C {
function f(string[] calldata a)
external
returns (uint256, uint256, uint256, string memory)
{
string memory s1 = a[0];
bytes memory m1 = bytes(s1);
return (a.length, m1.length, uint8(m1[0]), s1);
}
}
// ----
// f(string[]): 0x20, 0x1, 0x20, 0x2, hex"6162000000000000000000000000000000000000000000000000000000000000" -> 1, 2, 97, 0x80, 2, "ab"

View File

@ -0,0 +1,22 @@
pragma experimental ABIEncoderV2;
contract C {
struct S {
uint8 a;
bytes1 b;
}
function f(S calldata s) external pure returns (uint256 a, bytes32 b) {
uint8 tmp1 = s.a;
bytes1 tmp2 = s.b;
assembly {
a := tmp1
b := tmp2
}
}
}
// ----
// f((uint8,bytes1)): 0x12, hex"3400000000000000000000000000000000000000000000000000000000000000" -> 0x12, hex"3400000000000000000000000000000000000000000000000000000000000000" # double check that the valid case goes through #
// f((uint8,bytes1)): 0x1234, hex"5678000000000000000000000000000000000000000000000000000000000000" -> FAILURE
// f((uint8,bytes1)): 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff, 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff -> FAILURE

View File

@ -0,0 +1,23 @@
contract C {
function f(bool _b) public returns (uint256) {
if (_b) return 1;
else return 0;
}
function g(bool _in) public returns (bool _out) {
_out = _in;
}
}
// ====
// ABIEncoderV1Only: true
// ----
// f(bool): 0x0 -> 0x0
// f(bool): 0x1 -> 0x1
// f(bool): 0x2 -> 0x1
// f(bool): 0x3 -> 0x1
// f(bool): 0xff -> 0x1
// g(bool): 0x0 -> 0x0
// g(bool): 0x1 -> 0x1
// g(bool): 0x2 -> 0x1
// g(bool): 0x3 -> 0x1
// g(bool): 0xff -> 0x1

View File

@ -0,0 +1,24 @@
pragma experimental ABIEncoderV2;
contract C {
function f(bool _b) public returns (uint256) {
if (_b) return 1;
else return 0;
}
function g(bool _in) public returns (bool _out) {
_out = _in;
}
}
// ----
// f(bool): 0x0 -> 0x0
// f(bool): 0x1 -> 0x1
// f(bool): 0x2 -> FAILURE
// f(bool): 0x3 -> FAILURE
// f(bool): 0xff -> FAILURE
// g(bool): 0x0 -> 0x0
// g(bool): 0x1 -> 0x1
// g(bool): 0x2 -> FAILURE
// g(bool): 0x3 -> FAILURE
// g(bool): 0xff -> FAILURE

View File

@ -0,0 +1,17 @@
// Checks that address types are properly cleaned before they are compared.
contract C {
function f(address a) public returns (uint256) {
if (a != 0x1234567890123456789012345678901234567890) return 1;
return 0;
}
function g(address payable a) public returns (uint256) {
if (a != 0x1234567890123456789012345678901234567890) return 1;
return 0;
}
}
// ====
// ABIEncoderV1Only: true
// ----
// f(address): 0xffff1234567890123456789012345678901234567890 -> 0x0 # We input longer data on purpose.#
// g(address): 0xffff1234567890123456789012345678901234567890 -> 0x0

View File

@ -0,0 +1,18 @@
pragma experimental ABIEncoderV2;
// Checks that address types are properly cleaned before they are compared.
contract C {
function f(address a) public returns (uint256) {
if (a != 0x1234567890123456789012345678901234567890) return 1;
return 0;
}
function g(address payable a) public returns (uint256) {
if (a != 0x1234567890123456789012345678901234567890) return 1;
return 0;
}
}
// ----
// f(address): 0xffff1234567890123456789012345678901234567890 -> FAILURE # We input longer data on purpose.#
// g(address): 0xffff1234567890123456789012345678901234567890 -> FAILURE

View File

@ -0,0 +1,13 @@
// Checks that bytesXX types are properly cleaned before they are compared.
contract C {
function f(bytes2 a, uint16 x) public returns (uint256) {
if (a != "ab") return 1;
if (x != 0x0102) return 2;
if (bytes3(uint24(x)) != 0x000102) return 3;
return 0;
}
}
// ====
// ABIEncoderV1Only: true
// ----
// f(bytes2,uint16): "abc", 0x40102 -> 0x0 # We input longer data on purpose. #

View File

@ -0,0 +1,14 @@
pragma experimental ABIEncoderV2;
// Checks that bytesXX types are properly cleaned before they are compared.
contract C {
function f(bytes2 a, uint16 x) public returns (uint256) {
if (a != "ab") return 1;
if (x != 0x0102) return 2;
if (bytes3(uint24(x)) != 0x000102) return 3;
return 0;
}
}
// ----
// f(bytes2,uint16): "abc", 0x40102 -> FAILURE # We input longer data on purpose. #

View File

@ -0,0 +1,37 @@
contract C {
uint256 value;
function set(uint256 _value) external {
value = _value;
}
function get() external view returns (uint256) {
return value;
}
function get_delegated() external returns (bool, bytes memory) {
return address(this).delegatecall(abi.encodeWithSignature("get()"));
}
function assert0() external view {
assert(value == 0);
}
function assert0_delegated() external returns (bool, bytes memory) {
return address(this).delegatecall(abi.encodeWithSignature("assert0()"));
}
}
// ====
// EVMVersion: >=byzantium
// ----
// get() -> 0x00
// assert0_delegated() -> 0x01, 0x40, 0x0
// get_delegated() -> 0x01, 0x40, 0x20, 0x0
// set(uint256): 0x01 ->
// get() -> 0x01
// assert0_delegated() -> 0x00, 0x40, 0x0
// get_delegated() -> 0x01, 0x40, 0x20, 0x1
// set(uint256): 0x2a ->
// get() -> 0x2a
// assert0_delegated() -> 0x00, 0x40, 0x0
// get_delegated() -> 0x01, 0x40, 0x20, 0x2a

View File

@ -0,0 +1,39 @@
contract C {
uint256 value;
function set(uint256 _value) external {
value = _value;
}
function get() external view returns (uint256) {
return value;
}
function get_delegated() external returns (bool) {
(bool success,) = address(this).delegatecall(abi.encodeWithSignature("get()"));
return success;
}
function assert0() external view {
assert(value == 0);
}
function assert0_delegated() external returns (bool) {
(bool success,) = address(this).delegatecall(abi.encodeWithSignature("assert0()"));
return success;
}
}
// ====
// EVMVersion: <byzantium
// ----
// get() -> 0x00
// assert0_delegated() -> true
// get_delegated() -> true
// set(uint256): 0x01 ->
// get() -> 0x01
// assert0_delegated() -> false
// get_delegated() -> true
// set(uint256): 0x2a ->
// get() -> 0x2a
// assert0_delegated() -> false
// get_delegated() -> true

View File

@ -0,0 +1,34 @@
contract C {
function shl(uint256 a, uint256 b) public returns (uint256 c) {
assembly {
c := shl(b, a)
}
}
function shr(uint256 a, uint256 b) public returns (uint256 c) {
assembly {
c := shr(b, a)
}
}
function sar(uint256 a, uint256 b) public returns (uint256 c) {
assembly {
c := sar(b, a)
}
}
}
// ====
// EVMVersion: >=constantinople
// compileViaYul: also
// ----
// shl(uint256,uint256): 0x01, 0x02 -> 0x04
// shl(uint256,uint256): 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff, 0x01 -> 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe
// shl(uint256,uint256): 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff, 0x100 -> 0x00
// shr(uint256,uint256): 0x03, 0x01 -> 0x01
// shr(uint256,uint256): 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff, 0x01 -> 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
// shr(uint256,uint256): 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff, 0xff -> 0x01
// shr(uint256,uint256): 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff, 0x100 -> 0x00
// sar(uint256,uint256): 0x03, 0x01 -> 0x01
// sar(uint256,uint256): 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff, 0x01 -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
// sar(uint256,uint256): 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff, 0xff -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
// sar(uint256,uint256): 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff, 0x100 -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff

View File

@ -0,0 +1,122 @@
contract C {
function shl_zero(uint256 a) public returns (uint256 c) {
assembly {
c := shl(0, a)
}
}
function shr_zero(uint256 a) public returns (uint256 c) {
assembly {
c := shr(0, a)
}
}
function sar_zero(uint256 a) public returns (uint256 c) {
assembly {
c := sar(0, a)
}
}
function shl_large(uint256 a) public returns (uint256 c) {
assembly {
c := shl(0x110, a)
}
}
function shr_large(uint256 a) public returns (uint256 c) {
assembly {
c := shr(0x110, a)
}
}
function sar_large(uint256 a) public returns (uint256 c) {
assembly {
c := sar(0x110, a)
}
}
function shl_combined(uint256 a) public returns (uint256 c) {
assembly {
c := shl(4, shl(12, a))
}
}
function shr_combined(uint256 a) public returns (uint256 c) {
assembly {
c := shr(4, shr(12, a))
}
}
function sar_combined(uint256 a) public returns (uint256 c) {
assembly {
c := sar(4, sar(12, a))
}
}
function shl_combined_large(uint256 a) public returns (uint256 c) {
assembly {
c := shl(0xd0, shl(0x40, a))
}
}
function shl_combined_overflow(uint256 a) public returns (uint256 c) {
assembly {
c := shl(0x01, shl(not(0x00), a))
}
}
function shr_combined_large(uint256 a) public returns (uint256 c) {
assembly {
c := shr(0xd0, shr(0x40, a))
}
}
function shr_combined_overflow(uint256 a) public returns (uint256 c) {
assembly {
c := shr(0x01, shr(not(0x00), a))
}
}
function sar_combined_large(uint256 a) public returns (uint256 c) {
assembly {
c := sar(0xd0, sar(0x40, a))
}
}
}
// ====
// EVMVersion: >=constantinople
// compileViaYul: also
// ----
// shl_zero(uint256): 0x00 -> 0x00
// shl_zero(uint256): 0xffff -> 0xffff
// shl_zero(uint256): 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
// shr_zero(uint256): 0x00 -> 0x00
// shr_zero(uint256): 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
// sar_zero(uint256): 0x00 -> 0x00
// sar_zero(uint256): 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
// shl_large(uint256): 0x00 -> 0x00
// shl_large(uint256): 0xffff -> 0x00
// shl_large(uint256): 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff -> 0x00
// shr_large(uint256): 0x00 -> 0x00
// shr_large(uint256): 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff -> 0x00
// sar_large(uint256): 0x00 -> 0x00
// sar_large(uint256): 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff -> 0x00
// sar_large(uint256): 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
// shl_combined(uint256): 0x00 -> 0x00
// shl_combined(uint256): 0xffff -> 0xffff0000
// shl_combined(uint256): 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000
// shr_combined(uint256): 0x00 -> 0x00
// shr_combined(uint256): 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
// sar_combined(uint256): 0x00 -> 0x00
// sar_combined(uint256): 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff -> 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
// sar_combined(uint256): 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
// shl_combined_large(uint256): 0x00 -> 0x00
// shl_combined_large(uint256): 0xffff -> 0x00
// shl_combined_large(uint256): 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff -> 0x00
// shl_combined_overflow(uint256): 0x02 -> 0x00
// shr_combined_large(uint256): 0x00 -> 0x00
// shr_combined_large(uint256): 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff -> 0x00
// shr_combined_overflow(uint256): 0x02 -> 0x00
// sar_combined_large(uint256): 0x00 -> 0x00
// sar_combined_large(uint256): 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff -> 0x00
// sar_combined_large(uint256): 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff

View File

@ -0,0 +1,83 @@
contract C {
function shl_1() public returns (bool) {
uint256 c;
assembly {
c := shl(2, 1)
}
assert(c == 4);
return true;
}
function shl_2() public returns (bool) {
uint256 c;
assembly {
c := shl(
1,
0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
)
}
assert(
c ==
0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe
);
return true;
}
function shl_3() public returns (bool) {
uint256 c;
assembly {
c := shl(
256,
0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
)
}
assert(c == 0);
return true;
}
function shr_1() public returns (bool) {
uint256 c;
assembly {
c := shr(1, 3)
}
assert(c == 1);
return true;
}
function shr_2() public returns (bool) {
uint256 c;
assembly {
c := shr(
1,
0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
)
}
assert(
c ==
0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
);
return true;
}
function shr_3() public returns (bool) {
uint256 c;
assembly {
c := shr(
256,
0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
)
}
assert(c == 0);
return true;
}
}
// ====
// EVMVersion: >=constantinople
// compileViaYul: also
// ----
// shl_1() -> 0x01
// shl_2() -> 0x01
// shl_3() -> 0x01
// shr_1() -> 0x01
// shr_2() -> 0x01
// shr_3() -> 0x01

View File

@ -0,0 +1,14 @@
contract C {
function f(uint8 a, uint8 b) public returns (uint256) {
assembly {
a := 0xffffffff
}
// Higher bits should be cleared before the shift
return a >> b;
}
}
// ====
// ABIEncoderV1Only: true
// ----
// f(uint8,uint8): 0x00, 0x04 -> 0x0f
// f(uint8,uint8): 0x00, 0x1004 -> 0x0f

View File

@ -0,0 +1,30 @@
contract C {
function f(int8 a, uint8 b) public returns (int256) {
assembly {
a := 0xfffffff0
}
// Higher bits should be signextended before the shift
return a >> b;
}
function g(int8 a, uint8 b) public returns (int256) {
assembly {
a := 0xf0
}
// Higher bits should be signextended before the shift
return a >> b;
}
}
// ====
// ABIEncoderV1Only: true
// ----
// f(int8,uint8): 0x00, 0x03 -> 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe
// f(int8,uint8): 0x00, 0x04 -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
// f(int8,uint8): 0x00, 0xff -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
// f(int8,uint8): 0x00, 0x1003 -> 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe
// f(int8,uint8): 0x00, 0x1004 -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
// g(int8,uint8): 0x00, 0x03 -> 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe
// g(int8,uint8): 0x00, 0x04 -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
// g(int8,uint8): 0x00, 0xff -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
// g(int8,uint8): 0x00, 0x1003 -> 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe
// g(int8,uint8): 0x00, 0x1004 -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff

View File

@ -0,0 +1,31 @@
pragma experimental ABIEncoderV2;
contract C {
function f(int8 a, uint8 b) public returns (int256) {
assembly {
a := 0xfffffff0
}
// Higher bits should be signextended before the shift
return a >> b;
}
function g(int8 a, uint8 b) public returns (int256) {
assembly {
a := 0xf0
}
// Higher bits should be signextended before the shift
return a >> b;
}
}
// ----
// f(int8,uint8): 0x00, 0x03 -> 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe
// f(int8,uint8): 0x00, 0x04 -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
// f(int8,uint8): 0x00, 0xff -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
// f(int8,uint8): 0x00, 0x1003 -> FAILURE
// f(int8,uint8): 0x00, 0x1004 -> FAILURE
// g(int8,uint8): 0x00, 0x03 -> 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe
// g(int8,uint8): 0x00, 0x04 -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
// g(int8,uint8): 0x00, 0xff -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
// g(int8,uint8): 0x00, 0x1003 -> FAILURE
// g(int8,uint8): 0x00, 0x1004 -> FAILURE

View File

@ -0,0 +1,15 @@
pragma experimental ABIEncoderV2;
contract C {
function f(uint8 a, uint8 b) public returns (uint256) {
assembly {
a := 0xffffffff
}
// Higher bits should be cleared before the shift
return a >> b;
}
}
// ----
// f(uint8,uint8): 0x00, 0x04 -> 0x0f
// f(uint8,uint8): 0x00, 0x1004 -> FAILURE

View File

@ -0,0 +1,13 @@
contract C {
function f(int16 a, int16 b) public returns (int16) {
return a >> b;
}
}
// ====
// ABIEncoderV1Only: true
// ----
// f(int16,int16): 0xff99, 0x00 -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff99
// f(int16,int16): 0xff99, 0x01 -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffcc
// f(int16,int16): 0xff99, 0x02 -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe6
// f(int16,int16): 0xff99, 0x04 -> 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9
// f(int16,int16): 0xff99, 0x08 -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff

View File

@ -0,0 +1,14 @@
pragma experimental ABIEncoderV2;
contract C {
function f(int16 a, int16 b) public returns (int16) {
return a >> b;
}
}
// ----
// f(int16,int16): 0xff99, 0x00 -> FAILURE
// f(int16,int16): 0xff99, 0x01 -> FAILURE
// f(int16,int16): 0xff99, 0x02 -> FAILURE
// f(int16,int16): 0xff99, 0x04 -> FAILURE
// f(int16,int16): 0xff99, 0x08 -> FAILURE

View File

@ -0,0 +1,13 @@
contract C {
function f(int32 a, int32 b) public returns (int32) {
return a >> b;
}
}
// ====
// ABIEncoderV1Only: true
// ----
// f(int32,int32): 0xffffff99, 0x00 -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff99
// f(int32,int32): 0xffffff99, 0x01 -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffcc
// f(int32,int32): 0xffffff99, 0x02 -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe6
// f(int32,int32): 0xffffff99, 0x04 -> 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9
// f(int32,int32): 0xffffff99, 0x08 -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff

View File

@ -0,0 +1,14 @@
pragma experimental ABIEncoderV2;
contract C {
function f(int32 a, int32 b) public returns (int32) {
return a >> b;
}
}
// ----
// f(int32,int32): 0xffffff99, 0x00 -> FAILURE
// f(int32,int32): 0xffffff99, 0x01 -> FAILURE
// f(int32,int32): 0xffffff99, 0x02 -> FAILURE
// f(int32,int32): 0xffffff99, 0x04 -> FAILURE
// f(int32,int32): 0xffffff99, 0x08 -> FAILURE

View File

@ -0,0 +1,13 @@
contract C {
function f(int8 a, int8 b) public returns (int8) {
return a >> b;
}
}
// ====
// ABIEncoderV1Only: true
// ----
// f(int8,int8): 0x99, 0x00 -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff99
// f(int8,int8): 0x99, 0x01 -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffcc
// f(int8,int8): 0x99, 0x02 -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe6
// f(int8,int8): 0x99, 0x04 -> 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9
// f(int8,int8): 0x99, 0x08 -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff

View File

@ -0,0 +1,14 @@
pragma experimental ABIEncoderV2;
contract C {
function f(int8 a, int8 b) public returns (int8) {
return a >> b;
}
}
// ----
// f(int8,int8): 0x99, 0x00 -> FAILURE
// f(int8,int8): 0x99, 0x01 -> FAILURE
// f(int8,int8): 0x99, 0x02 -> FAILURE
// f(int8,int8): 0x99, 0x04 -> FAILURE
// f(int8,int8): 0x99, 0x08 -> FAILURE

View File

@ -0,0 +1,69 @@
contract Test {
struct S {
uint8 x;
uint16 y;
uint256 z;
}
struct X {
uint8 x;
S s;
uint8[2] a;
}
X m_x;
function load()
public
returns (
uint256 a,
uint256 x,
uint256 y,
uint256 z,
uint256 a1,
uint256 a2
)
{
m_x.x = 1;
m_x.s.x = 2;
m_x.s.y = 3;
m_x.s.z = 4;
m_x.a[0] = 5;
m_x.a[1] = 6;
X memory d = m_x;
a = d.x;
x = d.s.x;
y = d.s.y;
z = d.s.z;
a1 = d.a[0];
a2 = d.a[1];
}
function store()
public
returns (
uint256 a,
uint256 x,
uint256 y,
uint256 z,
uint256 a1,
uint256 a2
)
{
X memory d;
d.x = 1;
d.s.x = 2;
d.s.y = 3;
d.s.z = 4;
d.a[0] = 5;
d.a[1] = 6;
m_x = d;
a = m_x.x;
x = m_x.s.x;
y = m_x.s.y;
z = m_x.s.z;
a1 = m_x.a[0];
a2 = m_x.a[1];
}
}
// ----
// load() -> 0x01, 0x02, 0x03, 0x04, 0x05, 0x06
// store() -> 0x01, 0x02, 0x03, 0x04, 0x05, 0x06

View File

@ -0,0 +1,30 @@
contract C {
struct X {
uint256 x1;
uint256 x2;
}
struct S {
uint256 s1;
uint256[3] s2;
X s3;
}
S s;
constructor() public {
uint256[3] memory s2;
s2[1] = 9;
s = S(1, s2, X(4, 5));
}
function get()
public
returns (uint256 s1, uint256[3] memory s2, uint256 x1, uint256 x2)
{
s1 = s.s1;
s2 = s.s2;
x1 = s.s3.x1;
x2 = s.s3.x2;
}
}
// ----
// get() -> 0x01, 0x00, 0x09, 0x00, 0x04, 0x05

View File

@ -0,0 +1,23 @@
// This triggered a bug in some version because the variable in the modifier was not
// unregistered correctly.
contract C {
uint256 public x;
modifier m1 {
address a1 = msg.sender;
x++;
_;
}
function f1() public m1() {
x += 7;
}
function f2() public m1() {
x += 3;
}
}
// ----
// f1() ->
// x() -> 0x08
// f2() ->
// x() -> 0x0c

View File

@ -0,0 +1,39 @@
contract C {
uint256 x;
function f() public returns (uint256) {
x = 3;
return 1;
}
}
interface CView {
function f() external view returns (uint256);
}
interface CPure {
function f() external pure returns (uint256);
}
contract D {
function f() public returns (uint256) {
return (new C()).f();
}
function fview() public returns (uint256) {
return (CView(address(new C()))).f();
}
function fpure() public returns (uint256) {
return (CPure(address(new C()))).f();
}
}
// ====
// EVMVersion: >=byzantium
// ----
// f() -> 0x1 # This should work, next should throw #
// fview() -> FAILURE
// fpure() -> FAILURE

View File

@ -0,0 +1,39 @@
contract C {
uint256 x;
function f() public returns (uint256) {
x = 3;
return 1;
}
}
interface CView {
function f() external view returns (uint256);
}
interface CPure {
function f() external pure returns (uint256);
}
contract D {
function f() public returns (uint256) {
return (new C()).f();
}
function fview() public returns (uint256) {
return (CView(address(new C()))).f();
}
function fpure() public returns (uint256) {
return (CPure(address(new C()))).f();
}
}
// ====
// EVMVersion: <byzantium
// ----
// f() -> 0x1
// fview() -> 1
// fpure() -> 1