Skip to content

prohibit adding nonce account to address lookup table #659

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/instructions/src/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { AccountRole } from './roles';
export interface AccountMeta<TAddress extends string = string> {
readonly address: Address<TAddress>;
readonly role: AccountRole;
readonly static?: boolean;
}

/**
Expand All @@ -48,6 +49,10 @@ export type WritableSignerAccount<TAddress extends string = string> = AccountMet
role: AccountRole.WRITABLE_SIGNER;
};

export type StaticAccount<TAccount extends AccountMeta> = TAccount & {
readonly static: true;
};

/**
* Represents a lookup of the account's address in an address lookup table. It specifies which
* lookup table account in which to perform the lookup, the index of the desired account address in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,18 +138,22 @@ describe('decompileTransactionMessage', () => {
{
address: 'H4RdPRWYk3pKw2CkNznxQK6J6herjgQke2pzFJW4GC6x' as Address,
role: AccountRole.WRITABLE_SIGNER,
static: true,
},
{
address: 'G35QeFd4jpXWfRkuRKwn8g4vYrmn8DWJ5v88Kkpd8z1V' as Address,
role: AccountRole.READONLY_SIGNER,
static: true,
},
{
address: '3LeBzRE9Yna5zi9R8vdT3MiNQYuEp4gJgVyhhwmqfCtd' as Address,
role: AccountRole.WRITABLE,
static: true,
},
{
address: '8kud9bpNvfemXYdTFjs5cZ8fZinBkx8JAnhVmRwJZk5e' as Address,
role: AccountRole.READONLY,
static: true,
},
],
data: new Uint8Array([0, 1, 2, 3, 4]),
Expand Down Expand Up @@ -342,14 +346,17 @@ describe('decompileTransactionMessage', () => {
{
address: nonceAccountAddress,
role: AccountRole.WRITABLE,
static: true,
},
{
address: recentBlockhashesSysvarAddress,
role: AccountRole.READONLY,
static: true,
},
{
address: nonceAuthorityAddress,
role: AccountRole.WRITABLE_SIGNER,
static: true,
},
],
data: new Uint8Array([4, 0, 0, 0]),
Expand Down Expand Up @@ -437,14 +444,17 @@ describe('decompileTransactionMessage', () => {
{
address: nonceAccountAddress,
role: AccountRole.WRITABLE,
static: true,
},
{
address: recentBlockhashesSysvarAddress,
role: AccountRole.READONLY,
static: true,
},
{
address: nonceAuthorityAddress,
role: AccountRole.READONLY_SIGNER,
static: true,
},
],
data: new Uint8Array([4, 0, 0, 0]),
Expand Down Expand Up @@ -501,14 +511,17 @@ describe('decompileTransactionMessage', () => {
{
address: nonceAccountAddress,
role: AccountRole.WRITABLE,
static: true,
},
{
address: recentBlockhashesSysvarAddress,
role: AccountRole.READONLY,
static: true,
},
{
address: nonceAuthorityAddress,
role: AccountRole.WRITABLE_SIGNER,
static: true,
},
],
data: new Uint8Array([4, 0, 0, 0]),
Expand All @@ -519,10 +532,12 @@ describe('decompileTransactionMessage', () => {
{
address: nonceAuthorityAddress,
role: AccountRole.WRITABLE_SIGNER,
static: true,
},
{
address: nonceAccountAddress,
role: AccountRole.WRITABLE,
static: true,
},
],
data: new Uint8Array([1, 2, 3, 4]),
Expand Down Expand Up @@ -627,7 +642,7 @@ describe('decompileTransactionMessage', () => {
expect(transaction.instructions).toBeFrozenObject();
});
});

describe('for a transaction with address lookup tables', () => {
const blockhash = 'J4yED2jcMAHyQUg61DBmm4njmEydUr2WqrV9cdEcDDgL';
const programAddress = 'HZMKVnRrWLyQLwPLTTLKtY7ET4Cf7pQugrTr9eTBrpsf' as Address;
Expand Down Expand Up @@ -965,6 +980,7 @@ describe('decompileTransactionMessage', () => {
const expectedAccountMeta: AccountMeta = {
address: staticAddress,
role: AccountRole.READONLY,
static: true,
};

const expectedAccountLookupMeta: AccountLookupMeta = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import '@solana/test-matchers/toBeFrozenObject';

import { Address } from '@solana/addresses';
import { AccountRole, Instruction, ReadonlySignerAccount, WritableAccount } from '@solana/instructions';
import { AccountRole, Instruction, ReadonlySignerAccount, StaticAccount, WritableAccount } from '@solana/instructions';
import type { Blockhash } from '@solana/rpc-types';

import { TransactionMessageWithBlockhashLifetime } from '../blockhash';
Expand All @@ -25,7 +25,7 @@ function createMockAdvanceNonceAccountInstruction<
}): TransactionMessageWithDurableNonceLifetime['instructions'][0] {
return {
accounts: [
{ address: nonceAccountAddress, role: AccountRole.WRITABLE } as WritableAccount<TNonceAccountAddress>,
{ address: nonceAccountAddress, role: AccountRole.WRITABLE, static: true } as StaticAccount<WritableAccount<TNonceAccountAddress>>,
{
address:
'SysvarRecentB1ockHashes11111111111111111111' as Address<'SysvarRecentB1ockHashes11111111111111111111'>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ export function compressTransactionMessageUsingAddressLookupTables<
if (
'lookupTableAddress' in account ||
!lookupTableAddresses.has(account.address) ||
isSignerRole(account.role)
isSignerRole(account.role)||
account.static === true
) {
newAccounts.push(account);
continue;
Expand Down
4 changes: 4 additions & 0 deletions packages/transaction-messages/src/decompile-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ function getAccountMetas(message: CompiledTransactionMessage): AccountMeta[] {
accountMetas.push({
address: message.staticAccounts[accountIndex],
role: AccountRole.WRITABLE_SIGNER,
static: true,
});
accountIndex++;
}
Expand All @@ -43,6 +44,7 @@ function getAccountMetas(message: CompiledTransactionMessage): AccountMeta[] {
accountMetas.push({
address: message.staticAccounts[accountIndex],
role: AccountRole.READONLY_SIGNER,
static: true,
});
accountIndex++;
}
Expand All @@ -51,6 +53,7 @@ function getAccountMetas(message: CompiledTransactionMessage): AccountMeta[] {
accountMetas.push({
address: message.staticAccounts[accountIndex],
role: AccountRole.WRITABLE,
static: true,
});
accountIndex++;
}
Expand All @@ -59,6 +62,7 @@ function getAccountMetas(message: CompiledTransactionMessage): AccountMeta[] {
accountMetas.push({
address: message.staticAccounts[accountIndex],
role: AccountRole.READONLY,
static: true,
});
accountIndex++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
isSignerRole,
ReadonlyAccount,
ReadonlySignerAccount,
StaticAccount,
WritableAccount,
WritableSignerAccount,
} from '@solana/instructions';
Expand All @@ -19,7 +20,7 @@ export type AdvanceNonceAccountInstruction<
> = Instruction<'11111111111111111111111111111111'> &
InstructionWithAccounts<
readonly [
WritableAccount<TNonceAccountAddress>,
StaticAccount<WritableAccount<TNonceAccountAddress>>,
ReadonlyAccount<'SysvarRecentB1ockHashes11111111111111111111'>,
ReadonlySignerAccount<TNonceAuthorityAddress> | WritableSignerAccount<TNonceAuthorityAddress>,
]
Expand Down Expand Up @@ -54,7 +55,7 @@ export function createAdvanceNonceAccountInstruction<
): AdvanceNonceAccountInstruction<TNonceAccountAddress, TNonceAuthorityAddress> {
return {
accounts: [
{ address: nonceAccountAddress, role: AccountRole.WRITABLE },
{ address: nonceAccountAddress, role: AccountRole.WRITABLE, static: true },
{
address: RECENT_BLOCKHASHES_SYSVAR_ADDRESS,
role: AccountRole.READONLY,
Expand Down
3 changes: 3 additions & 0 deletions packages/transaction-messages/src/durable-nonce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ function isAdvanceNonceAccountInstructionForNonce<
nonceAccountAddress: TNonceAccountAddress,
nonceAuthorityAddress: TNonceAuthorityAddress,
): instruction is AdvanceNonceAccountInstruction<TNonceAccountAddress, TNonceAuthorityAddress> {
if (!instruction.accounts[0]?.static) {
throw new Error('Nonce account must be marked as static');
}
return (
instruction.accounts[0].address === nonceAccountAddress &&
instruction.accounts[2].address === nonceAuthorityAddress
Expand Down