Skip to content

disallow cpi#4

Merged
zz-sol merged 41 commits into
solana-program:mainfrom
zz-sol:zz/disallow_cpi
Jun 10, 2026
Merged

disallow cpi#4
zz-sol merged 41 commits into
solana-program:mainfrom
zz-sol:zz/disallow_cpi

Conversation

@zz-sol

@zz-sol zz-sol commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

this PR disallows this program to be called via CPI

@zz-sol zz-sol requested a review from samkim-crypto June 8, 2026 14:30

@samkim-crypto samkim-crypto left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me. Just a style suggestion and a clarifying question regarding makefile changes.

Comment thread program/src/lib.rs Outdated
let instruction_data =
core::slice::from_raw_parts(instruction_data_addr, instruction_data_len as usize);
processor::verify_secp256k1_instruction(instruction_data)
match processor::reject_cpi_stack_height(processor::current_stack_height()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is a nit style issue, but this stack height check seems a bit more complicated than necessary. What do you think about adding an in_cpi function like here and just invoking in_cpi() in the beginning of the entrypoint?

Comment thread Makefile
Comment on lines +50 to +60
@if [ -f target/deploy/$(call make-so,$*).so ]; then \
SBF_OUT_DIR=$(PWD)/target/deploy cargo test \
--locked \
--manifest-path $(call make-path,$*)/Cargo.toml \
$(ARGS); \
else \
cargo test \
--locked \
--manifest-path $(call make-path,$*)/Cargo.toml \
$(ARGS); \
fi

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just for my own knowledge, are these changes in the makefile related to the logic of disallowing CPI?

@zz-sol zz-sol Jun 9, 2026

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.

No, this is not related to the CPI.

CI failed after I merged main from a dirty branch, because make test-program requires cargo build-sbf installed. So this was to address the CI failure.

it is now splitted into a dedicated commit.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oh I see. It seems like we need this for mollusk. What do you think about simplifying it as follows?

test-%: build-sbf-%
	SBF_OUT_DIR=$(PWD)/target/deploy cargo test \
		--locked \
		--manifest-path $(call make-path,$*)/Cargo.toml \
		$(ARGS)

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.

hmmm did not work... turns out that we still need a fall back path for mollusk

Comment thread program/src/lib.rs Outdated
processor::verify_secp256k1_instruction(instruction_data)
}
if processor::in_cpi() {
Err(ProgramError::InvalidArgument)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

what about doing something like:

if processor::in_cpi() {
    return Err(ProgramError::InvalidArgument);
}

(... rest of the logic)

We can probably remove the unsafe here too since unsafe is wrapped into the in_cpi() function.

Comment thread Makefile
Comment on lines +50 to +60
@if [ -f target/deploy/$(call make-so,$*).so ]; then \
SBF_OUT_DIR=$(PWD)/target/deploy cargo test \
--locked \
--manifest-path $(call make-path,$*)/Cargo.toml \
$(ARGS); \
else \
cargo test \
--locked \
--manifest-path $(call make-path,$*)/Cargo.toml \
$(ARGS); \
fi

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oh I see. It seems like we need this for mollusk. What do you think about simplifying it as follows?

test-%: build-sbf-%
	SBF_OUT_DIR=$(PWD)/target/deploy cargo test \
		--locked \
		--manifest-path $(call make-path,$*)/Cargo.toml \
		$(ARGS)

@zz-sol zz-sol requested a review from samkim-crypto June 9, 2026 12:57

@samkim-crypto samkim-crypto left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Okay, I think the entrypoint can be simplified a bit more, but since this will require some restructuring for abiv2 anyway, I think this is fine to merge. Thanks for the updates!

@zz-sol zz-sol merged commit 830e05b into solana-program:main Jun 10, 2026
19 checks passed
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.

2 participants