Skip to content
Request an audit

‹ All findings

When recording failed transactions in ConnextHandler, getting the next Nonce involves an unnecessary for loop

Low/InfoFuji Finance·Three Sigma · Lending aggregator · 6th May, 20233S-FUJI-N06

Description

In ConnextHandler.sol, in order to record a failed transaction it is necessary to know the next nonce in the mapping, this involves a for cycle with a storage read that expends gas.

Since it only adds at the end of the list and access is always done using the nonce, the variable _failedTxns could be changed from a mapping of a mapping to the mapping of an array, this way in order to add a transaction push() could be used and to be able to know the nonce the length of the array would suffice.

This way the for cycle wouldn't be needed and it would save on gas.

Recommendation

solidity
New declaration: mapping(bytes32 => FailedTxn[]) private _failedTxns;
Fetching the nonce: uint128 nextNonce = _failedTxns[transferId].length;
And adding to the list: _failedTxns[transferId].push(...);

Status

Addressed here: Fujicracy/fuji-v2#616