# 3.11 ecrecover

This security pitfall is related to the use of the `ecrecover` primitive in EVM and supported by `Solidity`.

The specific pitfall is that it is susceptible to what is known as signature malleability or non-unique signatures. Remember that elliptic curve signatures in Ethereum have three components `v`, `r` and `s`. The `ecrecover` function takes in a message hash the signature associated with that message hash and returns the Ethereum address that corresponds to the private key that was used to create that signature.

In the context of this pitfall, if an attacker has access to one of these signatures, then they can create a second valid signature without having access to the private key to generate that signature.

This is because of the specific range that the `s` value or the `s` component of that signature can be in it can be in an upper range or a lower range and both ranges are allowed by this primitive which results in the malleability.

This depending on the logic of the smart contract, the context in which it is using these signatures can result in replay attacks, so the mitigation is to check that the `s` component is only in the lower range and not in the higher range, this mitigation is enforced in OpenZeppelin's `ECDSA` library which is the recommended best practice.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://secureum.gitbook.io/secureum-book/learn/learn/3_security_pitfalls_and_best_practices/3.11_ecrecover.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
