2

How can I decode the exacute function going through:

"0x3fc91a3afd70395cd496c647d5a6cc9d4b2b7fad" router

Etherscan decodes the data as follows:

0   commands    bytes   0x0b08

1   inputs  bytes[] 0x00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000001c6bf52634000
0x00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000001c6bf526340000000000000000000000000000000000000000000000000000005a8a3c2bfb9f900000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000833074394898d85071c267f48d62532a9901662a

2   deadline    uint256 1690632143

How can I decode the inputs in javascript.

2 Answers 2

0

Try using this website. You can also check other function bytecode by using the abi [1]: https://www.4byte.directory/signatures/

0

On a basic level:

>>> ROUTER_ADDRESS = '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD'
>>> ROUTER_ABI = '''
... [{"inputs":[{"components":[{"internalType":"address","name":"permit2","type":"address"},{"inte rnalType":"address","name":"weth9","type":"address"},{"internalType":"address","name":"seaportV1_5 ","type":"address"},{"internalType":"address","name":"seaportV1_4","type":"address"},{"internalTyp e":"address","name":"openseaConduit","type":"address"},{"internalType":"address","name":"nftxZap", "type":"address"},{"internalType":"address","name":"x2y2","type":"address"},{"internalType":"addre ss","name":"foundation","type":"address"},{"internalType":"address","name":"sudoswap","type":"addr ess"},{"internalType":"address","name":"elementMarket","type":"address"},{"internalType":"address" ,"name":"nft20Zap","type":"address"},{"internalType":"address","name":"cryptopunks","type":"addres s"},{"internalType":"address","name":"looksRareV2","type":"address"},{"internalType":"address","na me":"routerRewardsDistributor","type":"address"},{"internalType":"address","name":"looksRareReward sDistributor","type":"address"},{"internalType":"address","name":"looksRareToken","type":"address" },{"internalType":"address","name":"v2Factory","type":"address"},{"internalType":"address","name": "v3Factory","type":"address"},{"internalType":"bytes32","name":"pairInitCodeHash","type":"bytes32" },{"internalType":"bytes32","name":"poolInitCodeHash","type":"bytes32"}],"internalType":"struct Ro uterParameters","name":"params","type":"tuple"}],"stateMutability":"nonpayable","type":"constructo r"},{"inputs":[],"name":"BalanceTooLow","type":"error"},{"inputs":[],"name":"BuyPunkFailed","type" :"error"},{"inputs":[],"name":"ContractLocked","type":"error"},{"inputs":[],"name":"ETHNotAccepted ","type":"error"},{"inputs":[{"internalType":"uint256","name":"commandIndex","type":"uint256"},{"i nternalType":"bytes","name":"message","type":"bytes"}],"name":"ExecutionFailed","type":"error"},{" inputs":[],"name":"FromAddressIsNotOwner","type":"error"},{"inputs":[],"name":"InsufficientETH","t ype":"error"},{"inputs":[],"name":"InsufficientToken","type":"error"},{"inputs":[],"name":"Invalid Bips","type":"error"},{"inputs":[{"internalType":"uint256","name":"commandType","type":"uint256"}] ,"name":"InvalidCommandType","type":"error"},{"inputs":[],"name":"InvalidOwnerERC1155","type":"err or"},{"inputs":[],"name":"InvalidOwnerERC721","type":"error"},{"inputs":[],"name":"InvalidPath","t ype":"error"},{"inputs":[],"name":"InvalidReserves","type":"error"},{"inputs":[],"name":"InvalidSp ender","type":"error"},{"inputs":[],"name":"LengthMismatch","type":"error"},{"inputs":[],"name":"S liceOutOfBounds","type":"error"},{"inputs":[],"name":"TransactionDeadlinePassed","type":"error"},{ "inputs":[],"name":"UnableToClaim","type":"error"},{"inputs":[],"name":"UnsafeCast","type":"error" },{"inputs":[],"name":"V2InvalidPath","type":"error"},{"inputs":[],"name":"V2TooLittleReceived","t ype":"error"},{"inputs":[],"name":"V2TooMuchRequested","type":"error"},{"inputs":[],"name":"V3Inva lidAmountOut","type":"error"},{"inputs":[],"name":"V3InvalidCaller","type":"error"},{"inputs":[]," name":"V3InvalidSwap","type":"error"},{"inputs":[],"name":"V3TooLittleReceived","type":"error"},{" inputs":[],"name":"V3TooMuchRequested","type":"error"},{"anonymous":false,"inputs":[{"indexed":fal se,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"RewardsSent","type":"event" },{"inputs":[{"internalType":"bytes","name":"looksRareClaim","type":"bytes"}],"name":"collectRewar ds","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"byt es","name":"commands","type":"bytes"},{"internalType":"bytes[]","name":"inputs","type":"bytes[]"}] ,"name":"execute","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"interna lType":"bytes","name":"commands","type":"bytes"},{"internalType":"bytes[]","name":"inputs","type": "bytes[]"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"execute","output s":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":" payable","type":"receive"}],"stateMutability":"nonpayable","type":"function"},{"stateMutability":" 
... '''
>>>
>>> router = w3.eth.contract(address=ROUTER_ADDRESS, abi=ROUTER_ABI)
>>> tx = w3.eth.get_transaction('0xa6fd1bad03bc9ac90c0848d41b60825880509a7d528f3340f22e87a011e99b6 c')
>>> print(f'[+] INPUT: {router.decode_function_input(tx["input"])}')
[+] INPUT: (<Function execute(bytes,bytes[],uint256)>, {'commands': b'\x0b\x08', 'inputs': [b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x15\x1c\x964{\x00\x00', b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x15\x1c\x964{\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\\bU\xb5\xa3.\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xa0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xc0*\xaa9\xb2#\xfe\x8d\n\x0e\\O'\xea\xd9\x08<ul\xc2\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfdAN9\x15_\x91\xe9DC\xa9\xfe\x97\xe8VV\x9d\x0f^\xec"], 'deadline': 1693228895})
>>>

To get what you want, which I'm guessing is the decoded call data from the encoded calls:

>>> res[1]['commands'].hex()
'0b08'
>>> res[1]['inputs'][0].hex() #deposit eth -> weth
'000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000001151c96347b0000'
>>> res[1]['inputs'][1].hex() #swap
'000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000001151c96347b000000000000000000000000000000000000000000000000000000005c6255b5a32e00000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000fd414e39155f91e94443a9fe97e856569d0f5eec'

You will need some understanding of the called commands.

>>> decode(['uint256'], res[1]["inputs"][0][-32:])
(78000000000000000,)

Decode manually or use other contract abi to recursively decode just as we did with execute.

The usual sigs are not present there so cannot use the 4byte directory to look them up, but with some understanding of the swaps, an ability to read through the router, or even the motivation to go through the logs. You will be able to see what is decoded and called.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.