Skip to content

Update error wording to reflect actual cause - #1154

Merged
paul-schaaf merged 1 commit into
otter-sec:masterfrom
losman0s:man0s/error-wording
Dec 17, 2021
Merged

Update error wording to reflect actual cause#1154
paul-schaaf merged 1 commit into
otter-sec:masterfrom
losman0s:man0s/error-wording

Conversation

@losman0s

@losman0s losman0s commented Dec 16, 2021

Copy link
Copy Markdown
Contributor

Problem

Error message thrown in case of wrong account ownership is too restrictive, and can mislead the developer.

Any Account<'info, XXX> in an endpoint's derive(Accounts) struct is automatically validated at runtime to be owned by the program (~crate) it was created in (c.f. here for the check, and here to see how the #[account] macro automatically sets an account struct's owner). However, when a client call provides an account owned by an unexpected program, the validation fails (good) with the confusing error message The given account is not owned by the executing program (bad).

This does not reflect that fact that an account can very well be owned by any program other than the one executing.

Summary of Changes

Move to suggested error enum name and error message:

#[msg("The given account is owned by a different program than expected")]
AccountOwnedByWrongProgram,

Fixes #1100

@losman0s
losman0s force-pushed the man0s/error-wording branch 4 times, most recently from aa7b7e6 to 6178141 Compare December 17, 2021 09:18
Comment thread CHANGELOG.md Outdated
@losman0s
losman0s force-pushed the man0s/error-wording branch from 6178141 to 89a97d8 Compare December 17, 2021 09:22
@paul-schaaf
paul-schaaf marked this pull request as ready for review December 17, 2021 09:26
@paul-schaaf

Copy link
Copy Markdown
Contributor

@losman0s pls sign the commits in this pr and force push

@losman0s
losman0s force-pushed the man0s/error-wording branch 2 times, most recently from ac64f9c to 9fac17d Compare December 17, 2021 10:40
@losman0s

Copy link
Copy Markdown
Contributor Author

@losman0s pls sign the commits in this pr and force push

@paul-schaaf Done

@paul-schaaf

Copy link
Copy Markdown
Contributor

Problem

Error message thrown in case of wrong account ownership is too restrictive, and can mislead the developer.

Example: an Account<'info, MyData> in an endpoint's derive(Accounts) struct is validated to be owned by program Z (#[account( owner = Z::ID )]), but when a client call provides instead an account owned by Y, the validation fails (good) with the confusing error message The given account is not owned by the executing program (bad).

Summary of Changes

Move to suggested error enum name and error message:

#[msg("The given account is owned by a different program than expected")]
AccountOwnedByWrongProgram,

Fixes #1100

this is not correct btw. this error is not thrown when an owner check fails (which would be the ConstraintOwner error)

@paul-schaaf

Copy link
Copy Markdown
Contributor

#1154 (comment)

because this is wrong, the changelog isnt quite accurate either. this change does not affect the owner validation macro. It's the Account<'a, T> owner validation that fails

@losman0s
losman0s force-pushed the man0s/error-wording branch from 9fac17d to 564ef40 Compare December 17, 2021 11:57
@losman0s

Copy link
Copy Markdown
Contributor Author

@paul-schaaf Does the updated PR description and changelog fit better now?

@paul-schaaf

Copy link
Copy Markdown
Contributor

@losman0s yes

@paul-schaaf
paul-schaaf merged commit 561f7cd into otter-sec:master Dec 17, 2021
akash-osec pushed a commit to akash-osec/anchor that referenced this pull request Mar 25, 2026
@jamie-osec jamie-osec added this to the Pre-1.0 milestone Jun 24, 2026
akash-osec pushed a commit to akash-osec/anchor that referenced this pull request Jul 25, 2026
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.

lang: improve AccountNotProgramOwned error msg or add new error

3 participants