ethers-io / ethers.js

Complete Ethereum library and wallet implementation in JavaScript.
https://ethers.org/
MIT License
7.91k stars 1.84k forks source link

Decode 0x3593564c execute function #4809

Closed jazzlifepro closed 1 month ago

jazzlifepro commented 1 month ago

Ethers Version

6.13.2

Search Terms

abi, execute function, 0x3593564c, decode

Describe the Problem

I'm trying to decode parameter data in a swap transaction that uses function "0x3593564c execute" occurred on BSC TestNet to extract all the information they contain. The ABI is 'function execute(bytes calldata param1, bytes[] calldata param2, uint256 param3)'. Here is an example of the data that can be seen in the transaction details, in the Input Data field:" https://testnet.bscscan.com/tx/0xaa4eca5c9fbc195238fd2a5158e424cb899020f45dba0a8791963bded6ca4e4e 0 | commands | bytes | 0x0b00 1 | inputs | bytes[] | 0x000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000005af3107a4000 0x000000000000000000000000a9e4c77d44267f7f48f96c67fabee55783c6e1a400000000000000000000000000000000000000000000000000005af3107a400000000000000000000000000000000000000000000000000000069d506d8ae68d00000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002bae13d989dac2f0debff460ac112a837c89baa7cd0009c4ed24fc36d5ee211ea25a80239fb8c4cfd80f12ee000000000000000000000000000000000000000000 2 | deadline | uint256 | 1724064461

Param1: Commands Param2: Unknown Param3: Timestamp

I was searching on the internet for the param2 encoding format of this function but I couldn't find anything.

I've been trying various functions in ethers.js to decode this array of data, but none of them work without knowing its structure beforehand.

Code Snippet

No response

Contract ABI

'function execute(bytes calldata param1, bytes[] calldata param2, uint256 param3)'

Errors

No response

Environment

node.js (v12 or newer)

Environment (Other)

No response

ricmoo commented 1 month ago

Can you include the error you are getting? Also, what is the ABI used to encode the param2. If you want to decode the bytes, you need to know what format is used to encode it. If you have a link to the tx on block explorer, that'd be helpful too. :)

Few quick notes:

(chatted on Discord; the OP will update the issue shortly)

jazzlifepro commented 1 month ago

Can you include the error you are getting? Also, what is the ABI used to encode the param2. If you want to decode the bytes, you need to know what format is used to encode it. If you have a link to the tx on block explorer, that'd be helpful too. :)

Few quick notes:

  • the data (inputs) is 321 bytes long, which seems odd, since it should be a multiple of 32
  • no selector is present, so decoding will require using the low-level decode operations since the high-level API expects calldata.

(chatted on Discord; the OP will update the issue shortly)

I already updated the issue.

ricmoo commented 1 month ago

Sorry for the delay. Here is a complete working example, which should help:

import { ethers } from "./test.js";

(async function() {
  const hash = "0xaa4eca5c9fbc195238fd2a5158e424cb899020f45dba0a8791963bded6ca4e4e";

  // Connect to BNB testnet
  const provider = ethers.getDefaultProvider("bnbt");

  // Get the transaction from the network
  const tx = await provider.getTransaction(hash);

  // The minimal ABI needed for parsing
  const iface = new ethers.Interface([
    "function execute(bytes command, bytes[] inputs, uint deadline)"
  ]);

  // Parse the transaction; this will include a .args property
  const result = iface.parseTransaction(tx);
  console.log(result);
  // TransactionDescription {
  //   name: 'execute',
  //   args: Result(3) [
  //     '0x0b00',
  //     Result(2) [
  //       '0x000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000005af3107a4000',
  //       '0x000000000000000000000000a9e4c77d44267f7f48f96c67fabee55783c6e1a400000000000000000000000000000000000000000000000000005af3107a400000000000000000000000000000000000000000000000000000069d506d8ae68d00000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002bae13d989dac2f0debff460ac112a837c89baa7cd0009c4ed24fc36d5ee211ea25a80239fb8c4cfd80f12ee000000000000000000000000000000000000000000'
  //     ],
  //     1724064461n
  //   ],
  //   signature: 'execute(bytes,bytes[],uint256)',
  //   selector: '0x3593564c',
  //   value: 100000000000000n
  // }

  const { command, inputs, deadline } = result.args;
  console.log({ command, inputs, deadline });
  // {
  //   command: '0x0b00',
  //   inputs: Result(2) [
  //     '0x000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000005af3107a4000',
  //     '0x000000000000000000000000a9e4c77d44267f7f48f96c67fabee55783c6e1a400000000000000000000000000000000000000000000000000005af3107a400000000000000000000000000000000000000000000000000000069d506d8ae68d00000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002bae13d989dac2f0debff460ac112a837c89baa7cd0009c4ed24fc36d5ee211ea25a80239fb8c4cfd80f12ee000000000000000000000000000000000000000000'
  //   ],
  //   deadline: 1724064461n
  // }
})();

Let me know if anything needs further explanation. :)

(I'll move this from issues to discussions)