Skip to content

Commit eb5a3b2

Browse files
Merge pull request #2928 from rainlanguage/context-column-order
Order clearer reads the order column or reverts
2 parents 5d2b05a + 6b0fe18 commit eb5a3b2

24 files changed

Lines changed: 431 additions & 194 deletions

‎crates/test_fixtures/abis/RaindexV6.json‎

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

‎crates/test_fixtures/abis/RaindexV6SubParser.json‎

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

‎meta/RaindexV6SubParser.rain.meta‎

-20 Bytes
Binary file not shown.
64 Bytes
Binary file not shown.

‎src/concrete/parser/RaindexV6SubParser.sol‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import {
5151
CONTEXT_CALCULATIONS_ROW_MAX_OUTPUT,
5252
CONTEXT_CALCULATIONS_ROWS,
5353
CONTEXT_CALLING_CONTEXT_ROW_ORDER_COUNTERPARTY,
54+
CONTEXT_CALLING_CONTEXT_ROW_ORDER_CLEARER,
5455
CONTEXT_DEPOSIT_COLUMN,
5556
CONTEXT_WITHDRAW_COLUMN,
5657
CONTEXT_CALLING_CONTEXT_ROW_ORDER_OWNER,
@@ -121,6 +122,8 @@ contract RaindexV6SubParser is BaseRainlangSubParser {
121122
contextCallingContextHandlers[CONTEXT_CALLING_CONTEXT_ROW_ORDER_OWNER] = LibParseOperand.handleOperandDisallowed;
122123
contextCallingContextHandlers[CONTEXT_CALLING_CONTEXT_ROW_ORDER_COUNTERPARTY] =
123124
LibParseOperand.handleOperandDisallowed;
125+
contextCallingContextHandlers[CONTEXT_CALLING_CONTEXT_ROW_ORDER_CLEARER] =
126+
LibParseOperand.handleOperandDisallowed;
124127

125128
function(bytes32[] memory) internal pure returns (OperandV2)[] memory contextCalculationsHandlers =
126129
new function(bytes32[] memory) internal pure returns (OperandV2)[](CONTEXT_CALCULATIONS_ROWS);
@@ -216,6 +219,8 @@ contract RaindexV6SubParser is BaseRainlangSubParser {
216219
contextCallingContextParsers[CONTEXT_CALLING_CONTEXT_ROW_ORDER_OWNER] = LibRaindexSubParser.subParserOrderOwner;
217220
contextCallingContextParsers[CONTEXT_CALLING_CONTEXT_ROW_ORDER_COUNTERPARTY] =
218221
LibRaindexSubParser.subParserOrderCounterparty;
222+
contextCallingContextParsers[CONTEXT_CALLING_CONTEXT_ROW_ORDER_CLEARER] =
223+
LibRaindexSubParser.subParserOrderClearer;
219224

220225
function(uint256, uint256, OperandV2) internal view returns (bool, bytes memory, bytes32[] memory)[] memory
221226
contextCalculationsParsers =

‎src/concrete/raindex/RaindexV6.sol‎

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ import {
6464
} from "../../lib/LibRaindex.sol";
6565
import {RaindexV6FlashLender} from "../../abstract/RaindexV6FlashLender.sol";
6666
import {LibBytes32Array} from "rain-solmem-0.1.28/src/lib/LibBytes32Array.sol";
67-
import {LibBytes32Matrix} from "rain-solmem-0.1.28/src/lib/LibBytes32Matrix.sol";
6867

6968
import {LibFormatDecimalFloat} from "rain-math-float-0.3.10/src/lib/format/LibFormatDecimalFloat.sol";
7069
import {
@@ -319,7 +318,10 @@ contract RaindexV6 is IRaindexV6, IMetaV1_2, ReentrancyGuard, Multicall, Raindex
319318
/// with a context of the order hash and the caller.
320319
function _doOrderPost(bytes32 orderHash, TaskV2[] calldata post) internal {
321320
LibRaindex.doPost(
322-
LibBytes32Matrix.matrixFrom(LibBytes32Array.arrayFrom(orderHash, bytes32(uint256(uint160(msg.sender))))),
321+
LibRaindex.callingContextColumn(
322+
CONTEXT_CALLING_CONTEXT_COLUMN,
323+
LibBytes32Array.arrayFrom(orderHash, bytes32(uint256(uint160(msg.sender))))
324+
),
323325
post
324326
);
325327
}
@@ -351,6 +353,7 @@ contract RaindexV6 is IRaindexV6, IMetaV1_2, ReentrancyGuard, Multicall, Raindex
351353
msg.sender,
352354
quoteConfig.signedContext,
353355
new bytes32[](0),
356+
false,
354357
false
355358
);
356359
// true is quote2's "order is live" result required by IRaindexV6.
@@ -441,7 +444,8 @@ contract RaindexV6 is IRaindexV6, IMetaV1_2, ReentrancyGuard, Multicall, Raindex
441444
msg.sender,
442445
takeOrderConfig.signedContext,
443446
new bytes32[](0),
444-
true
447+
true,
448+
false
445449
);
446450

447451
// Skip orders that are too expensive rather than revert as we have
@@ -635,7 +639,8 @@ contract RaindexV6 is IRaindexV6, IMetaV1_2, ReentrancyGuard, Multicall, Raindex
635639
bobOrder.owner,
636640
bobSignedContext,
637641
new bytes32[](0),
638-
false
642+
false,
643+
true
639644
);
640645
(, OrderIOCalculationV4 memory bobOrderIOCalculation) = calculateOrderIO(
641646
bobOrder,
@@ -644,7 +649,8 @@ contract RaindexV6 is IRaindexV6, IMetaV1_2, ReentrancyGuard, Multicall, Raindex
644649
aliceOrder.owner,
645650
aliceSignedContext,
646651
new bytes32[](0),
647-
false
652+
false,
653+
true
648654
);
649655

650656
// Each side must be one `takeOrders4` would take. Given this, each
@@ -720,6 +726,8 @@ contract RaindexV6 is IRaindexV6, IMetaV1_2, ReentrancyGuard, Multicall, Raindex
720726
/// single-order callers (`quote`, `clear3`).
721727
/// @param skipFailure If true, a reverting calculate eval or a stack shorter
722728
/// than `CALCULATE_ORDER_MIN_OUTPUTS` returns false instead of reverting.
729+
/// @param clearing Whether the order column includes the clearer row; true
730+
/// only for `clear3`.
723731
/// @return False if `skipFailure` caught a failure, in which case the
724732
/// calculation is zeroed and MUST NOT be used.
725733
/// @return The order IO calculation.
@@ -730,15 +738,23 @@ contract RaindexV6 is IRaindexV6, IMetaV1_2, ReentrancyGuard, Multicall, Raindex
730738
address counterparty,
731739
SignedContextV1[] memory signedContext,
732740
bytes32[] memory stateOverlay,
733-
bool skipFailure
741+
bool skipFailure,
742+
bool clearing
734743
) internal view returns (bool, OrderIOCalculationV4 memory) {
735744
unchecked {
736745
bytes32[][] memory context;
737746
{
738747
bytes32[][] memory callingContext = new bytes32[][](CALLING_CONTEXT_COLUMNS);
739-
callingContext[CONTEXT_CALLING_CONTEXT_COLUMN - 1] = LibBytes32Array.arrayFrom(
740-
order.hash(), bytes32(uint256(uint160(order.owner))), bytes32(uint256(uint160(counterparty)))
741-
);
748+
callingContext[CONTEXT_CALLING_CONTEXT_COLUMN - 1] = clearing
749+
? LibBytes32Array.arrayFrom(
750+
order.hash(),
751+
bytes32(uint256(uint160(order.owner))),
752+
bytes32(uint256(uint160(counterparty))),
753+
bytes32(uint256(uint160(msg.sender)))
754+
)
755+
: LibBytes32Array.arrayFrom(
756+
order.hash(), bytes32(uint256(uint160(order.owner))), bytes32(uint256(uint160(counterparty)))
757+
);
742758

743759
// The calculations column holds the calculated max output and IO
744760
// ratio, which only become known after the calculate eval below.

‎src/generated/RaindexV6SubParserPointers.sol‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ pragma solidity ^0.8.25;
55
// THIS FILE IS AUTOGENERATED BY THE BUILD SCRIPT. DO NOT EDIT BY HAND.
66

77
/// @dev Hash of the known bytecode.
8-
bytes32 constant BYTECODE_HASH = bytes32(0xabceaad67b2bfb22234dced976036095d341129762d317512657852774711ece);
8+
bytes32 constant BYTECODE_HASH = bytes32(0xbb26d1e20a8360e1508cbc0938a2ed1ad7af70827261928c041de84987ca731e);
99

1010
/// @dev The hash of the meta that describes the contract.
11-
bytes32 constant DESCRIBED_BY_META_HASH = bytes32(0xa18bcfb6026768fff923ba3f6d2ab7c37c7a6ab3f226e540ca92278af8d56f2c);
11+
bytes32 constant DESCRIBED_BY_META_HASH = bytes32(0x8336a7fad53960ed41ca79692ce772de758261a38ddecfa23983c3b89d00aaba);
1212

1313
/// @dev The parse meta that is used to lookup word definitions.
1414
/// The structure of the parse meta is:
@@ -27,7 +27,7 @@ bytes32 constant DESCRIBED_BY_META_HASH = bytes32(0xa18bcfb6026768fff923ba3f6d2a
2727
/// bit count of the previous bloom filter. If we reach the end of the bloom
2828
/// filters then we have a miss.
2929
bytes constant PARSE_META =
30-
hex"0101180010800082000100010480300038412a001810000010020004200004002038038ff54900cc66c61df3dcab0616592209895f0b14fec9301902e0920c5bfe561b21609201e959460b1974270f844db208bcd3bf1c9893761e1049db11b93430180ae9a00af82a7805c138f40d28083f0742ef2104d561fd1215a13315716a6117d260cc107b9bfc0eec7ade13cba2891a6b14a51f792bdb02e0f14716565589";
30+
hex"0101180010a00082000100010480300038412a001810000010020004200004002038038ff54905cc66c61ef3dcab071659220a895f0b15fec9301a02e0920d5bfe561c21609201e959460c19742710844db209bcd3bf1d9893761f1049db12b93430190ae9a00bf82a7806c138f40e28083f0842ef2104d561fd1315a13316716a6118d260cc117b9bfc0fec7ade14cba28900a422961b6b14a520792bdb02e0f14717565589";
3131

3232
/// @dev The build depth of the parser meta.
3333

@@ -39,13 +39,13 @@ uint8 constant PARSE_META_BUILD_DEPTH = 1;
3939
/// to things that happen entirely on the interpreter such as well known
4040
/// constants and references to the context grid.
4141
bytes constant SUB_PARSER_WORD_PARSERS =
42-
hex"16ee170b171a1729173817481757176717761786179617a517b517c417d417e417f4186818771886189618a618b618c618d518e418f41904191419241803181c";
42+
hex"175a17771786179517a417b417c417d317e317f21802181218211831184018501860187018e418f3190219121922193219421951196019701980199019a0187f1898";
4343

4444
/// @dev Every two bytes is a function pointer for an operand handler.
4545
/// These positional indexes all map to the same indexes looked up in the parse
4646
/// meta.
4747
bytes constant OPERAND_HANDLER_FUNCTION_POINTERS =
48-
hex"1ccb1ccb1ccb1ccb1ccb1ccb1ccb1ccb1ccb1ccb1ccb1ccb1ccb1ccb1ccb1ccb1ccb1ccb1ccb1ccb1ccb1ccb1ccb1ccb1ccb1ccb1ccb1ccb1ccb1ccb1cf41d90";
48+
hex"1d471d471d471d471d471d471d471d471d471d471d471d471d471d471d471d471d471d471d471d471d471d471d471d471d471d471d471d471d471d471d471d701e0c";
4949

5050
/// @dev Every two bytes is a function pointer for a literal parser.
5151
/// Literal dispatches are determined by the first byte(s) of the literal

‎src/generated/candidate/GenericPoolRaindexV6ArbOrderTaker.sol‎

Lines changed: 5 additions & 5 deletions
Large diffs are not rendered by default.

‎src/generated/candidate/GenericPoolRaindexV6FlashBorrower.sol‎

Lines changed: 5 additions & 5 deletions
Large diffs are not rendered by default.

‎src/generated/candidate/RaindexV6.sol‎

Lines changed: 4 additions & 4 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)