Skip to content

Commit

Permalink
fix: update order cancelation and allow partial fills validation
Browse files Browse the repository at this point in the history
  • Loading branch information
dcapitator committed Dec 4, 2024
1 parent 4546493 commit 70dcf44
Show file tree
Hide file tree
Showing 10 changed files with 617 additions and 485 deletions.
50 changes: 42 additions & 8 deletions contracts/marketplace/exchange/ExchangeCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -410,17 +410,51 @@ contract ExchangeCore is
);
}

function setOrderFill(bytes32 hash, uint256 fill) external {
///@dev Assert fill is not already set.
if (fills[msg.sender][hash] == fill) {
revert FillIsSetToTheDesiredValue();
/**
* @notice Allows makers to update order fills with strict validation
* @dev Prevents manipulative fill modifications after partial or full order execution
* @param hashes Array of order hashes to update fills for
* @param newFillsToSet Array of new fill values corresponding to each hash
*
* Key invariants:
* - Fills can only be increased, not decreased
* - Prevents resetting or arbitrarily changing fills after partial execution
* - Protects against post-match fill manipulation
*/
function setOrdersFill(
bytes32[] calldata hashes,
uint256[] calldata newFillsToSet
) external {
uint256 length = hashes.length;

// Validate input arrays have matching lengths
if (length == 0 || length != newFillsToSet.length) {
revert LengthMismatch();
}

///@dev Mark order as accordingly filled.
fills[msg.sender][hash] = fill;
address maker = msg.sender;
mapping(bytes32 => uint256) storage makerFills = fills[maker];

unchecked {
for (uint256 i; i < length; ) {
bytes32 hash = hashes[i];
uint256 newFill = newFillsToSet[i];
uint256 currentFill = makerFills[hash];

// Strict fill update rules:
// 1. Prevent setting fills to 0
// 2. Only allow increasing existing fills
// 3. Prevent arbitrary fill manipulations
if (newFill > currentFill) {
makerFills[hash] = newFill;

///@notice Log order fill change event.
emit OrderFillChanged(hash, msg.sender, fill);
// Emit event for off-chain tracking
emit OrderFillChanged(hash, maker, newFill);
}

++i;
}
}
}

function atomicMatch(
Expand Down
10 changes: 5 additions & 5 deletions contracts/marketplace/lib/MarketErrorsAndEvents.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ interface MarketErrorsAndEvents {
*/
error OrderHasAlreadyBeenApproved();

/**
* @dev Error indicating that the fill value is already set to the desired value.
*/
error FillIsSetToTheDesiredValue();

/**
* @dev Error indicating that the first order hash has invalid parameters.
*/
Expand Down Expand Up @@ -106,6 +101,11 @@ interface MarketErrorsAndEvents {
*/
error FeeMismatch();

/**
* @dev Error indicating a mismatch in fees.
*/
error LengthMismatch();

/**
* @dev Error indicating that the sender is not authorized.
*/
Expand Down
Loading

0 comments on commit 70dcf44

Please sign in to comment.