Skip to content

Conversation

@calintje
Copy link
Contributor

  • Add tests Core tick.rs
  • Fix bug get_initializable_tick_index for ts1
  • Fix uncaught overflow issue in mul_shift_96 after casting to u128
  • Add new error
  • Fix test names in program

WIP

… Fix uncaught overflow issue for mul_shift_96. Add error. Fix test names in program.
let should_round_up = if let Some(round_up) = round_up {
round_up && remainder > 0
} else {
remainder >= tick_spacing_i32 / 2
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Previously, with tick_spacing: 1 and round_up: None, should_round_up would evaluate to true: remainder = 0 and 1_i32 / 2 = 0.

This would result in adding +1 to the result in the if statement below.


fn mul_shift_96(n0: u128, n1: u128) -> u128 {
let mul: U256 = (<U256>::from(n0) * <U256>::from(n1)) >> 96;
mul.as_u128()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ethnum's as_u128() simply takes the lower 128 bits of the u256 and casts that into a u128 without checking the content of the upper 128 bits: https://docs.rs/ethnum/1.5.2/src/ethnum/uint.rs.html#241-244

The program's u256 implementation implements this check here:

return Err(ErrorCode::NumberDownCastError);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants