From 0be8408a3a29f626bc409ed6644b4e234680d56f Mon Sep 17 00:00:00 2001 From: navelbuffle Date: Fri, 3 Jan 2025 10:51:45 +0300 Subject: [PATCH] extend helper reads with a boolean type --- onchain/src/Push3Interpreter.sol | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/onchain/src/Push3Interpreter.sol b/onchain/src/Push3Interpreter.sol index 4049a63..0ec3699 100644 --- a/onchain/src/Push3Interpreter.sol +++ b/onchain/src/Push3Interpreter.sol @@ -142,6 +142,19 @@ contract Push3Interpreter { val = uint32(word >> 224); } + function readBool(bytes calldata code, uint32 start) internal pure returns (bool val) { + require(start + 1 <= code.length, "readBool out of range"); + uint256 word; + assembly { + let buf := mload(0x40) // free memory + // copy exactly 1 byte from code into buf + calldatacopy(buf, add(code.offset, start), 1) + // assign 1 byte to a word + word := shr(248, mload(buf)) + } + val = word & 1 == 1; + } + /** * @dev Read 2 bytes from `code` at `start` as uint16. */