Git Product home page Git Product logo

abi-decoder's Introduction

Decode calldata without abi specification

This little program attemps to determine the structure of abi encoded data without knowing the abi specification. It was inspired by this excellent talk and primarily served as a learning project to better understand abi encoding and learn rust programming.

How to use it

Decode calldata from given transaction

cargo run 0x0031bd14c2a69ae3b4e1fbb986f7f5de1424e9f35501d7f166d10103c82de1cc

How it works

The output of this program will always be a "best guess" among many potential data formats that could have been encoded to the given calldata. The main assumption taken to get to decide which potential decoding to suggest is to prefer dynamically sized types. Therefore if a piece of data could be decoded as a dynamic array (i.e. address[]) or dynamic bytes / string this encoding is preferred over decoding the same piece of data as a collection of static types. (see below example for illustration)

Example

The following (hex-encoded) data:

0: 0000000000000000000000000000000000000000000000000000000000000020
1: 0000000000000000000000000000000000000000000000000000000000000002
2: 0000000000000000000000000000000000000000000000000000000000000003
3: 0000000000000000000000000000000000000000000000000000000000000004

Can be decoded as an array of two elements (3, and 4) because:

  1. Word 0 (32) is a valid memory offset pointing to Word 1
  2. Word 1 (2) is a valid array length that consumes the rest of the available data

Changing word 0 or word 1 on its own in any way or appending / removing elements from the data would break these assumptions and lead to the data not being a valid array anymore. Even though the same data could be decoded as individual pieces of staticly sized data (i.e. the numbers 32, 2, 3 and 4) it would be quite a coincidence. Therefore the dynamic / "more structured" interpretation of the data as an array is assumed more likely.

abi-decoder's People

Contributors

ckoopmann avatar

Stargazers

 avatar  avatar

Watchers

 avatar

abi-decoder's Issues

Add option to recursively decode dynamic bytes

Sometimes a bytes object is actually abi encoded data itself.
The user should have the option to let the algorithm recursively decode these elements for more insight.

This would make the tool more useful for example in the hack analysis from the talk that inspired this project in the first place.

See example test case:

"0x085beaf22438287312d56620973b9c00a82b99a44a6cf1f00ef6c88ab3656464",

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.