ecrecover is problematically hardcoded to pre-EIP-155 transactions #2743
Replies: 24 comments 5 replies
-
|
At least, I think this is what's happening? Any help would be appreciated. |
Beta Was this translation helpful? Give feedback.
-
|
Can you provide the actual inputs you're passing to |
Beta Was this translation helpful? Give feedback.
-
|
In our |
Beta Was this translation helpful? Give feedback.
-
var v = 45; // goerli (5 * 2 + 35)
var publicKey = ecrecover(hash, v, r, s, BigInt(5));This should do the trick. |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
|
I think if you make It should work. Ensure that |
Beta Was this translation helpful? Give feedback.
-
|
Thanks, but same result. "invalid type" |
Beta Was this translation helpful? Give feedback.
-
|
Try this: I'm not able to reproduce your exact error but the above code works. The 2 issues that I found where 1) the |
Beta Was this translation helpful? Give feedback.
-
|
Invalid type again, pasted exactly as above. Not sure what the disconnect is. Why would v need to be a BigInt? It's typically within a single byte range (0-255) except for Sepolia. |
Beta Was this translation helpful? Give feedback.
-
|
FYI, if I just hardcode mainnet (27) in there like this: I no longer get an error and what appears to be a valid byte Buffer. So clearly ecrecover doesn't require a BigInt for v. edit: if I try I get the same results as 28 and 27, respectively. (yes, 0=28 and 1=27). If I try 45 and 46, I get "invalid signature v value". |
Beta Was this translation helpful? Give feedback.
-
|
What version of
I used your script exactly in a pure JS file and got the above error. |
Beta Was this translation helpful? Give feedback.
-
|
I'm using the stock npm repos. Here's my full list of installs. |
Beta Was this translation helpful? Give feedback.
-
|
Several of those are quite out of date. |
Beta Was this translation helpful? Give feedback.
-
|
Updated everything and restarted node console. Still "invalid type" when trying to provide a BigInt for v. Here is the full script: |
Beta Was this translation helpful? Give feedback.
-
|
Is the first line still possibly the issue? const { ecrecover, toBuffer } = require('@ethereumjs/util');
var digestHashInputToTheSigningAlgorithm = '0xee3a667ed717a89d2012240dc28760ab4df39ab6949267aab31cebc4a33ce735';
var v = BigInt(45);
var our_r_and_s = "0x012345678901234567890123456789012345678901234567890123456789012";
var r = toBuffer(our_r_and_s);
var s = toBuffer(our_r_and_s);
var hash = toBuffer(digestHashInputToTheSigningAlgorithm);
var publicKey = ecrecover(hash, v, r, s, BigInt(5));
console.log(publicKey) |
Beta Was this translation helpful? Give feedback.
-
|
No. Still doesn't work. Same as before. Are you installing from public repos? What are your package versions? |
Beta Was this translation helpful? Give feedback.
-
|
Here's an example repo with the most recent version of Just run |
Beta Was this translation helpful? Give feedback.
-
|
This should work on your install with Do not use BigInts in your version, use "normal" numbers vor |
Beta Was this translation helpful? Give feedback.
-
|
And this works for me for: var { ecsign, ecrecover, pubToAddress, toBuffer } = require('ethereumjs-util');
var Web3 = require('web3')
var web3 = new Web3()
// Given values
var contractAddress = "0xc5edca3ebf230f0df3d75b3138d733fe58d234a0";
var unwrapTxValue = "1000000000000000";
var unwrapTxGasLimit = 1000000;
var unwrapTxGasPrice = "50000000000";
// Given values for col and row
var col = 16;
var row = 16;
// Generate the data for the transaction using the function signature and parameters
var unwrapTxData = web3.eth.abi.encodeFunctionCall({
name: 'unwrap',
type: 'function',
inputs: [{
type: 'uint8',
name: 'col'
},{
type: 'uint8',
name: 'row'
}]
}, [col, row]);
var parameters = [
contractAddress,
unwrapTxValue,
unwrapTxGasLimit,
unwrapTxGasPrice,
unwrapTxData
];
// Encode the parameters
var encodedParameters = web3.eth.abi.encodeParameters(
['address', 'uint256', 'uint256', 'uint256', 'bytes'],
parameters
);
// Hash the encoded parameters
var digestHashInputToTheSigningAlgorithm = web3.utils.keccak256(encodedParameters);
var v = 45
var our_r_and_s = '0x012345678901234567890123456789012345678901234567890123456789012'
var r = toBuffer(our_r_and_s)
var s = toBuffer(our_r_and_s)
var hash = toBuffer(digestHashInputToTheSigningAlgorithm)
var publicKey = ecrecover(hash, v, r, s, 5)
console.log(publicKey)I.e. do not use BigInts but use normal numbers. |
Beta Was this translation helpful? Give feedback.
-
|
Thanks. That "works" but maybe not? The resulting byte sequence I get for v=45 is identical to v=27. That doesn't seem right, does it?
|
Beta Was this translation helpful? Give feedback.
-
|
If I take this code I get I change the final lines to: I get an error. Which should be, due to EIP-155. (Note: If I now remove the chainId 5 from I again get |
Beta Was this translation helpful? Give feedback.
-
|
From EIP-155 |
Beta Was this translation helpful? Give feedback.
-
|
If you want to have a chat feel free to join our discord! 😄 https://discord.gg/FV4VnwXMG6 |
Beta Was this translation helpful? Give feedback.
-
|
Ugh. I'm just gonna use pre-eip-155 transactions. This is all too convoluted. (Not to mention solidity ecrecover can't handle Sepolia's chain id.) In your opinions, do you think pre-eip-155 transactions are in any danger of ever being sunset? |
Beta Was this translation helpful? Give feedback.

Uh oh!
There was an error while loading. Please reload this page.
-
ethereumjs-utils' ecrecover function rejects any attempt to use v = anything other than 27 or 28 which means it only supports pre-EIP-155 transactions. This is self-evidently sub-optimal.
Beta Was this translation helpful? Give feedback.
All reactions