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

Ban unsafe arithmetic operations #485

Merged
merged 2 commits into from
Jul 2, 2024
Merged

Ban unsafe arithmetic operations #485

merged 2 commits into from
Jul 2, 2024

Conversation

keithtensor
Copy link
Contributor

@keithtensor keithtensor commented May 28, 2024

Devnet Companion: #529

This PR bans raw arithmetic operations such as those with the + - / * symbols, and instead replaces them with either the saturating equivalent, or the checked equivalent.

Resolves #303.

@keithtensor keithtensor requested a review from a team May 28, 2024 16:50
@sam0x17
Copy link
Contributor

sam0x17 commented May 29, 2024

looks like some conflicts + CI failures now @keithtensor

@keithtensor keithtensor changed the base branch from development to main May 30, 2024 14:26
@keithtensor keithtensor force-pushed the ban-unsafe-arithmetic branch 3 times, most recently from e5f07f0 to c5620f9 Compare May 30, 2024 14:56
@sam0x17 sam0x17 requested a review from camfairchild June 4, 2024 18:53
pallets/collective/src/lib.rs Show resolved Hide resolved
pallets/subtensor/src/block_step.rs Show resolved Hide resolved
pallets/subtensor/src/lib.rs Show resolved Hide resolved
@sam0x17 sam0x17 requested a review from orriin June 5, 2024 19:33
sam0x17
sam0x17 previously approved these changes Jun 5, 2024
Copy link
Contributor

@sam0x17 sam0x17 left a comment

Choose a reason for hiding this comment

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

I had gpt 4o go over the diff of this in detail with me as well and it is satisfied all of these preserve the original behavior after a long convo

@distributedstatemachine distributedstatemachine changed the base branch from main to testnet June 10, 2024 06:46
@distributedstatemachine distributedstatemachine changed the base branch from testnet to main June 10, 2024 06:47
Copy link
Contributor

@distributedstatemachine distributedstatemachine left a comment

Choose a reason for hiding this comment

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

Approved but lets wait for @sam0x17 on merging this

sam0x17
sam0x17 previously approved these changes Jun 10, 2024
Copy link
Contributor

@sam0x17 sam0x17 left a comment

Choose a reason for hiding this comment

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

changes look good, next step would be for a companion PR to open, with a link to this branch, that merges a this branch into devnet-ready

JohnReedV
JohnReedV previously approved these changes Jun 11, 2024
@sam0x17
Copy link
Contributor

sam0x17 commented Jun 11, 2024

So yeah again, should have a companion that merges this branch into devnet-ready. Not sure what this opentensor:development is or why people keep opening PRs into it 😕

@sam0x17
Copy link
Contributor

sam0x17 commented Jun 11, 2024

but yeah if this is already tested on devnet, should add the devnet-pass label, if this is already tested on testnet, should add the testnet-pass label, at which point it should be able to merge into main

@keithtensor keithtensor force-pushed the ban-unsafe-arithmetic branch 2 times, most recently from 3f1763c to d98e663 Compare June 13, 2024 14:12
@Mananitade
Copy link

I'm curious about the outright ban of the operations + - / *, since these are rather common operations. Have you considered an alternative of catching overflow exceptions? To me, it seems like an overkill, but I'm open to being convinced otherwise. Is it considered good practice in the Rust community to ban these operations? What are the tradeoffs (how much slower does it make things run)?

sam0x17
sam0x17 previously approved these changes Jun 18, 2024
@sam0x17
Copy link
Contributor

sam0x17 commented Jun 18, 2024

I'm curious about the outright ban of the operations + - / *, since these are rather common operations. Have you considered an alternative of catching overflow exceptions? To me, it seems like an overkill, but I'm open to being convinced otherwise. Is it considered good practice in the Rust community to ban these operations? What are the tradeoffs (how much slower does it make things run)?

main reason being panicking in an extrinsic is enough to brick a substrate-based chain. On parity's end they have always said you should only use checked math in extrinsics.

JohnReedV
JohnReedV previously approved these changes Jun 19, 2024
@keithtensor keithtensor dismissed stale reviews from JohnReedV and sam0x17 via 2c5b1ff June 19, 2024 12:37
@sam0x17 sam0x17 added the devnet-ready PR's companion has been merged into devnet-ready label Jun 19, 2024
@sam0x17 sam0x17 added the blue team defensive programming, CI, etc label Jun 21, 2024
@keithtensor keithtensor added on-devnet PR has been deployed to devnet devnet-pass PR has been tested on devnet and removed devnet-ready PR's companion has been merged into devnet-ready on-devnet PR has been deployed to devnet labels Jun 25, 2024
@keithtensor keithtensor added the testnet-pass PR was successfully tested on testnet label Jul 2, 2024
@keithtensor keithtensor merged commit de10267 into main Jul 2, 2024
21 of 33 checks passed
@keithtensor keithtensor deleted the ban-unsafe-arithmetic branch July 2, 2024 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blue team defensive programming, CI, etc devnet-pass PR has been tested on devnet testnet-pass PR was successfully tested on testnet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

deny unsafe math operations
7 participants