Skip to content

Instantly share code, notes, and snippets.

@chriseth
Created May 28, 2019 19:08
Show Gist options
  • Save chriseth/4402022ba55f18bde768fc1f8bcaed29 to your computer and use it in GitHub Desktop.
Save chriseth/4402022ba55f18bde768fc1f8bcaed29 to your computer and use it in GitHub Desktop.
/*******************************************************
* WARNING *
* Solidity to Yul compilation is still EXPERIMENTAL *
* It can result in LOSS OF FUNDS or worse *
* !USE AT YOUR OWN RISK! *
*******************************************************/
object "ERC20_396" {
code {
{
mstore(64, 128)
if callvalue() { revert(0, 0) }
if iszero(caller())
{
let fmp := mload(64)
mstore(fmp, 0x08c379a000000000000000000000000000000000000000000000000000000000)
mstore(add(fmp, 4), 32)
revert(fmp, sub(abi_encode_t_stringliteral_fc0b381caf0a47702017f3c4b358ebe3d3aff6c60ce819a8bf3ef5a95d4f202e_to_t_string_memory_ptr_fromStack(add(fmp, 36)), fmp))
}
sstore(0x2, checked_add_uint_256(sload(0x2), 0x14))
sstore(mapping_index_access_t_mapping$_t_address_$_t_mapping$_t_address_$_t_uint256_$_$_of_t_address(0x0, caller()), checked_add_uint_256(sload(mapping_index_access_t_mapping$_t_address_$_t_mapping$_t_address_$_t_uint256_$_$_of_t_address(0x0, caller())), 0x14))
let _1 := mload(64)
log3(_1, sub(abi_encode_tuple_t_uint256__to_t_uint256__fromStack(_1, 0x14), _1), 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef, 0x0, caller())
let _2 := datasize("ERC20_396_deployed")
codecopy(0x0, dataoffset("ERC20_396_deployed"), _2)
return(0x0, _2)
}
function abi_encode_t_stringliteral_fc0b381caf0a47702017f3c4b358ebe3d3aff6c60ce819a8bf3ef5a95d4f202e_to_t_string_memory_ptr_fromStack(pos) -> end
{
mstore(pos, 31)
mstore(add(pos, 0x20), 0x45524332303a206d696e7420746f20746865207a65726f206164647265737300)
end := add(pos, 64)
}
function abi_encode_tuple_t_uint256__to_t_uint256__fromStack(headStart, value0) -> tail
{
tail := add(headStart, 32)
mstore(headStart, value0)
}
function checked_add_uint_256(x, y) -> sum
{
sum := add(x, y)
if lt(sum, x) { revert(0, 0) }
}
function mapping_index_access_t_mapping$_t_address_$_t_mapping$_t_address_$_t_uint256_$_$_of_t_address(slot, key) -> dataSlot
{
mstore(0, and(key, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))
mstore(0x20, slot)
dataSlot := keccak256(0, 0x40)
}
}
object "ERC20_396_deployed" {
code {
{
mstore(64, 128)
let _1 := 4
if iszero(lt(calldatasize(), _1))
{
let _2 := 0
switch shr(224, calldataload(_2))
case 0x095ea7b3 {
if callvalue() { revert(_2, _2) }
let param, param_1 := abi_decode_tuple_t_addresst_uint256(_1, calldatasize())
let ret := fun_approve_113(param, param_1)
let memPos := allocateMemory(_2)
return(memPos, sub(abi_encode_tuple_t_bool__to_t_bool__fromStack(memPos, ret), memPos))
}
case 0x18160ddd {
if callvalue() { revert(_2, _2) }
abi_decode_tuple_(_1, calldatasize())
let ret_1 := sload(0x2)
let memPos_1 := allocateMemory(_2)
return(memPos_1, sub(abi_encode_tuple_t_uint256__to_t_uint256__fromStack(memPos_1, ret_1), memPos_1))
}
case 0x23b872dd {
if callvalue() { revert(_2, _2) }
let param_2, param_3, param_4 := abi_decode_tuple_t_addresst_addresst_uint256(_1, calldatasize())
let ret_2 := fun_transferFrom_147(param_2, param_3, param_4)
let memPos_2 := allocateMemory(_2)
return(memPos_2, sub(abi_encode_tuple_t_bool__to_t_bool__fromStack(memPos_2, ret_2), memPos_2))
}
case 0x39509351 {
if callvalue() { revert(_2, _2) }
let param_5, param_6 := abi_decode_tuple_t_addresst_uint256(_1, calldatasize())
let ret_3 := fun_increaseAllowance_173(param_5, param_6)
let memPos_3 := allocateMemory(_2)
return(memPos_3, sub(abi_encode_tuple_t_bool__to_t_bool__fromStack(memPos_3, ret_3), memPos_3))
}
case 0x70a08231 {
if callvalue() { revert(_2, _2) }
let ret_4 := fun_balanceOf_59(abi_decode_tuple_t_address(_1, calldatasize()))
let memPos_4 := allocateMemory(_2)
return(memPos_4, sub(abi_encode_tuple_t_uint256__to_t_uint256__fromStack(memPos_4, ret_4), memPos_4))
}
case 0xa457c2d7 {
if callvalue() { revert(_2, _2) }
let param_7, param_8 := abi_decode_tuple_t_addresst_uint256(_1, calldatasize())
let ret_5 := fun_decreaseAllowance_199(param_7, param_8)
let memPos_5 := allocateMemory(_2)
return(memPos_5, sub(abi_encode_tuple_t_bool__to_t_bool__fromStack(memPos_5, ret_5), memPos_5))
}
case 0xa9059cbb {
if callvalue() { revert(_2, _2) }
let param_9, param_10 := abi_decode_tuple_t_addresst_uint256(_1, calldatasize())
let ret_6 := fun_transfer_94(param_9, param_10)
let memPos_6 := allocateMemory(_2)
return(memPos_6, sub(abi_encode_tuple_t_bool__to_t_bool__fromStack(memPos_6, ret_6), memPos_6))
}
case 0xdd62ed3e {
if callvalue() { revert(_2, _2) }
let param_11, param_12 := abi_decode_tuple_t_addresst_address(_1, calldatasize())
let value := sload(mapping_index_access_t_mapping$_t_address_$_t_mapping$_t_address_$_t_uint256_$_$_of_t_address(mapping_index_access_t_mapping$_t_address_$_t_mapping$_t_address_$_t_uint256_$_$_of_t_address(1, param_11), param_12))
let memPos_7 := allocateMemory(_2)
return(memPos_7, sub(abi_encode_tuple_t_uint256__to_t_uint256__fromStack(memPos_7, value), memPos_7))
}
}
revert(0, 0)
}
function abi_decode_t_address(offset, end) -> value
{
value := calldataload(offset)
if iszero(eq(value, and(value, sub(shl(160, 1), 1)))) { revert(0, 0) }
}
function abi_decode_tuple_(headStart, dataEnd)
{
if slt(sub(dataEnd, headStart), 0) { revert(0, 0) }
}
function abi_decode_tuple_t_address(headStart, dataEnd) -> value0
{
if slt(sub(dataEnd, headStart), 32) { revert(0, 0) }
value0 := abi_decode_t_address(headStart, dataEnd)
}
function abi_decode_tuple_t_addresst_address(headStart, dataEnd) -> value0, value1
{
if slt(sub(dataEnd, headStart), 64) { revert(0, 0) }
value0 := abi_decode_t_address(headStart, dataEnd)
value1 := abi_decode_t_address(add(headStart, 32), dataEnd)
}
function abi_decode_tuple_t_addresst_addresst_uint256(headStart, dataEnd) -> value0, value1, value2
{
if slt(sub(dataEnd, headStart), 96) { revert(0, 0) }
let value := calldataload(headStart)
validator_revert_t_address(value)
value0 := value
let value_1 := calldataload(add(headStart, 32))
validator_revert_t_address(value_1)
value1 := value_1
value2 := calldataload(add(headStart, 64))
}
function abi_decode_tuple_t_addresst_uint256(headStart, dataEnd) -> value0, value1
{
if slt(sub(dataEnd, headStart), 64) { revert(0, 0) }
value0 := abi_decode_t_address(headStart, dataEnd)
value1 := calldataload(add(headStart, 32))
}
function abi_encode_t_stringliteral_24883cc5fe64ace9d0df1893501ecb93c77180f0ff69cca79affb3c316dc8029_to_t_string_memory_ptr_fromStack(pos) -> end
{
mstore(pos, 34)
mstore(add(pos, 0x20), 0x45524332303a20617070726f766520746f20746865207a65726f206164647265)
mstore(add(pos, 64), shl(240, 29555))
end := add(pos, 96)
}
function abi_encode_tuple_t_bool__to_t_bool__fromStack(headStart, value0) -> tail
{
tail := add(headStart, 32)
mstore(headStart, iszero(iszero(value0)))
}
function abi_encode_tuple_t_uint256__to_t_uint256__fromStack(headStart, value0) -> tail
{
tail := add(headStart, 32)
mstore(headStart, value0)
}
function allocateMemory(size) -> memPtr
{
memPtr := mload(64)
let newFreePtr := add(memPtr, size)
if or(gt(newFreePtr, 0xffffffffffffffff), lt(newFreePtr, memPtr)) { revert(0, 0) }
mstore(64, newFreePtr)
}
function checked_add_uint_256(x, y) -> sum
{
sum := add(x, y)
if lt(sum, x) { revert(0, 0) }
}
function checked_sub_uint(x, y) -> diff
{
if lt(x, y) { revert(0, 0) }
diff := sub(x, y)
}
function fun__approve_368(vloc_owner, vloc_spender, vloc_value)
{
if iszero(vloc_owner)
{
let fmp := mload(64)
mstore(fmp, shl(229, 4594637))
mstore(add(fmp, 4), 32)
mstore(add(fmp, 36), 36)
mstore(add(fmp, 68), 0x45524332303a20617070726f76652066726f6d20746865207a65726f20616464)
mstore(add(fmp, 100), shl(224, 0x72657373))
revert(fmp, 132)
}
if iszero(vloc_spender)
{
let fmp_1 := mload(64)
mstore(fmp_1, shl(229, 4594637))
mstore(add(fmp_1, 4), 32)
revert(fmp_1, sub(abi_encode_t_stringliteral_24883cc5fe64ace9d0df1893501ecb93c77180f0ff69cca79affb3c316dc8029_to_t_string_memory_ptr_fromStack(add(fmp_1, 36)), fmp_1))
}
sstore(mapping_index_access_t_mapping$_t_address_$_t_mapping$_t_address_$_t_uint256_$_$_of_t_address(mapping_index_access_t_mapping$_t_address_$_t_mapping$_t_address_$_t_uint256_$_$_of_t_address(1, vloc_owner), vloc_spender), vloc_value)
let _1 := mload(64)
log3(_1, sub(abi_encode_tuple_t_uint256__to_t_uint256__fromStack(_1, vloc_value), _1), 0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925, vloc_owner, vloc_spender)
}
function fun__transfer_244(vloc_from, vloc_to, vloc_value)
{
let expr := 0x0
if iszero(vloc_to)
{
let fmp := mload(64)
mstore(fmp, shl(229, 4594637))
mstore(add(fmp, 4), 32)
mstore(add(fmp, 36), 35)
mstore(add(fmp, 68), 0x45524332303a207472616e7366657220746f20746865207a65726f2061646472)
mstore(add(fmp, 100), shl(232, 6648691))
revert(fmp, 132)
}
mstore(expr, and(vloc_from, sub(shl(160, 1), 1)))
mstore(0x20, expr)
sstore(mapping_index_access_t_mapping$_t_address_$_t_mapping$_t_address_$_t_uint256_$_$_of_t_address(expr, vloc_from), checked_sub_uint(sload(keccak256(expr, 0x40)), vloc_value))
sstore(mapping_index_access_t_mapping$_t_address_$_t_mapping$_t_address_$_t_uint256_$_$_of_t_address(expr, vloc_to), checked_add_uint_256(sload(mapping_index_access_t_mapping$_t_address_$_t_mapping$_t_address_$_t_uint256_$_$_of_t_address(expr, vloc_to)), vloc_value))
let _1 := mload(0x40)
log3(_1, sub(abi_encode_tuple_t_uint256__to_t_uint256__fromStack(_1, vloc_value), _1), 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef, vloc_from, vloc_to)
}
function fun_approve_113(vloc_spender, vloc_value) -> vloc
{
fun__approve_368(caller(), vloc_spender, vloc_value)
vloc := 1
}
function fun_balanceOf_59(vloc_owner) -> vloc
{
vloc := sload(mapping_index_access_t_mapping$_t_address_$_t_mapping$_t_address_$_t_uint256_$_$_of_t_address(0, vloc_owner))
}
function fun_decreaseAllowance_199(vloc_spender, vloc_subtractedValue) -> vloc
{
mstore(0, caller())
mstore(0x20, 1)
let _1 := sload(mapping_index_access_t_mapping$_t_address_$_t_mapping$_t_address_$_t_uint256_$_$_of_t_address(keccak256(0, 0x40), vloc_spender))
if lt(_1, vloc_subtractedValue) { revert(0, 0) }
fun__approve_368(caller(), vloc_spender, sub(_1, vloc_subtractedValue))
vloc := 1
}
function fun_increaseAllowance_173(vloc_spender, vloc_addedValue) -> vloc
{
mstore(0, caller())
mstore(0x20, 1)
fun__approve_368(caller(), vloc_spender, checked_add_uint_256(sload(mapping_index_access_t_mapping$_t_address_$_t_mapping$_t_address_$_t_uint256_$_$_of_t_address(keccak256(0, 0x40), vloc_spender)), vloc_addedValue))
vloc := 1
}
function fun_transferFrom_147(vloc_from, vloc_to, vloc_value) -> vloc
{
fun__transfer_244(vloc_from, vloc_to, vloc_value)
mstore(0, and(vloc_from, sub(shl(160, 1), 1)))
mstore(0x20, 1)
let _1 := sload(mapping_index_access_t_mapping$_t_address_$_t_mapping$_t_address_$_t_uint256_$_$_of_t_address(keccak256(0, 0x40), caller()))
if lt(_1, vloc_value) { revert(0, 0) }
fun__approve_368(vloc_from, caller(), sub(_1, vloc_value))
vloc := 1
}
function fun_transfer_94(vloc_to, vloc_value) -> vloc
{
fun__transfer_244(caller(), vloc_to, vloc_value)
vloc := 1
}
function mapping_index_access_t_mapping$_t_address_$_t_mapping$_t_address_$_t_uint256_$_$_of_t_address(slot, key) -> dataSlot
{
mstore(0, and(key, sub(shl(160, 1), 1)))
mstore(0x20, slot)
dataSlot := keccak256(0, 0x40)
}
function validator_revert_t_address(value)
{
if iszero(eq(value, and(value, sub(shl(160, 1), 1)))) { revert(0, 0) }
}
}
}
}
@malik672
Copy link

how did you get this good at writing in yul, need a guide

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment