Skip to content

Safe value types #4850

@romanagureev

Description

@romanagureev

Simple Summary

Make it easy to use numeric values that are allowed to be only within given ranges (and optionally only certain discrete values).

Motivation

When doing math, values may converge and/or have needed properties only for some range (e.g. 10**12 .. 10**36). For example, the Balancer incident wouldn’t be feasible if one restricted Wei swaps. Currently this can be achieved through additional asserts on values, though it makes it hard to follow all inputs/outputs and makes the code clumsy. Adding defined ranges/conditions for values may improve explicitness.

Specification

Basic usage is defining acceptable ranges for values, e.g. 10**12 .. 10**36 for amounts and 10**5 .. 10**10 for fees, with similar ranges for other parameters. Amount values might also need to accept 0. Open question: how to deal with values like 10**18 + 1—in some cases it might be helpful to fully ignore wei values (if it doesn’t break EIP requirements).

Illustrative syntax (suggested by AI):

amount: uint256[10**12:10**36]
fee: uint256[10**5:10**10]
amount18: uint256[10**12:10**36, step=10**10]

Backwards Compatibility

Compatible.

Dependencies

References

Copyright

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions