Currently, I am looking for a way to extract the metadata.json
file URL from the ethereum bytecode. I have referred to this doc and figured out that metadata mapping is stored CBOR-encoded manner. Hence, I used CBOR parser to decode it. Please find the below example.
Bytecode:
0x60806040526004361061002d5760003560e01c8063893d20e81461011c578063cf6cbb3d1461017357610117565b36610117576000803690501461004257600080fd5b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc349081150290604051600060405180830381858888f19350505050158015610
0a9573d6000803e3d6000fd5b507f6643d795ec4836e9ebd83ebe59402e7510c7fef7c2d84e7eee10ec77898e1d4a3334604051808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019250505060405180910390a1005b600080fd5b34801561012857600080fd5b506101316101ce565b604051808273fffffffff
fffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561017f57600080fd5b506101cc6004803603604081101561019657600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506101f7565b005b60008060009054906101000a9
00473ffffffffffffffffffffffffffffffffffffffff16905090565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461025057600080fd5b60008290508073ffffffffffffffffffffffffffffffffffffffff1663a9059cbb60008090549061010
00a900473ffffffffffffffffffffffffffffffffffffffff16846040518363ffffffff1660e01b8152600401808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050600060405180830381600087803b1580156102fd57600080fd5b505af1158015610311573d6000803e3d6000fd5b5050505060003d6
000811461032d576020811461033757600080fd5b6000199150610343565b60206000803e60005191505b508061034e57600080fd5b5050505056fea264697066735822122063fe8f2fa2dbda25d02e48cffe12a007baade89f2491b12f9c259644aa435b3464736f6c63430006080033
Metadata Hash of above bytecode (starting from 0xa264):
a264697066735822122063fe8f2fa2dbda25d02e48cffe12a007baade89f2491b12f9c259644aa435b3464736f6c63430006080033
User CBOR parser to decode:
echo a2646.....> | xxd -r -ps | python3 -m cbor2.tool --pretty
{
"ipfs": "\u0012 c\\xfe\\x8f/\\xa2\\xdb\\xda%\\xd0.H\\xcf\\xfe\u0012\\xa0\u0007\\xba\\xad\\xe8\\x9f$\\x91\\xb1/\\x9c%\\x96D\\xaaC[4",
"solc": "\u0000\u0006\b"
}
As in the above result, the CBOR parser still gives a Unicode string for IPFS and SOLC values. Is there any approach or method to derive the IPFS metadata.json file path from this result? My ultimate goal is to get the contract ABI/metadata from the EVM bytecode.
Please advise me if I am following the wrong way.