Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

evm_tokens: fix potential nil-pointer dereference #430

Merged
merged 1 commit into from
Jun 6, 2023

Conversation

ptrus
Copy link
Member

@ptrus ptrus commented Jun 3, 2023

On Testnet Production:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x1109189]

goroutine 70736 [running]:
github.com/oasisprotocol/oasis-indexer/analyzer/evmtokens.Main.processStaleToken({{0x14cb622, 0x8}, {0x18b5680, 0xc000450a30}, {0x18bbc40, 0xc0003a6370}, 0xc0006ac4e0}, {0x18b39b0, 0xc000922f80}, 0xc000b771e0, ...)
        /code/go/analyzer/evmtokens/evm_tokens.go:122 +0x449
github.com/oasisprotocol/oasis-indexer/analyzer/evmtokens.Main.processBatch.func1()
        /code/go/analyzer/evmtokens/evm_tokens.go:170 +0x4e
golang.org/x/sync/errgroup.(*Group).Go.func1()
        /go/pkg/mod/golang.org/x/[email protected]/errgroup/errgroup.go:75 +0x64
created by golang.org/x/sync/errgroup.(*Group).Go
        /go/pkg/mod/golang.org/x/[email protected]/errgroup/errgroup.go:72 +0xa5

Looking at the code, the EVMDownloadNewToken can return EVMTokenTypeUnsupported which will cause tokenData.TotalSupply to be nil (so shouldn't call .String() on it without checking): https://github.com/oasisprotocol/oasis-indexer/blob/f33b4a9558b4d5736af5c137592ed951cf1c0fff/analyzer/runtime/evm/client.go#L243


Don't have a lot of context about the code around here, so I just pushed a minimal change to avoid the nil pointer here.

@ptrus ptrus force-pushed the ptrus/bugfix/nil-pointer-token branch 2 times, most recently from cd89a23 to c139650 Compare June 3, 2023 14:00
@pro-wh
Copy link
Collaborator

pro-wh commented Jun 3, 2023

testnet, was this emerald? can we figure out the height and/or contract address? the ERC spec says the total supply is required. we're meant to treat the contract as not ERC-20 if the total supply is not supported

@ptrus
Copy link
Member Author

ptrus commented Jun 5, 2023

was this emerald

Looking at the DB it looks like this is sapphire. (there is no stale emerald tokens found if running the RuntimeEVMTokenAnalysisStale query).

Also, a lot of "ERC20 call failed" errors in the logs:

2023-06-05T05:31:41.558081128Z {"analyzer":"evm_tokens_sapphire","caller":"client.go:180","err":"runtime client evm simulate call: rpc error: code = Canceled desc = context canceled","level":"info","method":"name","module":"analysis_service","msg":"ERC20 call failed","round":1454725,"token_eth_addr_hex":"ed33e0bb03fefd0f343f634c3f40a5f6839753f2","ts":"2023-06-05T05:31:41.557871724Z"}
2023-06-05T05:31:41.559847210Z {"analyzer":"evm_tokens_sapphire","caller":"client.go:180","err":"runtime client evm simulate call: rpc error: code = Canceled desc = context canceled","level":"info","method":"name","module":"analysis_service","msg":"ERC20 call failed","round":1454725,"token_eth_addr_hex":"d708be8af397cd28b69520db3bd2d92429efb1a8","ts":"2023-06-05T05:31:41.559580189Z"}
2023-06-05T05:31:41.561058059Z {"analyzer":"evm_tokens_sapphire","caller":"client.go:180","err":"runtime client evm simulate call: rpc error: code = Canceled desc = context canceled","level":"info","method":"name","module":"analysis_service","msg":"ERC20 call failed","round":1454725,"token_eth_addr_hex":"8e6b9362275b93c0e4da3662938456dff485604f","ts":"2023-06-05T05:31:41.560914619Z"}
2023-06-05T05:31:47.634407918Z {"analyzer":"evm_tokens_sapphire","caller":"client.go:180","err":"runtime client evm simulate call: roothash: block not found","level":"info","method":"name","module":"analysis_service","msg":"ERC20 call failed","round":1454754,"token_eth_addr_hex":"af0d800b67f2688e4c40e1879537df956f3f1c12","ts":"2023-06-05T05:31:47.634183789Z"}
2023-06-05T05:31:47.634454950Z {"analyzer":"evm_tokens_sapphire","caller":"client.go:180","err":"runtime client evm simulate call: rpc error: code = Canceled desc = context canceled","level":"info","method":"name","module":"analysis_service","msg":"ERC20 call failed","round":1454754,"token_eth_addr_hex":"d239ce2b79f1d9757c6fe6bf44f83bf74a969010","ts":"2023-06-05T05:31:47.634317936Z"}
2023-06-05T05:31:47.634489488Z {"analyzer":"evm_tokens_sapphire","caller":"client.go:180","err":"runtime client evm simulate call: rpc error: code = Canceled desc = context canceled","level":"info","method":"name","module":"analysis_service","msg":"ERC20 call failed","round":1454754,"token_eth_addr_hex":"06f3c5b365c7af22140c1f5cd3f80a43c186df3a","ts":"2023-06-05T05:31:47.634388413Z"}
...
...
2023-06-05T05:32:11.968103275Z {"analyzer":"evm_tokens_sapphire","caller":"client.go:180","err":"runtime client evm simulate call: reverted: no revert reason","level":"info","method":"name","module":"analysis_service","msg":"ERC20 call failed","round":1454857,"token_eth_addr_hex":"13f000cb55295d846b8a014ebfb63917a21c7d14","ts":"2023-06-05T05:32:11.96794633Z"}
2023-06-05T05:32:11.974407688Z {"analyzer":"evm_tokens_sapphire","caller":"client.go:180","err":"runtime client evm simulate call: reverted: no revert reason","level":"info","method":"name","module":"analysis_service","msg":"ERC20 call failed","round":1454857,"token_eth_addr_hex":"d708be8af397cd28b69520db3bd2d92429efb1a8","ts":"2023-06-05T05:32:11.974252006Z"}
2023-06-05T05:32:11.983481180Z {"analyzer":"evm_tokens_sapphire","caller":"client.go:180","err":"runtime client evm simulate call: reverted: no revert reason","level":"info","method":"name","module":"analysis_serv

@kostko
Copy link
Member

kostko commented Jun 5, 2023

Also, a lot of "ERC20 call failed" errors in the logs:

Are there any successful ones as well or do they all fail?

@ptrus
Copy link
Member Author

ptrus commented Jun 5, 2023

It could be that all are failing, not sure how to check actually, I don't think there's anything logged for successful calls. Someone that understands the tokens analysis code should probably check.

@kostko
Copy link
Member

kostko commented Jun 5, 2023

If all are failing this likely means that the client node is not configured correctly or is not whitelisted for key manager access. @gw0 do you know?

@gw0
Copy link

gw0 commented Jun 6, 2023

If all are failing this likely means that the client node is not configured correctly or is not whitelisted for key manager access. @gw0 do you know?

Looks correct. The production testnet-oasis-indexer is using our internal Testnet Sapphire gRPC node. Its P2P pubkey is whitelisted in our Testnet Keymanager nodes.

@ptrus
Copy link
Member Author

ptrus commented Jun 6, 2023

Yeah some calls are working, since here e.g. simulate call works (but is reverted).


@pro-wh This is sapphire, see the round and address in the log message below.

{
    "analyzer": "evm_tokens_sapphire",
    "caller": "client.go:157",
    "err": "runtime client evm simulate call: reverted: no revert reason",
    "level": "info",
    "method": "totalSupply",
    "module": "analysis_service",
    "msg": "ERC20 call failed",
    "round": 1467342,
    "token_eth_addr_hex": "98b50e303836bf301221ddf715a154dde7cbfd56",
    "ts": "2023-06-06T07:18:15.563730585Z"
}

This happens here: https://github.com/oasisprotocol/oasis-indexer/blob/f33b4a9558b4d5736af5c137592ed951cf1c0fff/analyzer/runtime/evm/client.go#L210-L216

Which then causes the EVMDownloadNewToken to return:
https://github.com/oasisprotocol/oasis-indexer/blob/f33b4a9558b4d5736af5c137592ed951cf1c0fff/analyzer/runtime/evm/client.go#L243

Which causes the nil pointer here:
https://github.com/oasisprotocol/oasis-indexer/blob/f33b4a9558b4d5736af5c137592ed951cf1c0fff/analyzer/evmtokens/evm_tokens.go#L122

@ptrus ptrus force-pushed the ptrus/bugfix/nil-pointer-token branch from c139650 to 2a42365 Compare June 6, 2023 08:01
Copy link
Collaborator

@pro-wh pro-wh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh right we're inserting the unsupported tokens now

@ptrus ptrus force-pushed the ptrus/bugfix/nil-pointer-token branch from 2a42365 to e9f7969 Compare June 6, 2023 20:11
@ptrus ptrus enabled auto-merge June 6, 2023 20:11
@ptrus ptrus merged commit 5579416 into main Jun 6, 2023
@ptrus ptrus deleted the ptrus/bugfix/nil-pointer-token branch June 6, 2023 20:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants