Update Math.sol

pull/5035/head
Hadrien Croubois 4 months ago committed by GitHub
parent cc807105a4
commit e635d9b07c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 12
      contracts/utils/math/Math.sol

@ -23,9 +23,9 @@ library Math {
* The result is stored in two 256 variables such that product = high * 2² + low.
*/
function addFull(uint256 a, uint256 b) internal pure returns (uint256 high, uint256 low) {
unchecked {
low = a + b;
high = SafeCast.toUint(low < a);
assembly ("memory-safe") {
low: = add(a, b)
high: = lt(low, a)
}
}
@ -37,14 +37,12 @@ library Math {
function mulFull(uint256 a, uint256 b) internal pure returns (uint256 high, uint256 low) {
// Compute the product mod 2² and mod 2² - 1, then use use the Chinese Remainder Theorem to reconstruct
// the 512 bit result.
unchecked {
low = a * b;
assembly {
assembly ("memory-safe") {
let mm := mulmod(a, b, not(0))
low := mul(a, b)
high := sub(sub(mm, low), lt(mm, low))
}
}
}
/**
* @dev Returns the addition of two unsigned integers, with an success flag (no overflow).

Loading…
Cancel
Save