Skip to content

Commit

Permalink
Use a different lib for abi parsing + add more methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ferranbt committed Feb 2, 2024
1 parent 61070f3 commit 3a3a24d
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 62 deletions.
4 changes: 3 additions & 1 deletion core/vm/contracts_suave.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ func (c *consoleLogPrecompile) RequiredGas(input []byte) uint64 {
}

func (c *consoleLogPrecompile) Run(input []byte) ([]byte, error) {
consolelog.Print(input)
if err := consolelog.Print(input); err != nil {
log.Error("failed to console2 print", "err", err)
}
return nil, nil
}

Expand Down
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ require (
github.com/golang-jwt/jwt/v4 v4.3.0
github.com/golang/protobuf v1.5.2
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb
github.com/google/gofuzz v1.1.1-0.20200604201612-c04b05f3adfa
github.com/google/gofuzz v1.2.0
github.com/google/uuid v1.3.1
github.com/gorilla/websocket v1.4.2
github.com/graph-gophers/graphql-go v1.3.0
Expand Down Expand Up @@ -66,6 +66,7 @@ require (
github.com/supranational/blst v0.3.11-0.20230406105308-e9dfc5ee724b
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
github.com/tyler-smith/go-bip39 v1.1.0
github.com/umbracle/ethgo v0.1.3
github.com/urfave/cli/v2 v2.17.2-0.20221006022127-8f469abc00aa
golang.org/x/crypto v0.13.0
golang.org/x/exp v0.0.0-20230810033253-352e893a4cad
Expand Down Expand Up @@ -134,6 +135,8 @@ require (
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/tklauser/go-sysconf v0.3.5 // indirect
github.com/tklauser/numcpus v0.2.2 // indirect
github.com/umbracle/fastrlp v0.0.0-20220527094140-59d5dd30e722 // indirect
github.com/valyala/fastjson v1.4.1 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
github.com/yuin/gopher-lua v1.1.0 // indirect
golang.org/x/mod v0.11.0 // indirect
Expand Down
23 changes: 21 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ github.com/Azure/azure-sdk-for-go/sdk/internal v0.8.3 h1:E+m3SkZCN0Bf5q7YdTs5lSm
github.com/Azure/azure-sdk-for-go/sdk/internal v0.8.3/go.mod h1:KLF4gFr6DcKFZwSuH8w8yEK6DpFl3LP5rhdvAb7Yz5I=
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v0.3.0 h1:Px2UA+2RvSSvv+RvJNuUB6n7rs5Wsel4dXLe90Um2n4=
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v0.3.0/go.mod h1:tPaiy8S5bQ+S5sOiDlINkp7+Ef339+Nz5L5XO+cnOHo=
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 h1:w+iIsaOQNcT7OZ575w+acHgRric5iCyQh+xv+KJ4HB8=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0=
github.com/CloudyKit/fastprinter v0.0.0-20200109182630-33d98a066a53/go.mod h1:+3IMCy2vIlbG1XG/0ggNQv0SvxCAIpPM5b1nCz56Xno=
github.com/CloudyKit/jet/v3 v3.0.0/go.mod h1:HKQPgSJmdK8hdoAbKUUWajkHyHo4RaU5rMdUywE7VMo=
github.com/DataDog/zstd v1.5.2 h1:vUG4lAyuPCXO0TLbXvPv7EB7cNK1QV/luu55UHLrrn8=
github.com/DataDog/zstd v1.5.2/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw=
github.com/Joker/hpp v1.0.0/go.mod h1:8x5n+M1Hp5hC0g8okX3sR3vFQwynaX/UgSOM9MeBKzY=
github.com/Microsoft/go-winio v0.4.13 h1:Hmi80lzZuI/CaYmlJp/b+FjZdRZhKu9c2mDVqKlLWVs=
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 h1:TngWCqHvy9oXAN6lEVMRuU21PR1EtLVZJmdB18Gu3Rw=
github.com/Shopify/goreferrer v0.0.0-20181106222321-ec9c9a553398/go.mod h1:a1uqRtAwp2Xwc6WNPJEufxJ7fx3npB4UV/JOLmbu5I0=
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 h1:fLjPD/aNc3UIOA6tDi6QXUemppXK3P9BI7mr2hd6gx8=
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
Expand Down Expand Up @@ -53,9 +56,11 @@ github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/bits-and-blooms/bitset v1.7.0 h1:YjAGVd3XmtK9ktAbX8Zg2g2PwLIMjGREZJHlV4j7NEo=
github.com/bits-and-blooms/bitset v1.7.0/go.mod h1:gIdJ4wp64HaoK2YrL1Q5/N7Y16edYb8uY+O0FJTyyDA=
github.com/btcsuite/btcd v0.22.1 h1:CnwP9LM/M9xuRrGSCGeMVs9iv09uMqwsVX7EeIpgV2c=
github.com/btcsuite/btcd/btcec/v2 v2.3.2 h1:5n0X6hX0Zk+6omWcihdYvdAlGf2DfasC0GMf7DClJ3U=
github.com/btcsuite/btcd/btcec/v2 v2.3.2/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04=
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 h1:q0rUy8C/TYNBQS1+CGKw68tLOFYSNEs0TFnxxnS9+4U=
github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/cespare/cp v0.1.0 h1:SE+dxFebS7Iik5LK0tsi1k9ZCxEaFX4AjQmoyA+1dJk=
github.com/cespare/cp v0.1.0/go.mod h1:SOGHArjBr4JWaSDEVpWpo/hNg6RoKrls6Oh40hiwW+s=
Expand Down Expand Up @@ -85,6 +90,7 @@ github.com/consensys/bavard v0.1.13 h1:oLhMLOFGTLdlda/kma4VOJazblc7IM5y5QPd2A/Yj
github.com/consensys/bavard v0.1.13/go.mod h1:9ItSMtA/dXMAiL7BG6bqW2m3NdSEObYWoH223nGHukI=
github.com/consensys/gnark-crypto v0.11.0 h1:QqzHQlwEqlQr5jfWblGDkwlKHpT+4QodYqqExkAtyks=
github.com/consensys/gnark-crypto v0.11.0/go.mod h1:Iq/P3HHl0ElSjsg2E1gsMwhAyxnxoKK5nVyZKd+/KhU=
github.com/containerd/continuity v0.0.0-20191214063359-1097c8bae83b h1:pik3LX++5O3UiNWv45wfP/WT81l7ukBJzd3uUiifbSU=
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
Expand Down Expand Up @@ -122,6 +128,8 @@ github.com/dnaeon/go-vcr v1.2.0 h1:zHCHvJYTMh1N7xnV7zf1m1GPBF9Ad0Jk/whtQ1663qI=
github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ=
github.com/docker/docker v1.6.2 h1:HlFGsy+9/xrgMmhmN+NGhCc5SHGJ7I+kHosRR1xc/aI=
github.com/docker/docker v1.6.2/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ=
github.com/docker/go-units v0.4.0 h1:3uh0PgVws3nIA0Q+MwDC8yjEPf9zjRfZZWXZYDct3Tw=
github.com/dop251/goja v0.0.0-20211022113120-dc8c55024d06/go.mod h1:R9ET47fwRVRPZnOGvHxxhuZcbrMCuiqOz3Rlrh4KSnk=
github.com/dop251/goja v0.0.0-20230122112309-96b1610dd4f7 h1:kgvzE5wLsLa7XKfV85VZl40QXaMCaeFtHpPwJ8fhotY=
github.com/dop251/goja v0.0.0-20230122112309-96b1610dd4f7/go.mod h1:yRkwfj0CBpOGre+TwBsqPV0IH0Pk73e4PXJOeNDboGs=
Expand Down Expand Up @@ -236,8 +244,8 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/gofuzz v1.1.1-0.20200604201612-c04b05f3adfa h1:Q75Upo5UN4JbPFURXZ8nLKYUvF85dyFRop/vQ0Rv+64=
github.com/google/gofuzz v1.1.1-0.20200604201612-c04b05f3adfa/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4=
Expand Down Expand Up @@ -388,8 +396,12 @@ github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
github.com/opencontainers/go-digest v1.0.0-rc1 h1:WzifXhOVOEOuFYOJAW6aQqW0TooG2iki3E3Ii+WN7gQ=
github.com/opencontainers/image-spec v1.0.1 h1:JMemWkRwHx4Zj+fVxWoMCFm/8sYGGrUVojFA6h/TRcI=
github.com/opencontainers/runc v0.1.1 h1:GlxAyO6x8rfZYN9Tt0Kti5a/cP41iuiO2yYT0IJGY8Y=
github.com/opentracing/opentracing-go v1.1.0 h1:pWlfV3Bxv7k65HYwkikxat0+s3pV4bsqf19k25Ur8rU=
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
github.com/ory/dockertest v3.3.5+incompatible h1:iLLK6SQwIhcbrG783Dghaaa3WPzGc+4Emza6EbVUUGA=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7 h1:oYW+YCJ1pachXTQmzR3rNLYGGz4g/UgFcjb28p/viDM=
github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7/go.mod h1:CRroGNssyjTd/qIG2FyxByd2S8JEAZXBl4qUrZf8GS0=
Expand Down Expand Up @@ -430,6 +442,7 @@ github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAm
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible h1:Bn1aCHHRnjv4Bl16T8rcaFjYSrGrIZvpiGO6P3Q4GpU=
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
Expand Down Expand Up @@ -463,13 +476,19 @@ github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGr
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
github.com/umbracle/ethgo v0.1.3 h1:s8D7Rmphnt71zuqrgsGTMS5gTNbueGO1zKLh7qsFzTM=
github.com/umbracle/ethgo v0.1.3/go.mod h1:g9zclCLixH8liBI27Py82klDkW7Oo33AxUOr+M9lzrU=
github.com/umbracle/fastrlp v0.0.0-20220527094140-59d5dd30e722 h1:10Nbw6cACsnQm7r34zlpJky+IzxVLRk6MKTS2d3Vp0E=
github.com/umbracle/fastrlp v0.0.0-20220527094140-59d5dd30e722/go.mod h1:c8J0h9aULj2i3umrfyestM6jCq0LK0U6ly6bWy96nd4=
github.com/umbracle/gohashtree v0.0.2-alpha.0.20230207094856-5b775a815c10 h1:CQh33pStIp/E30b7TxDlXfM0145bn2e8boI30IxAhTg=
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
github.com/urfave/cli/v2 v2.17.2-0.20221006022127-8f469abc00aa h1:5SqCsI/2Qya2bCzK15ozrqo2sZxkh0FHynJZOTVoV6Q=
github.com/urfave/cli/v2 v2.17.2-0.20221006022127-8f469abc00aa/go.mod h1:1CNUng3PtjQMtRzJO4FMXBQvkGtuYRxxiR9xMa7jMwI=
github.com/urfave/negroni v1.0.0/go.mod h1:Meg73S6kFm/4PpbYdq35yYWoCZ9mS/YSx+lKnmiohz4=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasthttp v1.6.0/go.mod h1:FstJa9V+Pj9vQ7OJie2qMHdwemEDaDiSdBnvPM1Su9w=
github.com/valyala/fastjson v1.4.1 h1:hrltpHpIpkaxll8QltMU8c3QZ5+qIiCL8yKqPFJI/yE=
github.com/valyala/fastjson v1.4.1/go.mod h1:nV6MsjxL2IMJQUoHDIrjEI7oLyeqK6aBD7EFWPsvP8o=
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio=
Expand Down
73 changes: 34 additions & 39 deletions suave/consolelog/console2.json
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,39 @@
"log(bool,uint256,uint256,bool)": "be984353",
"log(bool,uint256,uint256,string)": "8e69fb5d",
"log(bool,uint256,uint256,uint256)": "374bb4b2",
"log(bytes)": "0be77f56",
"log(bytes1)": "6e18a128",
"log(bytes10)": "013d178b",
"log(bytes11)": "04004a2e",
"log(bytes12)": "86a06abd",
"log(bytes13)": "94529e34",
"log(bytes14)": "9266f07f",
"log(bytes15)": "da9574e0",
"log(bytes16)": "665c6104",
"log(bytes17)": "339f673a",
"log(bytes18)": "c4d23d9a",
"log(bytes19)": "5e6b5a33",
"log(bytes2)": "e9b62296",
"log(bytes20)": "5188e3e9",
"log(bytes21)": "e9da3560",
"log(bytes22)": "d5fae89c",
"log(bytes23)": "aba1cf0d",
"log(bytes24)": "f1b35b34",
"log(bytes25)": "0b84bc58",
"log(bytes26)": "f8b149f1",
"log(bytes27)": "3a3757dd",
"log(bytes28)": "c82aeaee",
"log(bytes29)": "4b69c3d5",
"log(bytes3)": "2d834926",
"log(bytes30)": "ee12c4ed",
"log(bytes31)": "c2854d92",
"log(bytes32)": "27b7cf85",
"log(bytes4)": "e05f48d1",
"log(bytes5)": "a684808d",
"log(bytes6)": "ae84a591",
"log(bytes7)": "4ed57e28",
"log(bytes8)": "4f84252e",
"log(bytes9)": "90bd8cd0",
"log(int256)": "2d5b6cb9",
"log(string)": "41304fac",
"log(string,address)": "319af333",
Expand Down Expand Up @@ -341,43 +374,5 @@
"log(uint256,uint256,uint256,address)": "fa8185af",
"log(uint256,uint256,uint256,bool)": "c598d185",
"log(uint256,uint256,uint256,string)": "59cfcbe3",
"log(uint256,uint256,uint256,uint256)": "193fb800",
"logAddress(address)": "5f91b0af",
"logBool(bool)": "ba7ab84e",
"logBytes(bytes)": "e17bf956",
"logBytes1(bytes1)": "6f4171c9",
"logBytes10(bytes10)": "9dc2a897",
"logBytes11(bytes11)": "dc08b6a7",
"logBytes12(bytes12)": "7656d6c7",
"logBytes13(bytes13)": "34c1d81b",
"logBytes14(bytes14)": "3ceaba65",
"logBytes15(bytes15)": "591a3da2",
"logBytes16(bytes16)": "1f8d7312",
"logBytes17(bytes17)": "f89a532f",
"logBytes18(bytes18)": "d8652642",
"logBytes19(bytes19)": "00f56bc9",
"logBytes2(bytes2)": "9b5e943e",
"logBytes20(bytes20)": "ecb8567e",
"logBytes21(bytes21)": "3052c08f",
"logBytes22(bytes22)": "807ab434",
"logBytes23(bytes23)": "4979b037",
"logBytes24(bytes24)": "0977aefc",
"logBytes25(bytes25)": "aea9963f",
"logBytes26(bytes26)": "d3635628",
"logBytes27(bytes27)": "fc372f9f",
"logBytes28(bytes28)": "382f9a34",
"logBytes29(bytes29)": "7a187641",
"logBytes3(bytes3)": "7782fa2d",
"logBytes30(bytes30)": "c4340ef6",
"logBytes31(bytes31)": "81fc8648",
"logBytes32(bytes32)": "2d21d6f7",
"logBytes4(bytes4)": "fba3ad39",
"logBytes5(bytes5)": "5583be2e",
"logBytes6(bytes6)": "4942adc6",
"logBytes7(bytes7)": "4574afab",
"logBytes8(bytes8)": "9902e47f",
"logBytes9(bytes9)": "50a138df",
"logInt(int256)": "6525b5f5",
"logString(string)": "0bb563d6",
"logUint(uint256)": "9905b744"
"log(uint256,uint256,uint256,uint256)": "193fb800"
}
18 changes: 6 additions & 12 deletions suave/consolelog/consolelog.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"fmt"
"strings"

"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
"github.com/umbracle/ethgo/abi"
)

// embed the consolelog2 artifact with the method indentifiers
Expand All @@ -18,7 +18,7 @@ var console2Artifact string

// console2Methods is a map of method signatures to their
// types. It is populated by loadConsole2Methods
var console2Methods map[string]abi.Type
var console2Methods map[string]*abi.Type

// Console2ContractAddr is the address of the console2 contract
var Console2ContractAddr = common.HexToAddress("0x000000000000000000636F6e736F6c652e6c6f67")
Expand All @@ -33,10 +33,10 @@ func decode(b []byte) (interface{}, error) {

typ, ok := console2Methods[hex.EncodeToString(sig)]
if !ok {
return nil, fmt.Errorf("unknown console log method: %v", sig)
return nil, fmt.Errorf("unknown console log method: %v", hex.EncodeToString(sig))
}

val, err := typ.Unpack(b)
val, err := typ.Decode(b)
if err != nil {
return nil, err
}
Expand All @@ -56,7 +56,7 @@ func Print(b []byte) error {
}

func loadConsole2Methods() {
console2Methods = make(map[string]abi.Type)
console2Methods = make(map[string]*abi.Type)

var console2MethodIdentifiers map[string]string
if err := json.Unmarshal([]byte(console2Artifact), &console2MethodIdentifiers); err != nil {
Expand All @@ -71,17 +71,11 @@ func loadConsole2Methods() {
panic(fmt.Errorf("invalid signature for %s", sig))
}

typ, err := abi.NewTypeFromString("tuple" + sig[indx:])
typ, err := abi.NewType("tuple" + sig[indx:])
if err != nil {
panic(fmt.Errorf("invalid signature for %s: %v", "tuple"+sig[indx:], err))
}

// validate that the string representation of the type
// matches the signature
if !strings.HasSuffix(sig, typ.String()) {
panic(fmt.Errorf("invalid signature for %s: %s", sig, typ.String()))
}

console2Methods[sigID] = typ
}
}
Expand Down
28 changes: 21 additions & 7 deletions suave/consolelog/consolelog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,42 @@ import (
"strings"
"testing"

"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/stretchr/testify/require"
"github.com/umbracle/ethgo/abi"
)

func TestConsoleLog(t *testing.T) {
data := emitConsoleLog("log(address)", common.Address{})
val, err := decode(data)
require.NoError(t, err)
require.NotNil(t, val)
cases := []struct {
typStr string
args interface{}
}{
{
"log(address)", []interface{}{common.Address{}},
},
{
"log(bytes)", []interface{}{[]byte{0x1, 0x2, 0x3}},
},
}

for _, c := range cases {
data := emitConsoleLog(c.typStr, c.args)
val, err := decode(data)
require.NoError(t, err)
require.NotNil(t, val)
}
}

func emitConsoleLog(typStr string, args interface{}) []byte {
// decode the type and encode the arguments
typ, err := abi.NewTypeFromString(typStr[strings.Index(typStr, "("):])
typ, err := abi.NewType(typStr[strings.Index(typStr, "("):])
if err != nil {
panic(err)
}

// pack the arguments
data, err := typ.Pack(args)
data, err := typ.Encode(args)
if err != nil {
panic(err)
}
Expand Down
37 changes: 37 additions & 0 deletions suave/consolelog/gen/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package main

import (
"encoding/hex"
"encoding/json"
"fmt"
"os"
"regexp"

"github.com/ethereum/go-ethereum/crypto"
)

func main() {
// read the console.sol Solidity file from input args
console, err := os.ReadFile(os.Args[1])
if err != nil {
panic(err)
}

rxp := regexp.MustCompile("abi.encodeWithSignature\\(\"log(.*)\"")
matches := rxp.FindAllStringSubmatch(string(console), -1)

methodMap := map[string]string{}
for _, match := range matches {
signature := match[1]

// signature of the call. Use the version without the bytes in 'uint'.
sig := crypto.Keccak256([]byte("log" + match[1]))[:4]
methodMap["log"+signature] = hex.EncodeToString(sig)
}

raw, err := json.MarshalIndent(methodMap, "", "\t")
if err != nil {
panic(err)
}
fmt.Println(string(raw))
}

0 comments on commit 3a3a24d

Please sign in to comment.