autonity / aut

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

Accountability Contract: canSlash contract call reverts correctly but doesn't return a revert reason #151

Closed cmjc closed 5 months ago

cmjc commented 5 months ago

Description

Calling canSlash with autcli to see if a validator is slashable:

aut contract call --address 0x5a443704dd4B594B382c22a083e2BD3090A6feF3 canSlash 0x4B241e33CEFbeF5fFE87CF81C56f19D6321536c4 10 1245

returns reverted, but without a revert reason:

web3.exceptions.ContractLogicError: execution reverted

If calling getValidatorAccusation and there are no accusations, a revert reason of no accusation is returned:

aut contract call --address 0x5a443704dd4B594B382c22a083e2BD3090A6feF3 getValidatorAccusation 0x6558D2cEEb4a9Fe9c9cF19A3F6EBE7D45C30efaF
web3.exceptions.ContractLogicError: execution reverted: no accusation

System Information

Rationale

Returning a revert reason would be more informative to the user.

cmjc commented 5 months ago

Originally raised in autonity repo - transferred here per comment by @Jason-Zhangxin-Chen , see closed issue https://github.com/autonity/autonity/issues/954

Hi @cmjc, from your context, rule NO. 10 is not defined in the rule set:


// Must match autonity/types.go
enum Rule {
PN,
PO,
PVN,
PVO,
PVO12,
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.
}

// @dev return true if sending the event can lead to slashing
function canSlash(address _offender, Rule _rule, uint256 _block) public view returns (bool) {
    uint256 _severity = _ruleSeverity(_rule);
    uint256 _epoch = autonity.getEpochFromBlock(_block);

    return slashingHistory[_offender][_epoch] < _severity ;
}

>As the typing system limits the input of _rule should be a type of Rule, from inside the canSlash funtion we cannot capture such error. Thus from AUT tool side, we can do some check on it. This issue so move to Aut tool.
aiman commented 5 months ago

@cmjc I'm not satisfied that this is an autcli issue and so I'm reopening the original ticket.