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

idl: Check ambiguous discriminators #3157

Conversation

acheroncrypto
Copy link
Collaborator

Problem

The ability to set custom discriminators means the user can also set discriminators that are ambiguous. For example:

#[account(discriminator = 1)]
pub struct SomeAccount {
    pub a: u8,
    pub b: u16,
    pub c: u32,
}

#[account(discriminator = [1, 2, 3, 4])]
pub struct AnotherAccount {
    pub a: u32,
}

In this example, there is no way to reliably decide the expected account type from a given account info's data. For this reason, Anchor should not allow compilation of this program.

However, this results in another problem — definitions of accounts, events, and instructions don't have access to other definitions' discriminators, as proc-macros are stateless. To solve this, ambiguous discriminators should be checked during the IDL generation process, since we have access to all discriminator values (and introducing another idl-build-like feature just to check discriminators would increase the already long build times even more).

Summary of changes

Check potential discriminator collisisons during the IDL generation step.


Note: This PR is part of a greater effort explained in #3097.

Copy link

vercel bot commented Aug 7, 2024

@acheroncrypto is attempting to deploy a commit to the coral-xyz Team on Vercel.

A member of the Team first needs to authorize it.

@acheroncrypto acheroncrypto added idl related to the IDL, either program or client side feature labels Aug 7, 2024
@acheroncrypto acheroncrypto mentioned this pull request Aug 7, 2024
26 tasks
@acheroncrypto acheroncrypto merged commit 438c481 into coral-xyz:master Aug 7, 2024
0 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature idl related to the IDL, either program or client side
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant