Skip to content

fix: enfore type & count matching between ix handler and #instruction[(..)] args#4000

Merged
jacobcreech merged 10 commits into
otter-sec:masterfrom
Otter-0x4ka5h:anchor#3997
Nov 20, 2025
Merged

fix: enfore type & count matching between ix handler and #instruction[(..)] args#4000
jacobcreech merged 10 commits into
otter-sec:masterfrom
Otter-0x4ka5h:anchor#3997

Conversation

@Otter-0x4ka5h

@Otter-0x4ka5h Otter-0x4ka5h commented Oct 19, 2025

Copy link
Copy Markdown
Member

this pr enforces and fixes types on args.
Example: 1

// fail
pub fn abcd(
    ctx: Context<ABCD>,
    data: u64,
) -> Result<()> {
    Ok(())
}

#[derive(Accounts)]
#[instruction(data: u8)]
pub struct ABCD<'info> {
    pub user: Signer<'info>,
}

Example: 2

// pass
type myType = u64;
pub fn abcd(
    ctx: Context<ABCD>,
    data: u64,
) -> Result<()> {
    Ok(())
}

#[derive(Accounts)]
#[instruction(data: myType)]
pub struct ABCD<'info> {
    pub user: Signer<'info>,
}

Example: 3

// fail
pub fn abcd(
    ctx: Context<ABCD>,
    data: u64,
) -> Result<()> {
    Ok(())
}

#[derive(Accounts)]
#[instruction(data: u64, ehe: u64)]
pub struct ABCD<'info> {
    pub user: Signer<'info>,
}

Example: 4

// pass
pub fn abcd(
    ctx: Context<ABCD>,
    data: u64,
) -> Result<()> {
    Ok(())
}

#[derive(Accounts)]
#[instruction(data: u64)]
pub struct ABCD<'info> {
    pub user: Signer<'info>,
}

Closes #3997
Closes #3897

@vercel

vercel Bot commented Oct 19, 2025

Copy link
Copy Markdown

Someone is attempting to deploy a commit to the Solana Foundation Team on Vercel.

A member of the Team first needs to authorize it.

@Otter-0x4ka5h Otter-0x4ka5h changed the title fix: enfore type matching between ix and #instruction[(..)] args fix: enfore type & count matching between ix handler and #instruction[(..)] args Oct 19, 2025
@jamie-osec

Copy link
Copy Markdown
Collaborator

Also closes #453

@0x4ka5h 0x4ka5h requested a review from jamie-osec October 21, 2025 06:03
Comment thread lang/syn/src/codegen/program/handlers.rs
@0x4ka5h 0x4ka5h requested a review from jamie-osec October 22, 2025 03:49
@jamie-osec

Copy link
Copy Markdown
Collaborator

LGTM now

@jacobcreech jacobcreech merged commit b8f96b3 into otter-sec:master Nov 20, 2025
3 of 4 checks passed
@github-project-automation github-project-automation Bot moved this from Security Review Done to Done in Anchor 1.0 Nov 20, 2025
Otter-0x4ka5h added a commit to Otter-0x4ka5h/anchor that referenced this pull request Mar 25, 2026
…[(..)] args (otter-sec#4000)

* fix: silent compiles of ix when #instruction[(..)] expects more args than passed

* cargo fmt

* fix fmt

* fix: enfore type matching between ix and #instruction[(..)] args

* fix: for non #instruction[(..)] accounts

* fix: check for min(expect, actual) params and make remaining stub

* fix: check for min(expect, actual) params and make remaining stub

* chore(add): add unreachable derivate to silence unwanted warnings

* add diagnostic message

---------

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

Labels

Projects

None yet

5 participants