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

Add builtins crate #3866

Merged
merged 7 commits into from
Dec 10, 2024
Merged

Conversation

buffalojoec
Copy link

@buffalojoec buffalojoec commented Dec 2, 2024

Problem

The new changes surrounding allocation of minimum required compute units for builtin programs in the cost model have realized a need to track the status of a builtin's migration to BPF. However, currently we are keeping these migration feature gates in two separate lists.

Summary of Changes

Introduce a solana-builtins crate, which can be the single source of truth for the list of builtins, including their migration feature ID and their CU designation.

enable_feature_id: Some(feature_set::zk_elgamal_proof_program_enabled::id()),
program_id: solana_sdk_ids::zk_elgamal_proof_program::id(),
entrypoint: solana_zk_elgamal_proof_program::Entrypoint::vm,
native_cu_cost: 0, // TODO, these are per-instruction.
Copy link
Author

Choose a reason for hiding this comment

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

@tao-stones the two ZK builtins are going to be tricky since they are metered per-instruction.

Copy link

@tao-stones tao-stones Dec 2, 2024

Choose a reason for hiding this comment

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

Yea, I don't know what to do with ZK builtins, they are per instruction and they consume much more CUs than other regular builtins. We could consider them as "not builtins" so to allocate 200K by default (Assume users of ZK will set cu-limit sensibly); or we can speed up SIMD-198 to make all remaining builtins per instruction as well (tho that does not address the issue that original builtins consumes hundreds of CUs, while ZK takes thousands of CUs)

Copy link
Author

Choose a reason for hiding this comment

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

Well, you originally didn't have them in the list, so should they not be included here at all? Or is setting them to zero okay?

Choose a reason for hiding this comment

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

There was no ZK when the list was created :) I think ZK builtins should be included in the list with "MAX(per instruction cost)"; then:

  • before SIMD-170 (eg, current behavior): cost mode reserve enough CUs for all its instructions, maybe a bit over reserving for some, but that is not new. VM's CU Meter always give default 200K for it.
  • after SIMD-170, both cost model and CU meter don't care about native_cu_cost anymore, they will give 3K CU for it, if user didn't request CU Limit, therefore fails TX.

Choose a reason for hiding this comment

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

wdyt @jstarry

Copy link

Choose a reason for hiding this comment

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

I don't really follow what you're suggesting we do in your comment above. But in any case, this PR should definitely not be changing the static list of builtins without a feature gate.

Choose a reason for hiding this comment

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

Not disagree that the static list shouldn't be changed without feature gate. But technically can still do that before #3799 feature gate is activated.

Copy link

@jstarry jstarry Dec 6, 2024

Choose a reason for hiding this comment

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

Yes we could but I don't think a crate refactoring PR is the right time do that. If we want to update the list before SIMD-0170 is activated we would need to backport the change to v2.0 and v2.1 and update the list of builtin id's included in the SIMD-0170 proposal details.

@buffalojoec buffalojoec force-pushed the joec-builtins-crate branch 2 times, most recently from d3b5f51 to 5cfd990 Compare December 3, 2024 06:20
@buffalojoec buffalojoec marked this pull request as ready for review December 3, 2024 08:18
@buffalojoec buffalojoec requested a review from a team as a code owner December 3, 2024 08:18
LucasSte
LucasSte previously approved these changes Dec 3, 2024
Copy link

@LucasSte LucasSte left a comment

Choose a reason for hiding this comment

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

SVM-wise looks good.

@buffalojoec buffalojoec changed the title [DRAFT] builtins crate Add builtins crate Dec 3, 2024
builtins-default-costs/src/lib.rs Outdated Show resolved Hide resolved
@buffalojoec
Copy link
Author

buffalojoec commented Dec 6, 2024

@jstarry @tao-stones @LucasSte I've popped the last commit (where I modify the CU default cost list) from this PR.

I think moving the list of builtins to its own crate is useful for a few reasons. It gives us, and other developers, the ability to access this list, the builtin entrypoint functions, and their respective feature gates (both for enabling and migrating) without having to pull in the whole runtime.

In another follow-up PR, I'll address the cost model problem more directly and see what you guys think.

jstarry
jstarry previously approved these changes Dec 6, 2024
Copy link

@tao-stones tao-stones left a comment

Choose a reason for hiding this comment

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

lgtm - makes sense to separate default cost related stuff from this PR

@buffalojoec
Copy link
Author

cc @yihau

@buffalojoec buffalojoec merged commit 6c6c26e into anza-xyz:master Dec 10, 2024
51 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.

4 participants