-
Notifications
You must be signed in to change notification settings - Fork 181
Do not allow decoding transactions with an unsupported version #871
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| '@solana/transaction-messages': patch | ||
| '@solana/transactions': patch | ||
| '@solana/errors': patch | ||
| --- | ||
|
|
||
| Do not allow decoding transactions with an unsupported version |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,9 +6,13 @@ import { | |
| VariableSizeDecoder, | ||
| VariableSizeEncoder, | ||
| } from '@solana/codecs-core'; | ||
| import { SOLANA_ERROR__TRANSACTION__VERSION_NUMBER_OUT_OF_RANGE, SolanaError } from '@solana/errors'; | ||
| import { | ||
| SOLANA_ERROR__TRANSACTION__VERSION_NUMBER_NOT_SUPPORTED, | ||
| SOLANA_ERROR__TRANSACTION__VERSION_NUMBER_OUT_OF_RANGE, | ||
| SolanaError, | ||
| } from '@solana/errors'; | ||
|
|
||
| import { TransactionVersion } from '../transaction-message'; | ||
| import { MAX_SUPPORTED_TRANSACTION_VERSION, TransactionVersion } from '../transaction-message'; | ||
|
|
||
| const VERSION_FLAG_MASK = 0x80; | ||
|
|
||
|
|
@@ -31,6 +35,12 @@ export function getTransactionVersionEncoder(): VariableSizeEncoder<TransactionV | |
| actualVersion: value, | ||
| }); | ||
| } | ||
|
|
||
| if (value > MAX_SUPPORTED_TRANSACTION_VERSION) { | ||
| throw new SolanaError(SOLANA_ERROR__TRANSACTION__VERSION_NUMBER_NOT_SUPPORTED, { | ||
| unsupportedVersion: value, | ||
| }); | ||
| } | ||
|
Comment on lines
+39
to
+43
Member
Author
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. I've also disallowed encoding a I mostly did this because I don't think it makes sense to have different supported/unsupported versions in the encode and decode tests. |
||
| bytes.set([value | VERSION_FLAG_MASK], offset); | ||
| return offset + 1; | ||
| }, | ||
|
|
@@ -53,8 +63,13 @@ export function getTransactionVersionDecoder(): VariableSizeDecoder<TransactionV | |
| // No version flag set; it's a legacy (unversioned) transaction. | ||
| return ['legacy', offset]; | ||
| } else { | ||
| const version = (firstByte ^ VERSION_FLAG_MASK) as TransactionVersion; | ||
| return [version, offset + 1]; | ||
| const version = firstByte ^ VERSION_FLAG_MASK; | ||
| if (version > MAX_SUPPORTED_TRANSACTION_VERSION) { | ||
| throw new SolanaError(SOLANA_ERROR__TRANSACTION__VERSION_NUMBER_NOT_SUPPORTED, { | ||
| unsupportedVersion: version, | ||
| }); | ||
| } | ||
| return [version as TransactionVersion, offset + 1]; | ||
| } | ||
| }, | ||
| }); | ||
|
|
||
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 like this better than what I wrote in the offchain messages PR. I'm going to use this instead.