keep-network / keep-core

The smart contracts and reference client behind the Keep network
https://keep.network
MIT License
118 stars 73 forks source link

Wallet maintainer: Prevent against `requestTimeout` being `max(uint32)` #3681

Closed lukasz-zimnoch closed 1 year ago

lukasz-zimnoch commented 1 year ago

Refs: https://github.com/keep-network/keep-core/issues/3614

While running the redemption task, the wallet maintainer fetches past RedemptionRequested events using a filter whose start block is calculated as:

startBlock := currentBlock - requestTimeoutBlocks - 1000

where requestTimeoutBlocks is computed as:

requestTimeoutBlocks := uint64(requestTimeout) /
    uint64(chain.AverageBlockTime().Seconds())

However, the current Bridge.requestTimeout on mainnet is set to max(uint32) as redemptions are not yet enabled. That means the requestTimeoutBlocks is higher than currentBlock and produces a negative startBlock which is eventually set to max(uint64) due to being an unsigned type. The startBlock is then converted to int64 within go-ethereum library which produces the invalid argument 0: block number larger than int64 error as a result.

In order to fix this problem, we are introducing an additional check that ensures the minimum possible value of startBlock is 0.