autonity / aut

A command-line RPC client for Autonity
MIT License
11 stars 10 forks source link

`contract call` to `Accountability.abi` `canAccuse` and `canSlash` throws `ValueError: invalid literal for int() with base 10: `` #127

Closed cmjc closed 6 months ago

cmjc commented 11 months ago

Bug

These methods take as parameters:

Field Datatype Description
_offender address identifier address of the offending validator
_rule Rule enumerated value providing the ID for the protocol rule
_block uint256 block number at which the rule infraction occurred

The _rule values are defined as a string enumeration type:

https://github.com/autonity/autonity/blob/8183c96276bfc0764ad59b31cde423d6245329c0/autonity/solidity/contracts/Accountability.sol#L30

enum Rule {
        PN,
        PO,
        PVN,
        PVO,
        PVO12,
        PVO3,
        C,
        C1,
        InvalidProposal, // The value proposed by proposer cannot pass the blockchain's validation.
        InvalidProposer, // A proposal sent from none proposer nodes of the committee.
        Equivocation,    // Multiple distinguish votes(proposal, prevote, precommit) sent by validator.
        InvalidRound,          // message contains invalid round number or step.
        WrongValidRound, // message was signed by sender, but it cannot be decoded.
        GarbageMessage // message sender is not the member of current committee.
    }

The function method signatures are:

https://github.com/autonity/autonity/blob/8183c96276bfc0764ad59b31cde423d6245329c0/autonity/solidity/contracts/Accountability.sol#L173

function canAccuse(address _offender, Rule _rule, uint256 _block) public view

https://github.com/autonity/autonity/blob/8183c96276bfc0764ad59b31cde423d6245329c0/autonity/solidity/contracts/Accountability.sol#L165

function canSlash(address _offender, Rule _rule, uint256 _block) public view returns (bool) {

The bug is calling the Accountability Contract Interface function canAccuse or canSlash using aut contract call fails throwing a ValueError on the type of the second method argument _rule: aut is expecting an integer not a string. See Example beneath.

Because uint256 starts at 0 and InvalidProposal is the 9th enumeration it is perhaps expecting the value 8?

Expected behaviour The method returns without error.

aut version

$ aut --version
aut, version 0.3.0.dev1

Example

ubuntu@vps-c7c3e8c7:~/TEST/autcli$ aut contract call --address 0x5a443704dd4B594B382c22a083e2BD3090A6feF3 --abi Accountability.abi canAccuse  0x21bb01Ae8EB831fFf68EbE1D87B11c85a766C94C InvalidProposal 504335
ValueError: invalid literal for int() with base 10: 'InvalidProposal'
ubuntu@vps-c7c3e8c7:~/TEST/autcli$ aut contract call --address 0x5a443704dd4B594B382c22a083e2BD3090A6feF3 --abi Accountability.abi canSlash  0x21bb01Ae8EB831fFf68EbE1D87B11c85a766C94C InvalidProposal 504335
ValueError: invalid literal for int() with base 10: 'InvalidProposal'

To replicate

  1. get valid values for parameters

    1. call aut validator list to get a validator address
    2. call aut block height to return a valid block height value.
    3. see Accountability.sol and get a valid rule ID - https://github.com/autonity/autonity/blob/8183c96276bfc0764ad59b31cde423d6245329c0/autonity/solidity/contracts/Accountability.sol#L30
  2. call aut contract call specifying the Accountability contract address and ABI, either in the call per example or in your .autrc config file.

cmjc commented 7 months ago

Update: a revision of the call to use the index number removes that error ValueError: invalid literal for int() with base 10: 'InvalidProposal'

Now using aut version 0.3.0, I get an Assertion Error, calling with an example here to call a validator for a PVN error (rule 2):

aut contract call --address 0x5a443704dd4B594B382c22a083e2BD3090A6feF3 canAccuse 0x43936c8c13ffe8078d9e374d42e0b4f27d35352a 2 3475260
AssertionError
szemate commented 6 months ago

Because uint256 starts at 0 and InvalidProposal is the 9th enumeration it is perhaps expecting the value 8?

Yes it is correct. The ABI type spec looks like:

      {
        "internalType": "enum Accountability.Rule",
        "name": "_rule",
        "type": "uint8"
      },

and therefore web3.py translates it into an int parameter.

As the aut contract call function is supposed to work with any contract ABI I don't think we should add a workaround here. I would propose a "won't fix" for this issue, and it will be implemented properly in #135 when we add proper CLI commands for the Accountability functionality.

szemate commented 6 months ago

Now using aut version 0.3.0, I get an Assertion Error, calling with an example here to call a validator for a PVN error (rule 2):

I could reproduce it, this error is fixed by https://github.com/autonity/autonity.py/pull/45.