-
Notifications
You must be signed in to change notification settings - Fork 772
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Util: Allow v
to be 0
or 1
for EIP1559 transactions
#1905
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8168d3f
Util: Allow v to be `0` or `1` for EIP1559 transactions
ernestognw f2dbdaa
vm: fix ecrecover precompile for v=0 and v=1
jochem-brouwer 98e7f36
tx/legacyTransaction: add `v` guard for non-EIP155 txs
jochem-brouwer a74572e
tx: switch to earlier v validation and throwing before v common/EIP-1…
holgerd77 5f6bcc4
tx: remove v==0 check which always defaults to the default common
jochem-brouwer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -136,6 +136,18 @@ export default class Transaction extends BaseTransaction<Transaction> { | |
} | ||
} | ||
|
||
if (!this.supports(Capability.EIP155ReplayProtection)) { | ||
// In case of a signed non-EIP155 tx, `ecrecover` does not get a `chainId` provided | ||
// Internally, `ecrecover` will calculate the recovery bit by `v = v - 27` | ||
// This recovery bit is either 0 or 1. Thus, any other value than `v = 27` or `v = 28` will | ||
// throw upon calling `getSenderAddress` here. Thus throw early in the constructor | ||
if (this.v !== undefined) { | ||
if (!this.v.eqn(27) && !this.v.eqn(28)) { | ||
throw new Error(`Non-EIP155 txs need either v = 27 or v = 28, got v = ${this.v}`) | ||
} | ||
} | ||
} | ||
|
||
if (this.common.isActivatedEIP(3860)) { | ||
checkMaxInitCodeSize(this.common, this.data.length) | ||
} | ||
|
@@ -382,7 +394,7 @@ export default class Transaction extends BaseTransaction<Transaction> { | |
// No unsigned tx and EIP-155 activated and chain ID included | ||
if ( | ||
v !== undefined && | ||
!v.eqn(0) && | ||
!v.eqn(0) && // TODO fixme -> why overwrite/return default common when `v` is set to 0? | ||
jochem-brouwer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
(!common || common.gteHardfork('spuriousDragon')) && | ||
!v.eqn(27) && | ||
!v.eqn(28) | ||
Comment on lines
397
to
398
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are these becoming unreachable code? |
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -389,8 +389,6 @@ tape('[Transaction]', function (t) { | |
'hex' | ||
) | ||
|
||
const fixtureTxSignedWithEIP155 = Transaction.fromTxData(txData).sign(privateKey) | ||
|
||
const common = new Common({ | ||
chain: Chain.Mainnet, | ||
hardfork: Hardfork.TangerineWhistle, | ||
|
@@ -400,9 +398,7 @@ tape('[Transaction]', function (t) { | |
common, | ||
}).sign(privateKey) | ||
|
||
let signedWithEIP155 = Transaction.fromTxData(<any>fixtureTxSignedWithEIP155.toJSON()).sign( | ||
privateKey | ||
) | ||
let signedWithEIP155 = Transaction.fromTxData(<any>txData).sign(privateKey) | ||
|
||
st.true(signedWithEIP155.verifySignature()) | ||
st.notEqual(signedWithEIP155.v?.toString('hex'), '1c') | ||
|
@@ -416,7 +412,7 @@ tape('[Transaction]', function (t) { | |
st.notEqual(signedWithEIP155.v?.toString('hex'), '1c') | ||
st.notEqual(signedWithEIP155.v?.toString('hex'), '1b') | ||
|
||
let signedWithoutEIP155 = Transaction.fromTxData(<any>fixtureTxSignedWithEIP155.toJSON(), { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For these tests we should review if there was any reason why we used this |
||
let signedWithoutEIP155 = Transaction.fromTxData(<any>txData, { | ||
common, | ||
}).sign(privateKey) | ||
|
||
|
@@ -427,7 +423,7 @@ tape('[Transaction]', function (t) { | |
"v shouldn't be EIP155 encoded" | ||
) | ||
|
||
signedWithoutEIP155 = Transaction.fromTxData(<any>fixtureTxSignedWithoutEIP155.toJSON(), { | ||
signedWithoutEIP155 = Transaction.fromTxData(<any>txData, { | ||
common, | ||
}).sign(privateKey) | ||
|
||
|
@@ -442,6 +438,24 @@ tape('[Transaction]', function (t) { | |
} | ||
) | ||
|
||
t.test( | ||
'constructor: throw on non-EIP155 transactions which have v != 27 and v != 28', | ||
function (st) { | ||
function getTxData(v: number) { | ||
return { | ||
v, | ||
} | ||
} | ||
for (let n = 0; n < 27; n++) { | ||
st.throws(() => Transaction.fromTxData(getTxData(n))) | ||
} | ||
st.throws(() => Transaction.fromTxData(getTxData(29))) | ||
st.doesNotThrow(() => Transaction.fromTxData(getTxData(27))) | ||
st.doesNotThrow(() => Transaction.fromTxData(getTxData(28))) | ||
st.end() | ||
} | ||
) | ||
|
||
t.test('sign(), verifySignature(): sign tx with chainId specified in params', function (st) { | ||
const common = new Common({ chain: 42, hardfork: Hardfork.Petersburg }) | ||
let tx = Transaction.fromTxData({}, { common }) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't tie this to "after the _validateTxV() analysis" but rather do before respectively directly in the method, think this will get more robust (less ocassion for the analysis to go wrong).
Will try this and update the tests.