Skip to content

feat(cli): Add program ID mismatch check before building#4018

Merged
jacobcreech merged 28 commits intosolana-foundation:masterfrom
swaroop-osec:feat/issue-3985
Nov 27, 2025
Merged

feat(cli): Add program ID mismatch check before building#4018
jacobcreech merged 28 commits intosolana-foundation:masterfrom
swaroop-osec:feat/issue-3985

Conversation

@swaroop-osec
Copy link
Copy Markdown
Collaborator

@swaroop-osec swaroop-osec commented Oct 23, 2025

Closes #3985

  • Added a check_program_id_mismatch function to verify if there’s a mismatch between the program keypair and the declare_id! in the source code during the build step. If a mismatch is detected, it returns an error prompting the user to run anchor keys sync
  • Users can bypass this check by using the --ignore-keys flag.

@vercel
Copy link
Copy Markdown

vercel bot commented Oct 23, 2025

@swaroop-osec is attempting to deploy a commit to the Solana Foundation Team on Vercel.

A member of the Team first needs to authorize it.

@swaroop-osec swaroop-osec self-assigned this Oct 23, 2025
@swaroop-osec swaroop-osec added the enhancement New feature or request label Oct 23, 2025
@swaroop-osec swaroop-osec marked this pull request as ready for review October 23, 2025 07:14
@jamie-osec
Copy link
Copy Markdown
Collaborator

jamie-osec commented Oct 23, 2025

Approach LGTM once test failures are fixed

);
const myAccount = await program.account.myAccount.fetch(
pubkeys.myAccount
pubkeys.myAccount as anchor.web3.PublicKey
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🤔 What change caused this to be needed?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Tbh I really have no idea some times the typescript raises errors. And the tests were passed locally without this change. Another example

@hrls
Copy link
Copy Markdown
Contributor

hrls commented Oct 23, 2025

We use #[cfg(feature = "contour")] IDs in our programs. Like for devnet, staging and so on. And program secrets are not in repo.
This PR forces us to use --skip-lint flag for just successful build. There should be a way to skip only ID sync, not the whole linter phase.

IMO regex based anchor keys sync is broken by design for anything more complex than single ID program with local keys. Program ID must be extracted from build product instead.

Copy link
Copy Markdown
Contributor

@Otter-0x4ka5h Otter-0x4ka5h left a comment

Choose a reason for hiding this comment

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

lgtm now.

Copy link
Copy Markdown
Collaborator

@jamie-osec jamie-osec left a comment

Choose a reason for hiding this comment

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

LGTM

@jacobcreech jacobcreech merged commit 007ed0d into solana-foundation:master Nov 27, 2025
56 of 57 checks passed
Otter-0x4ka5h pushed a commit to Otter-0x4ka5h/anchor that referenced this pull request Mar 25, 2026
…dation#4018)

* feat(cli): Add program ID mismatch check before building

* feat(cli): Skip program ID mismatch check if --skip-lint is used

* chore(tests): Add --skip-lint option to anchor build command

* fix(tests): Sync keys before building programs in safety checks

* fix(cli): Update program ID mismatch message to include '--skip-lint' option

* chore(tests): Fix safety-checks test

* fix(tests): Fix typescript error

* chore(tests): Add cleanup commands to safety-checks test

* refactor(tests): Update confirmation options in CPI return and events tests

* refactor(tests): prettier

* feat(cli): Introduce --ignore-keys option to skip program ID mismatch checks

* refactor(tests): Restore test.sh from master

* fix(tests): Update safety-checks test to use --ignore-keys

* refactor(cli): Clippy Fixes

* chore(tutorial): Update test script to include --ignore-keys option across all basic examples

* fix(tests): Format bench.json

* fix(tests): Add --ignore-keys option to stack-memory test build command

* fix(tests): Remove newline at end of bench.json

* fix(tests): Format stack-memory.ts

* feat(docs): Update CHANGELOG.md

* fix(tests): Set ignore_keys to true in anchor test

* fix(tests): Remove --ignore-keys option from anchor test

* feat(cli): Updated docs

* refactor(cli): Fix clippy warnings

* chore: fix merge conflict

* fix: merge conflict

---------

Co-authored-by: Jacob Creech <82475023+jacobcreech@users.noreply.github.com>
Co-authored-by: Jacob Creech <jacob.creech@solana.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request Merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

anchor build should run anchor keys sync before building program

6 participants