5

It’s a simple question, but I couldn’t find an answer. In an ERC20 contract lies this code

//The nonce for avoid transfer replay attacks
mapping(address => uint256) nonces;

.

    uint256 nonce = nonces[_address_from];
    bytes32 h = keccak256(_address_from ,_address_to ,_token_amount, _amount_fee ,nonce);
    if(_address_from != ecrecover(h,_v,_r,_s)) revert();

_r _s _v are functions parameters which must be set manually when calling it on contract execution.

How do I compute _r _s _v from my address and amounts in order to not get the transaction rejected ?

user2284570
  • 1,008
  • 1
  • 12
  • 30

1 Answers1

8

r, s and v are obtained from the signature of the transaction. if you have the signature (assume it is in a variable called sig) you can do:

r = sig.signature.slice(0, 32)
s = sig.signature.slice(32, 64)
v = sig.recovery + 27

So if you want to check that a message was signed by an account you need to pass the r,s and v values to your contract. Notice that when you send transactions to the network, the network do the verification automatically.

The signature can be obtained with web3, see here

Also for a complete discussion see this answer

Hope this help.

Jaime
  • 8,340
  • 1
  • 12
  • 20