TSender

Cyfrin
DeFiFoundry
15,000 USDC
View results
Submission Details
Severity: low
Invalid

Inefficient Error handling in Assembly code

Summary

The current error-handling mechanism in the assembly block stores error codes in memory and then reverts. This is a 2-step process and involves storing an error message or error code first and then using the revert opcode to revert the transaction. This method can be optimized by directly reverting to the error message without storing it first, it can save gas and make it more efficient.

Vulnerability Details

Problematic code

Example of current error handling

if iszero(call(gas(), tokenAddress, 0, 0x00, 0x64, 0, 0)) {
mstore(0x00, 0xfa10ea06) // cast sig "TSender__TransferFailed()"
revert(0x1c, 0x04)
}

Current process-

  1. Store Error code: the error code 0xfa10ea06 location 0x00

  2. Revert Transaction: The transaction is reverted with the error message starting from memory location 0x1c and length 0x04

This is inefficient as -

  1. Storing error code in memory before reverting involves an additional memory operation which consumes extra gas.

  2. Directly reverting with an error message avoids the need for intermediate memory storage, thus saving gas.

Impact

Currently, the assembly block stores the error code in memory and then reverts, which is inefficient and consumes more gas fees.

Recommendations

Instead of storing the error code in memory and then reverting, the revert opcode can be used directly with error message.

Example -

  1. Direct revert for Transfer Failed Error

if iszero(eq(recipients.length, amounts.length)) {
revert(0, 0x20) // revert with the error message "TSender__LengthsDontMatch"
}
  1. Direct revert for Zero Address Error

if iszero(recipient) {
revert(0, 0x20) // revert with the error message "TSender__ZeroAddress"
}
  1. Direct revert for Lengths Don't Match Error

if iszero(eq(recipients.length, amounts.length)) {
revert(0, 0x20) // revert with the error message "TSender__LengthsDontMatch"
}
Updates

Lead Judging Commences

inallhonesty Lead Judge about 1 year ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.