Newer
Older
# 4bytes
## what is
this is an embeddable ethereum method signature db for go applications
in package sigs, there is function signatures
it contains ~500,000 popular signatures, and will add ~26mb to your application binary
in package topics, there is topic[0]'s
it contains ~12,000 popular event hashes, and will add ~1mb to your application binary
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
## usage
if you want to use it, just do
```
go get -u gfx.cafe/open/4bytes
```
see `example.go` for example usage
tl;dr
```
import "gfx.cafe/open/4bytes/sigs"
fmt.Print(sigs.Hex("a9059cbb")) #transfer(address,uint256)
```
## how work
### how read
there are three files, zdict, sigData, hashTrie.
zdict is a zstd dictionary.
sigData is every single signature in db, sorted by hash, compressed with the zstd dictionary. they are laid out sequentially
hashTrie is a trie that stores 4 bytes -> {pos, sz}, where pos is the start point from sigData to read, and sz is the size
so, go into trie, lookup hash. if exists, then get sigData from pos to pos+sz. then decompress that data using the dictionary
this is very fast since its all in memory.
the datasets used are from https://github.com/ethereum-lists/4bytes and https://github.com/wmitsuda/topic0
first, i create a 32kb dictionary for std decoding. this seemed to work okay and isnt too big. bigger didnt help. this is trained using a subset of files. since signatures share so much info, it is more than plenty
so we have hashes and signatures, along with a compression dictionary
then i iterate over all hashes and signatures, creating key value pairs as i compress each signature and append to the sigData
then using package github.com/openacid/slim i create a trie of all the key-value pairs
### triemap
triemap package is where all the logic for reading the files is
### _hack/gen
in hack/gen is the script i use to generate these. it's sorta lol, but it works.