pipermerriam/ethereum-function-signature-registry

contract_abi: Could not validate ABI

Closed this issue · 2 comments

  • OS: Web
  • Python version: N/A
  • Environment: 4byte.directory

What is wrong?

Tried to upload the following ABI via Submit ABI link:

[{"constant":false,"inputs":[{"name":"newImplementation","type":"address"}],"name":"upgradeTo","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"newImplementation","type":"address"},{"name":"data","type":"bytes"}],"name":"upgradeToAndCall","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"constant":false,"inputs":[],"name":"implementation","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"newAdmin","type":"address"}],"name":"changeAdmin","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"admin","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[{"name":"_logic","type":"address"},{"name":"_admin","type":"address"},{"name":"_data","type":"bytes"}],"payable":true,"stateMutability":"payable","type":"constructor"},{"payable":true,"stateMutability":"payable","type":"fallback"},{"anonymous":false,"inputs":[{"indexed":false,"name":"previousAdmin","type":"address"},{"indexed":false,"name":"newAdmin","type":"address"}],"name":"AdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"implementation","type":"address"}],"name":"Upgraded","type":"event"}]

How can it be fixed

Nothing immediately jumps out at me as invalid in the ABI, I'm hoping that a more useful error is presented on the server. It would be nice if more verbose errors were available in the web interface when this happens so users (I) could work around the problem temporarily.

It looks like it is because we are using JSONSchema to validate the ABI JSON and our schema hasn't been updated to work with the latest ABI that solidity produces:

    def validate(self, *args, **kwargs):
        for error in self.iter_errors(*args, **kwargs):
>           raise error
E           jsonschema.exceptions.ValidationError: {'payable': True, 'stateMutability': 'payable', 'type': 'fallback'} is not valid under any of the given schemas
E
E           Failed validating 'anyOf' in schema['items']:
E               {'anyOf': [{'$ref': '#/definitions/function'},
E                          {'$ref': '#/definitions/event'},
E                          {'$ref': '#/definitions/constructor'}]}
E
E           On instance[6]:
E               {'payable': True, 'stateMutability': 'payable', 'type': 'fallback'}

Anyone who wants to fix this should probably start here:

def is_valid_contract_abi(contract_abi):

I can confirm that the provided ABI can now be submitted successfully.