Fair PVP on/off-chain with ECDSA

RealmLink
2 min readOct 3, 2022

--

Goal: To achieve verifiable pvp outcomes on chain using ECDSA

At first, I had no idea how I would achieve this but after a couple of weeks, it hit me. Use ECDSA signatures before & after the fight in order to make sure all participants are recorded & submit these signatures to the chain via a centralized wallet. Web2 security here is a must. You should not try to implement a production version of this without spending a considerable amount of time on web2 security since we’re using a centralised wallet.

Anyways….

hashedMessage = keccak256(
player1Addr,
player2Addr,
player1TokenID,
player2TokenID,
bool start,
string uniqueID
)

I forgot to add the unique ID in. Make sure to store the ID in a mapping as used after each function call. mapping(string => bool) should be fine.

Example

For those of you unaware about ECDSA (Eliptical Curve Digital Signature Algorithm) here is an implementation of it. The _hashedMessage is prefixed & then we recover the signer using the ecrecover function & passing in the hashed message aswell as the 3 parts of the signature _v, _r, _s.

Can you see a use case for this in your project?

If you found this one interesting why not check this out!
https://medium.com/p/cd06bca5e541

Solidity Dev Study Group — https://discord.gg/KzbcGmrnfN

-Polygon Alliance — https://www.polygonalliance.com/

-Polygon Alliance Discord — https://discord.gg/kJKPCGQu66

Did you enjoy this article?
Feel like buying me a cup of coffee?
Polygon/Eth/Bsc — 0x4A581E0eaf6b71D05905e8E6014dc0277A1B10ad

New to trading? Try crypto trading bots or copy trading on best crypto exchanges

Join Coinmonks Telegram Channel and Youtube Channel get daily Crypto News

Also, Read

--

--