Split calldataEncodedSize into calldataEncodedSize, calldataEncodedTailSize and calldataHeadSize and fix all usages.

This commit is contained in:
mingchuan
2019-08-08 15:52:21 +02:00
committed by Daniel Kirchner
parent d44f680a51
commit 15631a7fbe
11 changed files with 194 additions and 123 deletions
@@ -0,0 +1,11 @@
pragma experimental ABIEncoderV2;
contract C {
function f(uint256[][2][] calldata x) external returns (uint256) {
x[0]; // trigger bounds checks
return 23;
}
}
// ----
// f(uint256[][2][]): 0x20, 0x01, 0x20, 0x40, 0x60, 0x00, 0x00 -> 23 # this is the common encoding for x.length == 1 && x[0][0].length == 0 && x[0][1].length == 0 #
// f(uint256[][2][]): 0x20, 0x01, 0x20, 0x00, 0x00 -> 23 # exotic, but still valid encoding #
// f(uint256[][2][]): 0x20, 0x01, 0x20, 0x00 -> FAILURE # invalid (too short) encoding, but no failure due to this PR #
@@ -0,0 +1,13 @@
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);
}
}
// ----
// g(uint256[][2][]): 0x20, 0x01, 0x20, 0x40, 0x60, 0x00, 0x00 -> 42
// g(uint256[][2][]): 0x20, 0x01, 0x20, 0x00, 0x00 -> 42
// g(uint256[][2][]): 0x20, 0x01, 0x20, 0x00 -> FAILURE
@@ -0,0 +1,23 @@
pragma experimental ABIEncoderV2;
contract C {
struct A {
uint256 a;
uint256[] b;
}
struct B {
A a;
uint256 b;
}
function g(B calldata b) external pure returns(uint256) {
return b.b;
}
function f() public view returns(uint256, uint256) {
uint256[] memory arr = new uint256[](20);
arr[0] = 31; arr[2] = 84;
B memory b = B(A(420, arr), 11);
return (b.b, this.g(b));
}
}
// ----
// f() -> 11, 11