Closed juniuszhou closed 2 years ago
I have checked all the HexToAddress uages in source code, there is the IsHexAddress called before. We don't have IsHexAddress in the *_test.go, but I think it is fine, the Ethereum address in test code is hard coded with correct one. I suggest we won't fix it.
close it if one more person agree with no fix. @banshee @smartyalgo @Brando753
I think we'll need to add that validation for TokenMetadataAddRequest.ValidateBasic(). Please verify, not sure if IBC flow uses the same code
The rest are fine, that's the only one outstanding
will prepare a PR to add the IsHexAddress check in TokenMetadataAddRequest.ValidateBasic()
PR #3289 created.
close it after #3289 merged.
Description
In several code paths in the Sifchain codebase, the HexToAddress function from the go-ethereum library is used to parse Ethereum addresses. This function does not return an error when the format of the address passed to it is incorrect. Indeed, the function will accept any number of bytes and return the right-most 20 bytes. (see the following reference). For this reason, it is unsuitable for use as a function to validate Ethereum addresses. The use of this function may be misleading for developers unfamiliar with the go-ethereum library, as it appears to perform more thorough validation of Ethereum addresses than it actually does.
code location
Recommendation
Consider writing a helper function or struct to validate Ethereum addresses in a more robust way. This function could make use of go ethereum’s IsHexAddress function or alternatively use a regular expression or other means to verify valid Ethereum addresses. This function could additionally be used to filter out addresses that could lead to errors, for example the zero-address (0x00..00).