Skip to content

Commit

Permalink
Merge pull request #35 from ProjectOpenSea/validator-optimizations
Browse files Browse the repository at this point in the history
avoid setting unused filledNumerator values in OrderValidator
  • Loading branch information
0age authored Feb 28, 2024
2 parents d066634 + 94f5539 commit ed0ae6e
Showing 1 changed file with 4 additions and 16 deletions.
20 changes: 4 additions & 16 deletions src/core/lib/OrderValidator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,6 @@ contract OrderValidator is Executor, ZoneInteraction {
// Set the fill size to the current size.
denominator := filledDenominator

// Set the filled amount to the current size.
filledNumerator := filledDenominator

// Exit the "loop" early.
break
}
Expand All @@ -314,9 +311,6 @@ contract OrderValidator is Executor, ZoneInteraction {
// reduce the amount to fill by the excess.
numerator := sub(numerator, carry)

// Reduce the filled amount by the excess as well.
filledNumerator := sub(filledNumerator, carry)

// Exit the "loop" early.
break
}
Expand Down Expand Up @@ -346,10 +340,8 @@ contract OrderValidator is Executor, ZoneInteraction {
// Reduce the filled amount by the excess as well.
filledNumerator := sub(filledNumerator, carry)

// Check filledNumerator and denominator for uint120 overflow.
if or(
gt(filledNumerator, MaxUint120), gt(denominator, MaxUint120)
) {
// Check denominator for uint120 overflow.
if gt(denominator, MaxUint120) {
// Derive greatest common divisor using euclidean algorithm.
function gcd(_a, _b) -> out {
// "Loop" until only one non-zero value remains.
Expand All @@ -375,16 +367,12 @@ contract OrderValidator is Executor, ZoneInteraction {
// Ensure that the divisor is at least one.
let safeScaleDown := add(scaleDown, iszero(scaleDown))

// Scale all fractional values down by gcd.
// Scale fractional values down by gcd.
numerator := div(numerator, safeScaleDown)
filledNumerator := div(filledNumerator, safeScaleDown)
denominator := div(denominator, safeScaleDown)

// Perform the overflow check a second time.
if or(
gt(filledNumerator, MaxUint120),
gt(denominator, MaxUint120)
) {
if gt(denominator, MaxUint120) {
// Store the Panic error signature.
mstore(0, Panic_error_selector)
// Store the arithmetic (0x11) panic code.
Expand Down

0 comments on commit ed0ae6e

Please sign in to comment.