Skip to content

Instantly share code, notes, and snippets.

@hrkrshnn
Created September 9, 2021 11:53
Show Gist options
  • Save hrkrshnn/86b0ff81aaad64447633101032267e29 to your computer and use it in GitHub Desktop.
Save hrkrshnn/86b0ff81aaad64447633101032267e29 to your computer and use it in GitHub Desktop.
Optimized IR:
/*=====================================================*
* WARNING *
* Solidity to Yul compilation is still EXPERIMENTAL *
* It can result in LOSS OF FUNDS or worse *
* !USE AT YOUR OWN RISK! *
*=====================================================*/
/// @use-src 0:"/home/hari/s/4/test/libsolidity/semanticTests/userDefinedValueType/calldata.sol"
object "C_294" {
code {
{
/// @src 0:48:1650
mstore(64, 128)
if callvalue() { revert(0, 0) }
let _1 := datasize("C_294_deployed")
codecopy(128, dataoffset("C_294_deployed"), _1)
return(128, _1)
}
}
/// @use-src 0:"/home/hari/s/4/test/libsolidity/semanticTests/userDefinedValueType/calldata.sol"
object "C_294_deployed" {
code {
{
/// @src 0:48:1650
let _1 := 64
mstore(_1, 128)
if iszero(lt(calldatasize(), 4))
{
let _2 := 0
switch shr(224, calldataload(_2))
case 0x290c05ea {
if callvalue() { revert(_2, _2) }
let param, param_1 := abi_decode_array_userDefinedValueType_MyAddress_dyn_calldata(calldatasize())
fun_f(param, param_1)
return(mload(_1), _2)
}
case 0x937b5cdc {
if callvalue() { revert(_2, _2) }
abi_decode_2415(calldatasize())
let ret := fun_test_f()
let memPos := mload(_1)
return(memPos, sub(abi_encode_bool(memPos, ret), memPos))
}
case 0xc51b800f {
if callvalue() { revert(_2, _2) }
abi_decode_2415(calldatasize())
let ret_1 := fun_test_g()
let memPos_1 := mload(_1)
return(memPos_1, sub(abi_encode_bool(memPos_1, ret_1), memPos_1))
}
case 0xcb77ae28 {
if callvalue() { revert(_2, _2) }
fun_g(abi_decode_array_userDefinedValueType_MyAddress_dyn(calldatasize()))
return(mload(_1), _2)
}
case 0xedf26d9b {
if callvalue() { revert(_2, _2) }
let ret_2 := getter_fun_addresses(abi_decode_uint256(calldatasize()))
let memPos_2 := mload(_1)
return(memPos_2, sub(abi_encode_userDefinedValueType_MyAddress(memPos_2, ret_2), memPos_2))
}
}
revert(0, 0)
}
function abi_decode_array_userDefinedValueType_MyAddress_dyn_calldata(dataEnd) -> value0, value1
{
if slt(add(dataEnd, not(3)), 32) { revert(0, 0) }
let offset := calldataload(4)
let _1 := 0xffffffffffffffff
if gt(offset, _1) { revert(0, 0) }
if iszero(slt(add(offset, 35), dataEnd))
{
revert(/** @src -1:-1:-1 */ 0, 0)
}
/// @src 0:48:1650
let length := calldataload(add(4, offset))
if gt(length, _1)
{
revert(/** @src -1:-1:-1 */ 0, 0)
}
/// @src 0:48:1650
if gt(add(add(offset, shl(5, length)), 36), dataEnd)
{
revert(/** @src -1:-1:-1 */ 0, 0)
}
/// @src 0:48:1650
value0 := add(offset, 36)
value1 := length
}
function abi_decode_2415(dataEnd)
{
if slt(add(dataEnd, not(3)), 0) { revert(0, 0) }
}
function abi_decode(headStart, dataEnd)
{
if slt(sub(dataEnd, headStart), 0) { revert(0, 0) }
}
function abi_encode_bool(headStart, value0) -> tail
{
tail := add(headStart, 32)
mstore(headStart, iszero(iszero(value0)))
}
function panic_error_0x41()
{
mstore(0, shl(224, 0x4e487b71))
mstore(4, 0x41)
revert(0, 0x24)
}
function finalize_allocation_4673(memPtr)
{
let newFreePtr := add(memPtr, 192)
if or(gt(newFreePtr, 0xffffffffffffffff), lt(newFreePtr, memPtr)) { panic_error_0x41() }
mstore(64, newFreePtr)
}
function finalize_allocation(memPtr, size)
{
let newFreePtr := add(memPtr, and(add(size, 31), not(31)))
if or(gt(newFreePtr, 0xffffffffffffffff), lt(newFreePtr, memPtr)) { panic_error_0x41() }
mstore(64, newFreePtr)
}
function array_allocation_size_array_userDefinedValueType_MyAddress_dyn(length) -> size
{
if gt(length, 0xffffffffffffffff) { panic_error_0x41() }
size := add(shl(5, length), 0x20)
}
function validator_revert_userDefinedValueType_MyAddress(value)
{
if iszero(eq(value, and(value, sub(shl(160, 1), 1)))) { revert(0, 0) }
}
function abi_decode_array_userDefinedValueType_MyAddress_dyn(dataEnd) -> value0
{
let _1 := 32
if slt(add(dataEnd, not(3)), _1) { revert(0, 0) }
let offset := calldataload(4)
if gt(offset, 0xffffffffffffffff) { revert(0, 0) }
if iszero(slt(add(offset, 35), dataEnd))
{
revert(/** @src -1:-1:-1 */ 0, 0)
}
/// @src 0:48:1650
let _2 := calldataload(add(4, offset))
let _3 := array_allocation_size_array_userDefinedValueType_MyAddress_dyn(_2)
let memPtr := mload(64)
finalize_allocation(memPtr, _3)
let dst := memPtr
mstore(memPtr, _2)
dst := add(memPtr, _1)
let src := add(offset, 36)
if gt(add(add(offset, shl(5, _2)), 36), dataEnd)
{
revert(/** @src -1:-1:-1 */ 0, 0)
}
/// @src 0:48:1650
let i := /** @src -1:-1:-1 */ 0
/// @src 0:48:1650
for { } lt(i, _2) { i := add(i, 1) }
{
let value := calldataload(src)
validator_revert_userDefinedValueType_MyAddress(value)
mstore(dst, value)
dst := add(dst, _1)
src := add(src, _1)
}
value0 := memPtr
}
function abi_decode_uint256(dataEnd) -> value0
{
if slt(add(dataEnd, not(3)), 32) { revert(0, 0) }
value0 := calldataload(4)
}
function panic_error_0x32()
{
mstore(0, shl(224, 0x4e487b71))
mstore(4, 0x32)
revert(0, 0x24)
}
/// @src 0:65:93
function getter_fun_addresses(key) -> ret
{
if iszero(lt(key, /** @src 0:48:1650 */ sload(/** @src 0:65:93 */ 0))) { revert(0, 0) }
/// @src 0:48:1650
mstore(/** @src 0:65:93 */ 0, 0)
ret := /** @src 0:48:1650 */ sload(add(18569430475105882587588266137607568536673111973893317399460219858819262702947, key))
}
function abi_encode_userDefinedValueType_MyAddress(headStart, value0) -> tail
{
tail := add(headStart, 32)
mstore(headStart, and(value0, sub(shl(160, 1), 1)))
}
function increment_uint256(value) -> ret
{
if eq(value, not(0))
{
mstore(0, shl(224, 0x4e487b71))
mstore(4, 0x11)
revert(0, 0x24)
}
ret := add(value, 1)
}
function extract_returndata() -> data
{
switch returndatasize()
case 0 { data := 96 }
default {
let _1 := returndatasize()
if gt(_1, 0xffffffffffffffff) { panic_error_0x41() }
let memPtr := mload(64)
finalize_allocation(memPtr, add(and(add(_1, 31), not(31)), 0x20))
mstore(memPtr, _1)
data := memPtr
returndatacopy(add(memPtr, 0x20), /** @src -1:-1:-1 */ 0, /** @src 0:48:1650 */ returndatasize())
}
}
function update_storage_value_userDefinedValueType_MyAddress_to_userDefinedValueType_MyAddress(slot, value)
{
sstore(slot, and(value, sub(shl(160, 1), 1)))
}
function resize_array_array_userDefinedValueType_MyAddress_dyn_storage(newLen)
{
if gt(newLen, 18446744073709551616) { panic_error_0x41() }
/// @src 0:176:177
let _1 := 0x00
/// @src 0:48:1650
let oldLen := sload(/** @src 0:176:177 */ _1)
/// @src 0:48:1650
sstore(/** @src 0:176:177 */ _1, /** @src 0:48:1650 */ newLen)
if lt(newLen, oldLen)
{
mstore(/** @src 0:176:177 */ _1, _1)
/// @src 0:48:1650
let _2 := 18569430475105882587588266137607568536673111973893317399460219858819262702947
let _3 := add(_2, oldLen)
let start := add(_2, newLen)
for { } lt(start, _3) { start := add(start, 1) }
{
sstore(start, /** @src 0:176:177 */ _1)
}
}
}
/// @src 0:48:1650
function resize_array_array_userDefinedValueType_MyAddress_dyn_storage_4670()
{
/// @src 0:1335:1351
let _1 := 0
/// @src 0:48:1650
let oldLen := sload(/** @src 0:1335:1351 */ _1)
/// @src 0:48:1650
sstore(/** @src 0:1335:1351 */ _1, _1)
/// @src 0:48:1650
if iszero(iszero(oldLen))
{
mstore(/** @src 0:1335:1351 */ _1, _1)
/// @src 0:48:1650
let _2 := 18569430475105882587588266137607568536673111973893317399460219858819262702947
let _3 := add(_2, oldLen)
let start := _2
for { } lt(start, _3) { start := add(start, 1) }
{
sstore(start, /** @src 0:1335:1351 */ _1)
}
}
}
/// @src 0:99:310
function fun_f(var_addresses_offset, var_addresses_length)
{
/// @src 0:167:177
let var_i := /** @src 0:176:177 */ 0x00
/// @src 0:162:272
for { }
/** @src 0:179:200 */ lt(var_i, /** @src 0:183:200 */ var_addresses_length)
/// @src 0:167:177
{
/// @src 0:202:205
var_i := increment_uint256(var_i)
}
{
/// @src 0:48:1650
let value := calldataload(add(var_addresses_offset, shl(5, var_i)))
validator_revert_userDefinedValueType_MyAddress(value)
/// @src 0:221:261
pop(call(gas(), /** @src 0:48:1650 */ and(value, sub(shl(160, 1), 1)), /** @src 0:176:177 */ 0x00, /** @src 0:48:1650 */ mload(64), /** @src 0:176:177 */ 0x00, 0x00, 0x00))
/// @src 0:221:261
pop(extract_returndata())
}
/// @src 0:48:1650
resize_array_array_userDefinedValueType_MyAddress_dyn_storage(var_addresses_length)
let srcPtr := var_addresses_offset
mstore(/** @src 0:176:177 */ 0x00, 0x00)
/// @src 0:48:1650
let elementSlot := 18569430475105882587588266137607568536673111973893317399460219858819262702947
let i := /** @src 0:176:177 */ 0x00
/// @src 0:48:1650
for { } lt(i, var_addresses_length) { i := add(i, 1) }
{
let value_1 := calldataload(srcPtr)
validator_revert_userDefinedValueType_MyAddress(value_1)
update_storage_value_userDefinedValueType_MyAddress_to_userDefinedValueType_MyAddress(elementSlot, value_1)
srcPtr := add(srcPtr, 0x20)
elementSlot := add(elementSlot, 1)
}
}
function memory_array_index_access_userDefinedValueType_MyAddress_dyn_2433(baseRef) -> addr
{
if iszero(mload(baseRef)) { panic_error_0x32() }
addr := add(baseRef, 32)
}
function memory_array_index_access_userDefinedValueType_MyAddress_dyn_2435(baseRef) -> addr
{
if iszero(lt(/** @src 0:704:705 */ 0x01, /** @src 0:48:1650 */ mload(baseRef))) { panic_error_0x32() }
addr := add(baseRef, 64)
}
function memory_array_index_access_userDefinedValueType_MyAddress_dyn_2437(baseRef) -> addr
{
if iszero(lt(/** @src 0:751:752 */ 0x02, /** @src 0:48:1650 */ mload(baseRef))) { panic_error_0x32() }
addr := add(baseRef, 96)
}
function memory_array_index_access_userDefinedValueType_MyAddress_dyn_2447(baseRef) -> addr
{
if iszero(lt(/** @src 0:1136:1137 */ 0x03, /** @src 0:48:1650 */ mload(baseRef))) { panic_error_0x32() }
addr := add(baseRef, 128)
}
function memory_array_index_access_userDefinedValueType_MyAddress_dyn_2449(baseRef) -> addr
{
if iszero(lt(/** @src 0:1183:1184 */ 0x04, /** @src 0:48:1650 */ mload(baseRef))) { panic_error_0x32() }
addr := add(baseRef, 160)
}
function memory_array_index_access_userDefinedValueType_MyAddress_dyn(baseRef, index) -> addr
{
if iszero(lt(index, mload(baseRef))) { panic_error_0x32() }
addr := add(add(baseRef, shl(5, index)), 32)
}
/// @src 0:315:524
function fun_g(var_addresses_mpos)
{
/// @src 0:381:391
let var_i := /** @src 0:390:391 */ 0x00
/// @src 0:376:486
for { }
/** @src 0:381:391 */ 1
{
/// @src 0:416:419
var_i := increment_uint256(var_i)
}
{
/// @src 0:393:414
if iszero(lt(var_i, /** @src 0:48:1650 */ mload(/** @src 0:397:414 */ var_addresses_mpos)))
/// @src 0:393:414
{ break }
/// @src 0:48:1650
let cleaned := and(mload(/** @src 0:452:465 */ memory_array_index_access_userDefinedValueType_MyAddress_dyn(var_addresses_mpos, var_i)), /** @src 0:48:1650 */ sub(shl(160, 1), 1))
/// @src 0:435:475
pop(call(gas(), cleaned, /** @src 0:390:391 */ 0x00, /** @src 0:48:1650 */ mload(64), /** @src 0:390:391 */ 0x00, 0x00, 0x00))
/// @src 0:435:475
pop(extract_returndata())
}
/// @src 0:48:1650
let length := mload(var_addresses_mpos)
resize_array_array_userDefinedValueType_MyAddress_dyn_storage(length)
let _1 := 0x20
let srcPtr := add(var_addresses_mpos, _1)
mstore(/** @src 0:390:391 */ 0x00, 0x00)
/// @src 0:48:1650
let elementSlot := 18569430475105882587588266137607568536673111973893317399460219858819262702947
let i := /** @src 0:390:391 */ 0x00
/// @src 0:48:1650
for { } lt(i, length) { i := add(i, 1) }
{
update_storage_value_userDefinedValueType_MyAddress_to_userDefinedValueType_MyAddress(elementSlot, and(mload(srcPtr), sub(shl(160, 1), 1)))
srcPtr := add(srcPtr, _1)
elementSlot := add(elementSlot, 1)
}
}
function write_to_memory_userDefinedValueType_MyAddress_2434(memPtr)
{ mstore(memPtr, 21) }
function write_to_memory_userDefinedValueType_MyAddress_2436(memPtr)
{ mstore(memPtr, 22) }
function write_to_memory_userDefinedValueType_MyAddress_2438(memPtr)
{ mstore(memPtr, 23) }
function write_to_memory_userDefinedValueType_MyAddress(memPtr)
{ mstore(memPtr, 24) }
function write_to_memory_userDefinedValueType_MyAddress_2444(memPtr)
{ mstore(memPtr, 25) }
function write_to_memory_userDefinedValueType_MyAddress_2446(memPtr)
{ mstore(memPtr, 26) }
function write_to_memory_userDefinedValueType_MyAddress_2448(memPtr)
{ mstore(memPtr, 27) }
function write_to_memory_userDefinedValueType_MyAddress_2450(memPtr)
{ mstore(memPtr, 28) }
function abi_encode_array_userDefinedValueType_MyAddress_dyn(headStart, value0) -> tail
{
let _1 := 32
let tail_1 := add(headStart, _1)
mstore(headStart, _1)
let pos := tail_1
let length := mload(value0)
mstore(tail_1, length)
pos := add(headStart, 64)
let srcPtr := add(value0, _1)
let i := 0
for { } lt(i, length) { i := add(i, 1) }
{
mstore(pos, and(mload(srcPtr), sub(shl(160, 1), 1)))
pos := add(pos, _1)
srcPtr := add(srcPtr, _1)
}
tail := pos
}
function revert_forward()
{
let pos := mload(64)
returndatacopy(pos, 0, returndatasize())
revert(pos, returndatasize())
}
/// @src 0:529:862
function fun_test_f() -> var
{
/// @src 0:48:1650
resize_array_array_userDefinedValueType_MyAddress_dyn_storage_4670()
let memPtr := mload(64)
let newFreePtr := add(memPtr, 128)
if or(gt(newFreePtr, 0xffffffffffffffff), lt(newFreePtr, memPtr)) { panic_error_0x41() }
mstore(64, newFreePtr)
mstore(memPtr, /** @src 0:640:641 */ 0x03)
/// @src 0:48:1650
calldatacopy(add(memPtr, 0x20), calldatasize(), 96)
/// @src 0:652:689
write_to_memory_userDefinedValueType_MyAddress_2434(memory_array_index_access_userDefinedValueType_MyAddress_dyn_2433(memPtr))
/// @src 0:699:736
write_to_memory_userDefinedValueType_MyAddress_2436(memory_array_index_access_userDefinedValueType_MyAddress_dyn_2435(memPtr))
/// @src 0:746:783
write_to_memory_userDefinedValueType_MyAddress_2438(memory_array_index_access_userDefinedValueType_MyAddress_dyn_2437(memPtr))
/// @src 0:793:805
if iszero(extcodesize(/** @src 0:793:797 */ address()))
/// @src 0:793:805
{
/// @src 0:48:1650
revert(/** @src 0:1335:1351 */ 0, 0)
}
/// @src 0:793:805
let _1 := /** @src 0:48:1650 */ mload(64)
/// @src 0:793:805
mstore(_1, /** @src 0:48:1650 */ shl(225, 0x148602f5))
/// @src 0:793:805
let _2 := call(gas(), /** @src 0:793:797 */ address(), /** @src 0:1335:1351 */ 0, /** @src 0:793:805 */ _1, sub(abi_encode_array_userDefinedValueType_MyAddress_dyn(add(_1, 4), memPtr), _1), _1, /** @src 0:1335:1351 */ 0)
/// @src 0:793:805
if iszero(_2) { revert_forward() }
if _2
{
finalize_allocation(_1, returndatasize())
abi_decode(_1, add(_1, returndatasize()))
}
/// @src 0:829:833
fun_test_equality(memPtr)
/// @src 0:844:855
var := /** @src 0:704:705 */ 0x01
}
/// @src 0:867:1294
function fun_test_g() -> var_
{
/// @src 0:48:1650
resize_array_array_userDefinedValueType_MyAddress_dyn_storage_4670()
let memPtr := mload(64)
finalize_allocation_4673(memPtr)
mstore(memPtr, /** @src 0:978:979 */ 0x05)
/// @src 0:48:1650
calldatacopy(add(memPtr, 0x20), calldatasize(), 160)
/// @src 0:990:1027
write_to_memory_userDefinedValueType_MyAddress(memory_array_index_access_userDefinedValueType_MyAddress_dyn_2433(memPtr))
/// @src 0:1037:1074
write_to_memory_userDefinedValueType_MyAddress_2444(memory_array_index_access_userDefinedValueType_MyAddress_dyn_2435(memPtr))
/// @src 0:1084:1121
write_to_memory_userDefinedValueType_MyAddress_2446(memory_array_index_access_userDefinedValueType_MyAddress_dyn_2437(memPtr))
/// @src 0:1131:1168
write_to_memory_userDefinedValueType_MyAddress_2448(memory_array_index_access_userDefinedValueType_MyAddress_dyn_2447(memPtr))
/// @src 0:1178:1215
write_to_memory_userDefinedValueType_MyAddress_2450(memory_array_index_access_userDefinedValueType_MyAddress_dyn_2449(memPtr))
/// @src 0:1225:1237
if iszero(extcodesize(/** @src 0:1225:1229 */ address()))
/// @src 0:1225:1237
{
/// @src 0:48:1650
revert(/** @src 0:1335:1351 */ 0, 0)
}
/// @src 0:1225:1237
let _1 := /** @src 0:48:1650 */ mload(64)
/// @src 0:1225:1237
mstore(_1, /** @src 0:48:1650 */ shl(227, 0x196ef5c5))
/// @src 0:1225:1237
let _2 := call(gas(), /** @src 0:1225:1229 */ address(), /** @src 0:1335:1351 */ 0, /** @src 0:1225:1237 */ _1, sub(abi_encode_array_userDefinedValueType_MyAddress_dyn(add(_1, /** @src 0:1183:1184 */ 0x04), /** @src 0:1225:1237 */ memPtr), _1), _1, /** @src 0:1335:1351 */ 0)
/// @src 0:1225:1237
if iszero(_2) { revert_forward() }
if _2
{
finalize_allocation(_1, returndatasize())
abi_decode(_1, add(_1, returndatasize()))
}
/// @src 0:1261:1265
fun_test_equality(memPtr)
/// @src 0:1276:1287
var_ := /** @src 0:1042:1043 */ 0x01
}
/// @src 0:1363:1648
function fun_test_equality(var__addresses_mpos)
{
/// @src 0:1450:1467
let expr := /** @src 0:48:1650 */ mload(/** @src 0:1450:1467 */ var__addresses_mpos)
/// @src 0:1471:1480
let _1 := 0x00
/// @src 0:48:1650
let _2 := sload(/** @src 0:1471:1480 */ _1)
/// @src 0:48:1650
if iszero(/** @src 0:1450:1487 */ eq(expr, _2))
/// @src 0:48:1650
{
revert(/** @src 0:1471:1480 */ _1, _1)
}
/// @src 0:1503:1513
let var_i := /** @src 0:1471:1480 */ _1
/// @src 0:1498:1642
for { }
/** @src 0:1503:1513 */ 1
{
/// @src 0:1538:1541
var_i := increment_uint256(var_i)
}
{
/// @src 0:1515:1536
if iszero(lt(var_i, /** @src 0:48:1650 */ mload(/** @src 0:1519:1536 */ var__addresses_mpos)))
/// @src 0:1515:1536
{ break }
/// @src 0:48:1650
let _3 := sub(shl(160, 1), 1)
let cleaned := and(mload(/** @src 0:1582:1595 */ memory_array_index_access_userDefinedValueType_MyAddress_dyn(var__addresses_mpos, var_i)), /** @src 0:48:1650 */ _3)
if iszero(lt(var_i, _2)) { panic_error_0x32() }
mstore(/** @src 0:1471:1480 */ _1, _1)
/// @src 0:48:1650
if iszero(/** @src 0:1565:1630 */ eq(/** @src 0:48:1650 */ cleaned, and(sload(add(18569430475105882587588266137607568536673111973893317399460219858819262702947, var_i)), _3)))
{
revert(/** @src 0:1471:1480 */ _1, _1)
}
}
}
}
data ".metadata" hex"a2646970667358221220e318c9df8e925ba2d7ea5d2501f6999953a6987337511e49a416d50460ccfeb464736f6c637826302e382e382d646576656c6f702e323032312e392e392b636f6d6d69742e61303366626637300057"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment