From e220ff39fc72facf0811177a874ea46d22625738 Mon Sep 17 00:00:00 2001 From: navelbuffle Date: Sat, 4 Jan 2025 16:20:00 +0300 Subject: [PATCH] add bool stack return and fix adapter --- onchain/src/Push3IntAdapter.sol | 18 +++++++++--------- onchain/src/Push3Interpreter.sol | 7 ++++++- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/onchain/src/Push3IntAdapter.sol b/onchain/src/Push3IntAdapter.sol index 40f4c39..394d485 100644 --- a/onchain/src/Push3IntAdapter.sol +++ b/onchain/src/Push3IntAdapter.sol @@ -28,9 +28,9 @@ contract Push3IntAdapter { view returns (uint256) { - // CodeTag.SUBLIST is typically enum = 3, but - // let's fetch it via - // (uint8)Push3Interpreter.CodeTag.SUBLIST + // CodeTag.SUBLIST is typically enum = 4, but + // let's fetch it via + // (uint8)Push3Interpreter.CodeTag.SUBLIST // or we can directly pass 3 if we know the numeric value. // We'll do: @@ -70,7 +70,7 @@ contract Push3IntAdapter { initIntStack[0] = in1; // 4) Run - (, , int256[] memory finalIntStack) = + (, , int256[] memory finalIntStack,) = interpreter.runInterpreter(code, initCodeStack, initExecStack, initIntStack); // 5) Return top of final int stack @@ -96,11 +96,11 @@ contract Push3IntAdapter { initIntStack[0] = in1; initIntStack[1] = in2; - (, , int256[] memory finalIntStack) = + (, , int256[] memory finalIntStack,) = interpreter.runInterpreter(code, initCodeStack, initExecStack, initIntStack); require(finalIntStack.length > 0, "No integer output"); - + out1 = finalIntStack[finalIntStack.length - 1]; } @@ -121,7 +121,7 @@ contract Push3IntAdapter { int256[] memory initIntStack = new int256[](1); initIntStack[0] = in1; - (, , int256[] memory finalIntStack) = + (, , int256[] memory finalIntStack,) = interpreter.runInterpreter(code, initCodeStack, initExecStack, initIntStack); require(finalIntStack.length >= 2, "Not enough outputs"); @@ -130,7 +130,7 @@ contract Push3IntAdapter { } /** - * @notice Zero int input, returns entire final int stack + * @notice Zero int input, returns entire final int stack */ function run0InNOut(bytes calldata code) external @@ -144,7 +144,7 @@ contract Push3IntAdapter { uint256[] memory initCodeStack = new uint256[](0); int256[] memory initIntStack = new int256[](0); - (, , int256[] memory finalIntStack) = + (, , int256[] memory finalIntStack,) = interpreter.runInterpreter(code, initCodeStack, initExecStack, initIntStack); return finalIntStack; diff --git a/onchain/src/Push3Interpreter.sol b/onchain/src/Push3Interpreter.sol index aa7bcb4..9b5e572 100644 --- a/onchain/src/Push3Interpreter.sol +++ b/onchain/src/Push3Interpreter.sol @@ -293,7 +293,7 @@ contract Push3Interpreter { uint256[] calldata initCodeStack, // empty uint256[] calldata initExecStack, // descriptors int256[] calldata initIntStack, // 32bit word - bool[] calldata initBoolStack + bool[] calldata initBoolStack // bool array ) external pure @@ -436,5 +436,10 @@ contract Push3Interpreter { for (uint256 i = 0; i < intTop; i++) { finalIntStack[i] = intStack[i]; } + + finalBoolStack = new int256[](boolTop); + for (uint256 i = 0; i < boolTop; i++) { + finalBoolStack[i] = boolStack[i]; + } } }