Skip to content
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

adds system instruction to upgrade legacy nonce versions #25789

Merged

Conversation

behzadnouri
Copy link
Contributor

@behzadnouri behzadnouri commented Jun 5, 2022

Problem

#25788
permanently disables durable transactions with legacy nonce versions
which are within chain blockhash domain.

Summary of Changes

This commit adds a new system instruction for a one-time idempotent
upgrade of legacy nonce accounts in order to bump them out of chain
blockhash domain.

@behzadnouri behzadnouri changed the title adds system instruction to upgrade legacy durable nonce accounts adds system instruction to upgrade legacy nonce versions Jun 5, 2022
@behzadnouri behzadnouri force-pushed the upgrade-nonce-instruction branch 3 times, most recently from 14419a4 to 1f652f1 Compare June 6, 2022 00:07
Copy link
Contributor

@t-nelson t-nelson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is looking good, thanks for plumbing through cli and web3.js! just need to add the account owner check, i think

return Err(InstructionError::InvalidInstructionData);
}
instruction_context.check_number_of_instruction_accounts(1)?;
let mut nonce_account =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to verify that the account owner is the system program here to avoid account confusion vulnerabilities

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

@codecov
Copy link

codecov bot commented Jun 6, 2022

Codecov Report

Merging #25789 (169a7e3) into master (8caced6) will decrease coverage by 6.7%.
The diff coverage is n/a.

❗ Current head 169a7e3 differs from pull request most recent head 5cd72ba. Consider uploading reports for the commit 5cd72ba to get more accurate results

@@             Coverage Diff             @@
##           master   #25789       +/-   ##
===========================================
- Coverage    82.1%    75.4%     -6.8%     
===========================================
  Files         628       40      -588     
  Lines      171471     2345   -169126     
  Branches        0      338      +338     
===========================================
- Hits       140878     1769   -139109     
+ Misses      30593      459    -30134     
- Partials        0      117      +117     

@behzadnouri behzadnouri force-pushed the upgrade-nonce-instruction branch 3 times, most recently from 3ea2f13 to 9c7a7fc Compare June 6, 2022 16:04
@jstarry jstarry self-requested a review June 6, 2022 21:00
cli/src/nonce.rs Outdated
) -> ProcessResult {
let latest_blockhash = rpc_client.get_latest_blockhash()?;
let ixs = vec![upgrade_nonce_account(nonce_account)].with_memo(memo);
// TODO what signers?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this comment still needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this code is still in WIP until #25788 is merged.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

Copy link
Member

@jstarry jstarry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm after the todo comment cleanup

cli/src/nonce.rs Outdated
// TODO: need signers.
signers: CliSigners::default(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine because if CliSigners is empty, we fall back to the wallet keypair here:

if signers.is_empty() {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed todo

@@ -307,6 +307,13 @@ pub enum SystemInstruction {
/// Owner to use to derive the funding account address
from_owner: Pubkey,
},

/// One-time idempotent upgrade of legacy nonce versions in order to bump
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this idempotent refers to? i mean, this instruction impl. errors InstructionError::InvalidArgument if Current nonce account (i.e. already upgraded) is given. So, you cannot invoke UpgradeNonceAccount multiple times successfully, given the same nonce account.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It refers to the nonce account value.
If the instruction is applied multiple times on the same nonce account, the nonce account will not change beyond the first time.

@behzadnouri behzadnouri force-pushed the upgrade-nonce-instruction branch 2 times, most recently from e9f5265 to 2562de1 Compare June 9, 2022 13:43
runtime/src/accounts.rs Outdated Show resolved Hide resolved
Comment on lines +499 to +506
let nonce_versions: nonce::state::Versions = nonce_account.get_state()?;
match nonce_versions.upgrade() {
None => Err(InstructionError::InvalidArgument),
Some(nonce_versions) => nonce_account.set_state(&nonce_versions),
}
Copy link
Contributor Author

@behzadnouri behzadnouri Jun 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 🚨 🚨
The assumptions here are that:

  1. Any extant system account that has non-zero data and is not a nonce account is invalid.
  2. Writing to these invalid accounts is fine and won't break anything.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I didn't see them but would be good to have a test to exercise these assumptions

Copy link
Contributor Author

@behzadnouri behzadnouri Jun 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mergify mergify bot dismissed jackcmay’s stale review June 9, 2022 21:42

Pull request has been modified.

solana-labs#25788
permanently disables durable transactions with legacy nonce versions
which are within chain blockhash domain.

This commit adds a new system instruction for a one-time idempotent
upgrade of legacy nonce accounts in order to bump them out of chain
blockhash domain.
@behzadnouri behzadnouri merged commit b419031 into solana-labs:master Jun 10, 2022
@behzadnouri behzadnouri deleted the upgrade-nonce-instruction branch June 10, 2022 00:04
mergify bot pushed a commit that referenced this pull request Jun 10, 2022
…#25789)

#25788
permanently disables durable transactions with legacy nonce versions
which are within chain blockhash domain.

This commit adds a new system instruction for a one-time idempotent
upgrade of legacy nonce accounts in order to bump them out of chain
blockhash domain.

(cherry picked from commit b419031)

# Conflicts:
#	runtime/src/system_instruction_processor.rs
#	sdk/program/src/system_instruction.rs
#	web3.js/src/system-program.ts
mergify bot pushed a commit that referenced this pull request Jun 10, 2022
…#25789)

#25788
permanently disables durable transactions with legacy nonce versions
which are within chain blockhash domain.

This commit adds a new system instruction for a one-time idempotent
upgrade of legacy nonce accounts in order to bump them out of chain
blockhash domain.

(cherry picked from commit b419031)

# Conflicts:
#	sdk/program/src/system_instruction.rs
#	web3.js/src/system-program.ts
behzadnouri added a commit that referenced this pull request Jun 10, 2022
…5789) (#25890)

* feat(nonce): adds system instruction to upgrade legacy nonce versions (#25789)

#25788
permanently disables durable transactions with legacy nonce versions
which are within chain blockhash domain.

This commit adds a new system instruction for a one-time idempotent
upgrade of legacy nonce accounts in order to bump them out of chain
blockhash domain.

(cherry picked from commit b419031)

# Conflicts:
#	runtime/src/system_instruction_processor.rs
#	sdk/program/src/system_instruction.rs
#	web3.js/src/system-program.ts

* removes mergify merge conflicts

* backport UpgradeNonceAccount

Co-authored-by: behzad nouri <[email protected]>
behzadnouri added a commit that referenced this pull request Jun 10, 2022
…5789) (#25891)

* feat(nonce): adds system instruction to upgrade legacy nonce versions (#25789)

#25788
permanently disables durable transactions with legacy nonce versions
which are within chain blockhash domain.

This commit adds a new system instruction for a one-time idempotent
upgrade of legacy nonce accounts in order to bump them out of chain
blockhash domain.

(cherry picked from commit b419031)

# Conflicts:
#	sdk/program/src/system_instruction.rs
#	web3.js/src/system-program.ts

* removes mergify merge conflicts

* backport UpgradeNonceAccount

Co-authored-by: behzad nouri <[email protected]>
if !separate_nonce_from_blockhash {
return Err(InstructionError::InvalidInstructionData);
}
instruction_context.check_number_of_instruction_accounts(1)?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check_number_of_instruction_accounts is not necessary here as UpgradeNonceAccount is added as a whole. It was only used for older instructions to keep the error priorities the same without a feature gate.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though keeping it is consistent with the rest of the instruction processing and might make folks wonder why other places and not here. I would vote to keep it here for consistency with the other instructions and remove them all at once when deemed appropriate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants