From 2a40f4b409ad665279c155c66a8ca151922e10d3 Mon Sep 17 00:00:00 2001 From: acheron Date: Mon, 12 Aug 2024 18:49:37 +0200 Subject: [PATCH 1/2] idl: Disallow empty discriminators --- idl/src/build.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/idl/src/build.rs b/idl/src/build.rs index 563534f7fe..0dcc18c0bb 100644 --- a/idl/src/build.rs +++ b/idl/src/build.rs @@ -293,6 +293,22 @@ fn verify(idl: &Idl) -> Result<()> { )); } + // Check empty discriminators + macro_rules! check_empty_discriminators { + ($field:ident) => { + if let Some(item) = idl.$field.iter().find(|it| it.discriminator.is_empty()) { + return Err(anyhow!( + "Empty discriminators are not allowed for {}: `{}`", + stringify!($field), + item.name + )); + } + }; + } + check_empty_discriminators!(accounts); + check_empty_discriminators!(events); + check_empty_discriminators!(instructions); + // Check potential discriminator collisions macro_rules! check_discriminator_collision { ($field:ident) => { @@ -312,7 +328,6 @@ fn verify(idl: &Idl) -> Result<()> { } }; } - check_discriminator_collision!(accounts); check_discriminator_collision!(events); check_discriminator_collision!(instructions); From 3d7f79bdb28f32f641fcd1b4b58d70b1c2fac288 Mon Sep 17 00:00:00 2001 From: acheron Date: Mon, 12 Aug 2024 23:06:38 +0200 Subject: [PATCH 2/2] Update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0bf5871bc9..cf8682e3b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,7 @@ The minor version will be incremented upon a breaking change and the patch versi - idl: Check ambiguous discriminators ([#3157](https://github.com/coral-xyz/anchor/pull/3157)). - idl: Disallow all zero account discriminators ([#3159](https://github.com/coral-xyz/anchor/pull/3159)). - cli: Support non-8-byte discriminators ([#3165](https://github.com/coral-xyz/anchor/pull/3165)). +- idl: Disallow empty discriminators ([#3166](https://github.com/coral-xyz/anchor/pull/3166)). ### Fixes