headlong: A Contract ABI and RLP Library for the JVM by Evan Saulpaugh | Devcon Bogotá
Devcon 6 · 16 Oct 2022 · 5:45
Evan Saulpaugh describes headlong, a library implementing the Solidity contract ABI specification and RLP for the JVM. It parses any function signature or JSON description at runtime, type-checks inputs before encoding and outputs during decoding, and aims for faster encoding and decoding with better usability.
Speakers
Topics
From Devcon 6, hosted by Ethereum Foundation.
Transcript
foreign [Music] Library it uh it doesn't do anything else really it's just hyper focused it's used by Dune Unstoppable domains I figured that uh I wanted to make a general Solution that's like low level high performance that people can just build stuff on here's some just rough benchmarks for my laptop um you can do like partial decoding of uh call data for ABI so that's like the measured nanoseconds over there
so it works with bytes instead of strings so it's a lot faster than uh some other tools so yeah just very few dependencies supposed to be lightweight it's just sort of uh the general design philosophy around it and yeah Java so it does compatible with Android and kotlin and um it's like if you're using it on like a web server using decoding large amounts of data this is useful for something like that the other type of user I have is um like people are trying to work with like an array of structs inside a struct and like other tools aren't working for them
so uh like mine can decode any arbitrary function signature or data that matches any function signature so here's the API for like the rlp stuff this is different because uses an iterator pattern and it decodes on demand instead of uh eagerly yeah all these objects just sort of point at uh at a bite buffer and uh you can decode directly from the byte buffer on demand and so it saves some time there and then here's like the ABI stuff so all the objects are meant to be reused many times like the function object and they're stateless so you can
share them across threads or between code there's some decoding it also deals with Json so you can like parse Json and create a function from Json uh it also does event decoding as added recently um so just hear some details on you know how I got the performance benefits from you know using byte buffer and pre-calculating things and and holding on to them for like multiple encodings and decodings yeah and there's some denial of service protection for if you're decoding like untrusted data that wants to allocate like a huge array it'll throw an exception instead
of like allocating a gigabyte of uh memory yeah future work might involve um doing like more partial decodes like querying like nested tuples so like going to a specific index and then if that's a tuple go ahead and index and that and just pick out the thing you want to decode and just ignore everything else um but it requires like jumping around um the index and stuff and then yeah I've been talking to some people recently about a possible ABI V3 so um like I wrote a command line interface that can encode arguments as rlp and uses a lot less uh
bytes because you don't have an offset and all this zero padding and stuff like that so and then you can try that out if you want headlong clis like the command line interface and uh yeah faster simpler software Legos I kind of just want people to uh you know be able to build um modular stuff just so that you're not like weighted down by all these dependencies and like complex Frameworks where you have to read all this documentation and um just build something to last and then special thanks to Victor dylapine because uh he added some code
that now I can decode events with headlong and thanks do you have any plans for SSD support uh not right now I thought about maybe implementing something separate for SSE but uh I don't know if I'm gonna so maybe what does he uh good use cases for this Library I'll do an analytics uh start using it for like ingesting large amounts of data so they can put it into databases and like query it so like if you have a lot of historical data lying around do you want to decode like huge amounts of it
and gain insights from data and stuff otherwise it's just designed to work in every possible case nested arrays nested tuples tubular Rays drugs and stuff oh and there's no code generation so it's all just very uh traditional that way