good morning!!!!

Skip to content
Snippets Groups Projects
readme.md 2.06 KiB
Newer Older
  • Learn to ignore specific revisions
  • a's avatar
    a committed
    # 4bytes
    
    ## what is
    
    this is an embeddable ethereum method signature db for go applications
    
    
    a's avatar
    a committed
    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 
    
    
    a's avatar
    a committed
    
    
    ## 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.
    
    
    a's avatar
    a committed
    
    
    a's avatar
    a committed
    ### how generate
    
    
    a's avatar
    a committed
    the datasets used are from  https://github.com/ethereum-lists/4bytes and https://github.com/wmitsuda/topic0
    
    a's avatar
    a committed
    
    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
    
    
    
    a's avatar
    a committed
    ### 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. 
    
    a's avatar
    a committed
    feel free to use it as template to make your.
    
    a's avatar
    a committed
    
    ## contributing
    
    happy to take any suggestions / fixes.
    
    feel free to email eddy@gfxlabs.io, or find me on the erigon discord