nucypher / nucypher-contracts

Ethereum contracts supporting TACo applications on the Threshold Network.
16 stars 11 forks source link

GlobalAllowList returns `Panic error 0x11:` when deauthorizing a not authorized address #292

Open manumonti opened 1 month ago

manumonti commented 1 month ago

If I try to deauthorize an address that either has never been authorized or has been authorized in the past but deauthorized later, the transaction returns

Panic error 0x11: Arithmetic operation results in underflow or overflow.

I used this code (web3.py):

tx = global_allow_list_contract.functions.deauthorize(
        ritual_id,
        encryptors_addresses,
    ).build_transaction(
        {
            "from": account.address,
            "nonce": nonce, # TODO: update nonce consequently
        }
    )

    signed_tx = w3.eth.account.sign_transaction(tx, private_key=PRIVATE_KEY)
    tx_hash = w3.eth.send_raw_transaction(signed_tx.rawTransaction)
    tx_receipt = w3.eth.wait_for_transaction_receipt(tx_hash)

Error log:

Traceback (most recent call last):
  File "/Users/manumonti/Projects/nucypher/nucypher-contracts/scripts/bqeth_subscription.py", line 222, in <module>
    remove_encryptors(global_allow_list_contract, account, nonce, encryptors, ritual_id)
  File "/Users/manumonti/Projects/nucypher/nucypher-contracts/scripts/bqeth_subscription.py", line 166, in remove_encryptors
    ).build_transaction(
      ^^^^^^^^^^^^^^^^^^
  File "/Users/manumonti/.pyenv/versions/3.11.6/envs/nucypher-contracts/lib/python3.11/site-packages/web3/contract/contract.py", line 356, in build_transaction
    return build_transaction_for_function(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/manumonti/.pyenv/versions/3.11.6/envs/nucypher-contracts/lib/python3.11/site-packages/web3/contract/utils.py", line 233, in build_transaction_for_function
    prepared_transaction = fill_transaction_defaults(w3, prepared_transaction)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "cytoolz/functoolz.pyx", line 263, in cytoolz.functoolz.curry.__call__
  File "/Users/manumonti/.pyenv/versions/3.11.6/envs/nucypher-contracts/lib/python3.11/site-packages/web3/_utils/transactions.py", line 136, in fill_transaction_defaults
    default_val = default_getter(w3, transaction)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/manumonti/.pyenv/versions/3.11.6/envs/nucypher-contracts/lib/python3.11/site-packages/web3/_utils/transactions.py", line 76, in <lambda>
    "gas": lambda w3, tx: w3.eth.estimate_gas(tx),
                          ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/manumonti/.pyenv/versions/3.11.6/envs/nucypher-contracts/lib/python3.11/site-packages/web3/eth/eth.py", line 316, in estimate_gas
    return self._estimate_gas(transaction, block_identifier, state_override)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/manumonti/.pyenv/versions/3.11.6/envs/nucypher-contracts/lib/python3.11/site-packages/web3/module.py", line 75, in caller
    result = w3.manager.request_blocking(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/manumonti/.pyenv/versions/3.11.6/envs/nucypher-contracts/lib/python3.11/site-packages/web3/manager.py", line 330, in request_blocking
    return self.formatted_response(
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/manumonti/.pyenv/versions/3.11.6/envs/nucypher-contracts/lib/python3.11/site-packages/web3/manager.py", line 291, in formatted_response
    apply_error_formatters(error_formatters, response)
  File "/Users/manumonti/.pyenv/versions/3.11.6/envs/nucypher-contracts/lib/python3.11/site-packages/web3/manager.py", line 104, in apply_error_formatters
    formatted_resp = pipe(response, error_formatters)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "cytoolz/functoolz.pyx", line 680, in cytoolz.functoolz.pipe
  File "cytoolz/functoolz.pyx", line 655, in cytoolz.functoolz.c_pipe
  File "/Users/manumonti/.pyenv/versions/3.11.6/envs/nucypher-contracts/lib/python3.11/site-packages/web3/_utils/error_formatters_utils.py", line 157, in raise_contract_logic_error_on_revert
    _raise_contract_error(data)
  File "/Users/manumonti/.pyenv/versions/3.11.6/envs/nucypher-contracts/lib/python3.11/site-packages/web3/_utils/error_formatters_utils.py", line 115, in _raise_contract_error
    raise ContractPanicError(
web3.exceptions.ContractPanicError: ('Panic error 0x11: Arithmetic operation results in underflow or overflow.', '0x4e487b710000000000000000000000000000000000000000000000000000000000000011')
cygnusv commented 1 month ago

oh this is a great find! There's not enough checks in EncryptorSlotsSubscription.beforeSetAuthorization().