shazow / whatsabi

Extract the ABI (and resolve proxies, and get other metadata) from Ethereum bytecode, even without source code.
https://shazow.github.io/whatsabi/
MIT License
1.04k stars 71 forks source link

feature req: pull addresses from bytecode #16

Closed eyooooo closed 1 year ago

eyooooo commented 1 year ago

just found this repo so gonna see if i can help with a PR but it would be awesome if this tool could also pull addresses from bytecode. im guessing we need the PUSH20 opcode and maybe some other jazz.

thanks :)

shazow commented 1 year ago

Certainly not hard to pull PUSH20s but it is hard to guarantee that they're address types. Could you talk more about your higher-level usecases? Maybe there are other interesting approaches to try.

eyooooo commented 1 year ago

Certainly not hard to pull PUSH20s but it is hard to guarantee that they're address types. Could you talk more about your higher-level usecases? Maybe there are other interesting approaches to try.

fastest reply to an github issue EVER. my use case is scanning deployed bytecode and looking for valid addresses.

thinking out loud - maybe like grabbing from PUSH20 and then confirming the checksum.

eyooooo commented 1 year ago

nah that wont work it comes through as all lowercase. scratch that.

edit: might not really be a way to guarantee it tbh...

shazow commented 1 year ago

Would you care if you have a bunch of false positives? If not, could just pull PUSH20s out using a fairly simple regexp. :)

eyooooo commented 1 year ago

i wouldnt mind xD im parsing out some contracts and it seems like a common false positive is 0xffffffffffffffffffffffffffffffffffffffff

eyooooo commented 1 year ago

i dont have any proof of this (yet) but might be useful to also check PUSH32 for 20 byte addresses in case someone out here doing something weird. just adding for the sake of completeness :)

shazow commented 1 year ago

I think this use case is better done separately. Here's an example that you could base off of: https://github.com/hananbeer/flaccid/blob/main/getSignatures.js

eyooooo commented 1 year ago

got it :) feel free to close/reject this issue if you'd like. thanks a lot.

shazow commented 1 year ago

Thanks! Would love to see what you come up with and how reliable it is, please share if you develop something! :) Maybe we can toss it in as a separate helper somewhere.

I don't think it makes a lot of sense to put it into the core disasm parsing routine since it won't help the rest of the stuff we're trying to deduce, at least not yet.