Skip to content

fix: scaling values of alpha precompiles#1832

Merged
sam0x17 merged 3 commits intoopentensor:devnet-readyfrom
kenobijon:devnet-ready
Jul 11, 2025
Merged

fix: scaling values of alpha precompiles#1832
sam0x17 merged 3 commits intoopentensor:devnet-readyfrom
kenobijon:devnet-ready

Conversation

@kenobijon
Copy link
Contributor

Description

Alpha precompile was converting the U96F32 price directly to u64 without proper scaling, while the runtime API applies a scaling factor of 1_000_000_000.
Introduced fix to apply proper scaling to getAlphaPrice and getMovingAlphaPrice and pull raw storage value of tao weight.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Other (please describe):

Breaking Change

No breaking change.

Checklist

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have run cargo fmt and cargo clippy to ensure my code is formatted and linted correctly
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@JohnReedV JohnReedV added the skip-cargo-audit This PR fails cargo audit but needs to be merged anyway label Jul 8, 2025
Copy link
Contributor

@JohnReedV JohnReedV left a comment

Choose a reason for hiding this comment

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

The Validate-Benchmarks check will work after merging in the latest devnet-ready branch.

Comment on lines -35 to +36
Ok(U256::from(price.saturating_to_num::<u64>()))
let price_scaled = price.saturating_mul(U96F32::saturating_from_num(1_000_000_000));
Ok(U256::from(price_scaled.saturating_to_num::<u64>()))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could be nice to have the 1_000_000_000 set as the EVM_TO_SUBSTRATE_DECIMALS and set this constant in the runtime common instead of the main runtime file to be able to reuse it.

Copy link
Contributor

Choose a reason for hiding this comment

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

In this case it is not EVM to Substrate conversion, but rather price being U96F32 type internally and u64 in per-bil format externally.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

what do u recommend I call the constant

Copy link
Collaborator

@l0r1s l0r1s left a comment

Choose a reason for hiding this comment

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

one change so we don't end up with magic constants across the codebase

@sam0x17 sam0x17 merged commit e63df74 into opentensor:devnet-ready Jul 11, 2025
118 of 120 checks passed
This was referenced Jul 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-cargo-audit This PR fails cargo audit but needs to be merged anyway

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants