Skip to content

Latest commit

 

History

History
53 lines (29 loc) · 1.8 KB

File metadata and controls

53 lines (29 loc) · 1.8 KB

Oblong Cherry Halibut

Medium

Direct Usage of ecrecover()

Summary

The system currently uses the direct ecrecover() function to determine the signer of signatureData:

Root Cause

https://github.com/sherlock-audit/2024-10-gamma-rewarder/blob/main/GammaRewarder/contracts/brevis/lib/Lib.sol#L133 function recover(bytes32 message, bytes32 r, bytes32 s, uint8 v) internal pure returns (address) { if (v < 27) { v += 27; } return ecrecover(message, v, r, s); }

This approach has the following issues:

  • Error Handling: A failed signature verification returns 0 rather than reverting with an error, potentially leading to incorrect error handling downstream.
  • Signature Manipulation: Direct use of ecrecover() is vulnerable to manipulation. For example, adjusting the signatureData.r parameter can yield a random address, allowing for incorrect or malicious signatures to be processed as valid.

Using a function from a well-established library, such as OpenZeppelin’s, can address these concerns.

Internal pre-conditions

No response

External pre-conditions

No response

Attack Path

No response

Impact

No response

PoC

No response

Mitigation

To improve security and error handling, use the OpenZeppelin [ECDSA](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/cryptography/ECDSA.sol) library for signature verification. This library provides a secure and reliable implementation of ecrecover() that includes robust error handling and mitigates the risk of signature manipulation. Incorporating this library will ensure more accurate and secure signature verification in the contract.