From 12a5b75e82321ab9786b2cc9ca102b3adb1a0f9b Mon Sep 17 00:00:00 2001 From: Oba Date: Fri, 6 Dec 2024 09:37:06 +0100 Subject: [PATCH] fix: copy exact pendingWordLen (#15) --- src/CairoLib.sol | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/CairoLib.sol b/src/CairoLib.sol index bf9b9d9..9367d82 100644 --- a/src/CairoLib.sol +++ b/src/CairoLib.sol @@ -144,15 +144,14 @@ library CairoLib { uint256 fullWordsLength; uint256 fullWordsPtr; - uint256 pendingWord; + uint256 pendingWordPtr; uint256 pendingWordLen; assembly { fullWordsLength := mload(add(data, 32)) let fullWordsByteLength := mul(fullWordsLength, 32) fullWordsPtr := add(data, 64) - let pendingWordPtr := add(fullWordsPtr, fullWordsByteLength) - pendingWord := mload(pendingWordPtr) + pendingWordPtr := add(fullWordsPtr, fullWordsByteLength) pendingWordLen := mload(add(pendingWordPtr, 32)) } // Calculate the expected length of data @@ -174,7 +173,9 @@ library CairoLib { fullWordsPtr := add(fullWordsPtr, 32) } // Copy pending word - if iszero(eq(pendingWordLen, 0)) { mstore(resultPtr, shl(mul(sub(32, pendingWordLen), 8), pendingWord)) } + if iszero(eq(pendingWordLen, 0)) { + mcopy(resultPtr, add(pendingWordPtr, sub(32, pendingWordLen)), pendingWordLen) + } } return string(result);