Decompiling Contract Bytecode for Function Extraction

On OP_NET, decompiling contract bytecode is a useful way to explore the functions a smart contract offers, especially when the ABI isn’t available. Using tools like OPScan (similar to Etherscan) and OPDecompiler, you can identify function names and selectors. While OPDecompiler won’t provide the full ABI, it can give you the function names, which is enough to interact with the contract.


Step 1: Retrieve Contract Bytecode from OPScan

To start, you’ll need the bytecode of the smart contract. Here’s how to get it using OPScan:

  1. Go to OPScan: Visit OPScan, OP_NET’s blockchain explorer.

  2. Find the Contract: Enter the contract address in the search bar to locate the contract details.

  3. Copy the Bytecode: Scroll down to the "Bytecode" section and copy the entire bytecode string.


Step 2: Decompile Bytecode with OPDecompiler

With the bytecode in hand, you can use OPDecompiler to uncover the function names embedded in the contract.

  1. Access OPDecompiler: Head over to OPDecompiler.

  2. Paste the Bytecode: Input the bytecode you copied from OPScan.

  3. Click "Decompile": Once you paste the bytecode, click the "Decompile" button.


Step 3: Analyze the Decompiled Output

Once you decompile the bytecode using OPDecompiler, you'll see a list of function names and selectors. Keep in mind that the decompiler doesn't provide the full ABI or the exact parameter types, but it gives you enough information to identify key functions. Here's an example output from decompiling the bytecode of an OP_20 token contract (in this case, the Moto token):

Moto
MOTO
e0801
owner
allowance
approve
balanceOf
burn
mint
transfer
decimals
name
symbol
totalSupply
maxSupply
airdrop
c00b0c0c
P0f900f0c
Mint
eApprove
aEmpty
Burn
Transfer
abcdef
b019101a01a
amaximumSupply
A8210A82

In this output:

  • Functions like owner, allowance, balanceOf, transfer, mint, and burn are common in token contracts, especially those following the OP_20 standard.

  • Custom functions like airdrop and maximumSupply are also identified.

Last updated