# Does \`ecrecover\` prevent replay attack on different \`chainIds\`?

**URL:** <https://forum.soliditylang.org/t/does-ecrecover-prevent-replay-attack-on-different-chainids/1947>\
**Category:** Uncategorized\
**Created:** [October 27, 2023, 2:16am UTC](https://forum.soliditylang.org/t/does-ecrecover-prevent-replay-attack-on-different-chainids/1947 "2023-10-27T02:16:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![adu](https://sea1.discourse-cdn.com/flex001/user_avatar/forum.soliditylang.org/adu/32/1137_2.png) [@adu](https://forum.soliditylang.org/u/adu)\
**Post date:** [October 27, 2023, 2:16am UTC](https://forum.soliditylang.org/t/does-ecrecover-prevent-replay-attack-on-different-chainids/1947/1 "2023-10-27T02:16:08Z")

</div>

I mean if I sign an arbitrary message and verify the message with signature by calling `ecrecover(hash(encodedMsg), v, r, s)`, does this help prevent replay attack on different chains? I mean if I successfully verify the signature, would it be possible that the same signature and message could be used on another chain?

---

<div class="post-metadata">

**Author:** ![0xth0mas](https://sea1.discourse-cdn.com/flex001/user_avatar/forum.soliditylang.org/0xth0mas/32/1129_2.png) [@0xth0mas](https://forum.soliditylang.org/u/0xth0mas)\
**Post date:** [October 27, 2023, 3:16am UTC](https://forum.soliditylang.org/t/does-ecrecover-prevent-replay-attack-on-different-chainids/1947/2 "2023-10-27T03:16:05Z")

</div>

chainId needs to be part of the encoded message to prevent replays, ecrecover for the same hash, v, r and s will always return the same address regardless of the number of times it is called or the chain it is executed on

see EIP712 for reference

> **[EIP-712: Typed structured data hashing and signing](https://eips.ethereum.org/EIPS/eip-712)**
>
> A procedure for hashing and signing of typed structured data as opposed to just bytestrings.

---

<div class="post-metadata">

**Author:** ![adu](https://sea1.discourse-cdn.com/flex001/user_avatar/forum.soliditylang.org/adu/32/1137_2.png) [@adu](https://forum.soliditylang.org/u/adu)\
**Post date:** [October 27, 2023, 3:28am UTC](https://forum.soliditylang.org/t/does-ecrecover-prevent-replay-attack-on-different-chainids/1947/3 "2023-10-27T03:28:56Z")

</div>

I see. Really appreciate for your timely explanation!
