-
Notifications
You must be signed in to change notification settings - Fork 21
Contract ABI
Canonicalizes and parses function signatures, encodes and decodes contract ABI calls. Offers detailed error messages for illegal signature syntax and non-matching arguments.
Supports Java types of Integer
, int[]
, Long
, long[]
, BigInteger
, BigDecimal
, Boolean
, boolean[]
, String
, byte[]
, a custom Tuple
type, and arrays of any of these. Arrays can have up to 255 dimensions (max allowed by Java) and tuples can be arbitrarily nested (tested to depth of 2000). Can handle roughly 225,000 function call encodes or decodes per second, single-threaded on a laptop.
Function f = new Function("baz(uint32,bool)");
Tuple argsTuple = new Tuple(69L, true);
ByteBuffer one = f.encodeCall(argsTuple);
ByteBuffer two = f.encodeCallForArgs(69L, true);
System.out.println(Function.formatABI(one.array()));
Tuple decoded = f.decodeCall((ByteBuffer) two.flip());
System.out.println(decoded.equals(argsTuple));
MonteCarloTest generates a random function signature, parses it, generates random matching arguments, encodes and decodes a function call, and tests for equality. Done N times successively. Randomness is derived from an inital seed, and is fully replayable. Customizable parameters for maximum tuple/array depth/length are used to constrain memory usage and running time.
Before encoding, the output length is calculated so that a buffer of the correct length can be allocated. Encoding is done strictly left-to-right (no backtracking to insert offsets).
During decode, dynamic element offsets are read but their values are not necessary to complete the process as decoding is done strictly left-to-right.
A limited number of reflective calls are used to support the decoding of multidimensional arrays whose types are known only at runtime.
Refer to https://github.com/esaulpaugh/headlong/wiki/Build
You may verify the artifacts on Maven Central with my public key (fingerprint D2EA 6BCD 43B3 663C DF62 22C1 35AE 09FD 38F0 CFAE
):
-----BEGIN PGP PUBLIC KEY BLOCK-----
mQENBFxH8QMBCADYL3yUozFs4jWSEpD3WDlvmVtwo0mu2AY4i4+IF679Zk7iDB+Q
COzcgGqmVsDlG7yUNGJ5q267BbMVM+XE+HAPiZgnh+a2q6hyW0Zt1BfArUUIqjSx
S16Yyl8FsXEMpLNF9AeE5QXcxfb4I/AIxWCWtq+UKY39ApgsiDvgjcIsutPxs7Cm
Fb9HjNnY48dGUEOew6QOdj+70dHwRW+O84h79L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