Add interface signature generator

This commit is contained in:
nolash 2021-04-28 13:55:53 +02:00
parent 03856123d2
commit c956d9b202
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
5 changed files with 45 additions and 18 deletions

View File

@ -3,17 +3,22 @@
# File-version: 5
INPUTS = $(wildcard *.sol)
OUTPUTS = $(patsubst %.sol, %.json, $(INPUTS))
OUTPUTS_JSON = $(patsubst %.sol, %.json, $(INPUTS))
OUTPUTS_INTERFACE = $(patsubst %.sol, %.interface, $(INPUTS))
OUTPUTS = ${OUTPUTS_JSON} ${OUTPUTS_INTERFACE}
PREFIX = /usr/local/share/cic/solidity/abi
#%.abi.json: $(wildcard *.sol)
# install -vDm0644 $@ $(PREFIX)/$@
.SUFFIXES: .sol .json
.SUFFIXES: .sol .json .interface
.sol.json:
solc $(basename $@).sol --abi | awk 'NR>3' > $@
.sol.interface:
bash $(basename $@).sol > $@
all: $(OUTPUTS)
install: $(OUTPUTS)

29
calculate_eip165.py Normal file
View File

@ -0,0 +1,29 @@
# standard imports
import logging
import sys
# external imports
import sha3
#logging.basicConfig(level=logging.WARNING)
logging.basicConfig(level=logging.DEBUG)
logg = logging.getLogger()
if __name__ == '__main__':
f = open(sys.argv[1], 'r')
z = b''
for i in range(32):
z += b'\x00'
while True:
l = f.readline().rstrip()
if l == '':
break
logg.debug('line {}'.format(l))
h = sha3.keccak_256()
h.update(l.encode('utf-8'))
r = h.digest()
z = bytes([a ^ b for a, b in zip(r, z)])
logg.debug('{} -> {}'.format(r.hex(), z.hex()))
f.close()
print(z[:4].hex())

View File

@ -1,16 +0,0 @@
import sys
import web3
f = open(sys.argv[1], 'r')
z = b''
for i in range(32):
z += b'\x00'
while True:
l = f.readline()
if l == '':
break
print('line {}'.format(l))
h = web3.Web3.keccak(text=l)
z = bytes([a ^ b for a, b in zip(h, z)])
print(h.hex(), z.hex())
f.close()

9
to_interface.sh Normal file
View File

@ -0,0 +1,9 @@
#!/bin/bash
d=`mktemp -d`
b=`basename $1`
s=${b%%.*}
echo $s
python3 reduce_to_methods.py $1 > $d/$b
python3 calculate_eip165.py $d/$b > ${s}.interface
>&2 echo $d/$b