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 Gas and Ink types in rust #2736

Merged
merged 7 commits into from
Oct 16, 2024
Merged

Add Gas and Ink types in rust #2736

merged 7 commits into from
Oct 16, 2024

Conversation

PlasmaPower
Copy link
Collaborator

@PlasmaPower PlasmaPower commented Oct 14, 2024

This should help prevent future incidents like the one in storage_load where an ink cost was mistakenly used as an amount of gas.

Fixes NIT-2850

@cla-bot cla-bot bot added the s Automatically added by the CLA bot if the creator of a PR is registered as having signed the CLA. label Oct 14, 2024
eljobe
eljobe previously approved these changes Oct 15, 2024
Copy link
Member

@eljobe eljobe left a comment

Choose a reason for hiding this comment

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

LGTM.

I have a precious few minor comments/ideas, but this looks great.

arbitrator/arbutil/src/evm/api.rs Show resolved Hide resolved

/// For hostios that include pointers.
pub const PTR_INK: u64 = 13440 - HOSTIO_INK;
pub const PTR_INK: Ink = Ink(13440 - HOSTIO_INK.0);
Copy link
Member

Choose a reason for hiding this comment

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

Should we prefer:
pub const PTR_INK: Ink = Ink(13440) - HOSTIO_INK

I find it a little nicer to read instead of thinking, "Oh right, .0 means the wrapped u64."

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm afraid

calls in constants are limited to constant functions, tuple structs and tuple variants

I could make a constant subtraction method or use saturating_sub, but the normal subtraction is via a trait which can't be made const yet (they're still figuring out the syntax for that and how it'll work).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually, after seeing your comment on the Gas(EVM_API_INK.0) line, I decided to introduce a const sub method to prevent accidentally mixing Gas and Ink types in a situation like this, and use it here.

arbitrator/prover/src/programs/memory.rs Outdated Show resolved Hide resolved
@@ -147,7 +147,7 @@ pub trait UserHost<DR: DataReader>: GasMeteredMachine {

// require for cache-miss case, preserve wrong behavior for old arbos
let evm_api_gas_to_use = if arbos_version < ARBOS_VERSION_STYLUS_CHARGING_FIXES {
EVM_API_INK
Gas(EVM_API_INK.0)
Copy link
Member

Choose a reason for hiding this comment

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

Not actionable:

But, I love how quickly my mind went, "Wait, this can't be right! He's using an ink value to initialize a Gas." before I realized that this is in the block that says, "preserve wrong behavior" in the comment.

Copy link
Member

@eljobe eljobe left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@tsahee tsahee left a comment

Choose a reason for hiding this comment

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

LGTM

@tsahee tsahee merged commit fc2c2d8 into master Oct 16, 2024
15 checks passed
@tsahee tsahee deleted the gas-and-ink-types branch October 16, 2024 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design-approved s Automatically added by the CLA bot if the creator of a PR is registered as having signed the CLA.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants