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

fix(core, proto): use i128 for price instead of u128 #1991

Merged
merged 5 commits into from
Feb 24, 2025

Conversation

noot
Copy link
Collaborator

@noot noot commented Feb 20, 2025

Summary

it's theoretically possible for the price of an asset to become negative, although rare. in the case where a price became negative, the oracle would be unable to decode the price from the sidecar.

Background

resolves issue 3.2 "Price can become negative" in the zellic audit of the sequencer-side oracle implementation.

Changes

  • implement Int128 proto type, similar to our existing primitive Uint128
  • change Price in core to be i128 internally, instead of u128

Testing

unit tests

@noot noot requested review from a team as code owners February 20, 2025 19:29
@noot noot requested review from Fraser999 and joroshiba February 20, 2025 19:29
@github-actions github-actions bot added proto pertaining to the Astria Protobuf spec sequencer pertaining to the astria-sequencer crate labels Feb 20, 2025
Copy link
Member

@SuperFluffy SuperFluffy left a comment

Choose a reason for hiding this comment

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

Some comments on testing, but looks fine to me.

Note on the PR title: this should probably be fix(proto, core).

Also is there some interaction anywhere where you have to convert u128 to i128 or vice versa? Or will the price always "stand by itself"?

assert_eq!(expected, actual);
}
#[test]
fn i128_roundtrips_work() {
Copy link
Member

Choose a reason for hiding this comment

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

This should contain the case of i128::MIN, -1, and other distinct negative i128 values.

#[test]
fn can_parse_negative_price() {
let price = "-1".parse::<Price>().unwrap();
assert_eq!(price.get(), -1);
Copy link
Member

Choose a reason for hiding this comment

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

IMO compare on Price::new(-1) instead.

@noot noot changed the title fix(core): use i128 for price instead of u128 fix(core, proto): use i128 for price instead of u128 Feb 24, 2025
@noot
Copy link
Collaborator Author

noot commented Feb 24, 2025

Also is there some interaction anywhere where you have to convert u128 to i128 or vice versa? Or will the price always "stand by itself"?

@SuperFluffy no, there shouldn't be any case where prices are turned into a u128, the Price type will always stand alone.

@noot noot merged commit 5d8c66b into feat/oracle Feb 24, 2025
45 checks passed
@noot noot deleted the noot/negative-price branch February 24, 2025 18:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
allow-breaking-proto proto pertaining to the Astria Protobuf spec sequencer pertaining to the astria-sequencer crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants