Skip to content
Smart contracts Audit finding Intermediate

return value of 0 from ecrecover not checked

The smart contract did not check whether the ecrecover function returned zero on error, so an attacker could supply an invalid signature and set the maker address to zero to bypass signature validation. This could allow illegal and unexpected transactions.

gpersoon Follow

Originally disclosed on Code4rena

Submitted by gpersoon, also found by 0xRajeev, cmichel, and nikitastupin.

Impact

The solidity function ecrecover is used, however the error result of 0 is not checked for. See documentation: https://docs.soliditylang.org/en/v0.8.9/units-and-global-variables.html?highlight=ecrecover#mathematical-and-cryptographic-functions “recover the address associated with the public key from elliptic curve signature or return zero on error. ”

Now you can supply invalid input parameters to the Sig.recover function, which will then result 0. If you also set o.maker to be 0 then this will match and an invalid signature is not detected.

So you can do all kinds of illegal & unexpected transactions.

Proof of Concept

https://github.com/Swivel-Finance/gost/blob/v2/test/swivel/Swivel.sol#L476-L484

  function validOrderHash(Hash.Order calldata o, Sig.Components calldata c) internal view returns (bytes32) {
  ...
  require(o.maker == Sig.recover(Hash.message(domain, hash), c), 'invalid signature');
  return hash;
  }

https://github.com/Swivel-Finance/gost/blob/v2/test/swivel/Sig.sol#L16-L23

  function recover(bytes32 h, Components calldata c) internal pure returns (address) {
  ...
  return ecrecover(h, c.v, c.r, c.s);

Tools Used

Recommended Mitigation Steps

Verify that the result from ecrecover isn’t 0

JTraversa (Swivel) acknowledged JTraversa (Swivel) commented:

Id say this is noteable, but because all actions require approvals from o.maker, having 0x00 as o.maker with an “invalid” but valid signature should not be impactful. The suggestion would be to filter 0x00 makers from the orderbook? (which we do)

The original report as published on Code4rena, by gpersoon. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The contract did not verify that the address returned by ecrecover was not the zero address, allowing an invalid signature to match a maker address of zero.

Impact

An attacker could perform illegal and unexpected transactions, though the program owner noted that all actions require approvals from the maker, so using a zero maker address may not be impactful.

What the attacker needed

Ability to submit a transaction with a crafted signature

The fix

The result from ecrecover should be checked to ensure it is not zero.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

A smart contract uses a function called ecrecover to check digital signatures. If the signature is invalid, ecrecover returns zero instead of an error. The contract forgot to check for that zero, so an attacker could pretend to be the zero address and trick the contract into accepting a fake signature.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by gpersoon

View all

47 more disclosed reports, best first.

More from Swivel v3 contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.