From fb79fe83b428c11fe0b994edb6c80b5331caf518 Mon Sep 17 00:00:00 2001 From: Marcos Pernambuco Motta <1091485+mpernambuco@users.noreply.github.com> Date: Thu, 1 Aug 2024 18:40:14 -0300 Subject: [PATCH] fixup! fixup! feat: increase leaf size --- helper_scripts/generate_UArchConstants.sh | 6 +++--- src/AccessLogs.sol | 15 ++++++++++++--- templates/AccessLogs.sol.template | 14 ++++++++++++-- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/helper_scripts/generate_UArchConstants.sh b/helper_scripts/generate_UArchConstants.sh index 74a059c..83d482e 100755 --- a/helper_scripts/generate_UArchConstants.sh +++ b/helper_scripts/generate_UArchConstants.sh @@ -18,9 +18,9 @@ let last=total-end+1 h=`head -n $start $TEMPLATE_FILE` t=`tail -n -$last $TEMPLATE_FILE` -cd $EMULATOR_DIR -make build-emulator-image -cd - +# cd $EMULATOR_DIR +# make build-emulator-image +# cd - # run the Lua script that instantiates the cartesi module and # outputs the uarch constants values diff --git a/src/AccessLogs.sol b/src/AccessLogs.sol index 5ace90e..2abc625 100644 --- a/src/AccessLogs.sol +++ b/src/AccessLogs.sol @@ -99,7 +99,7 @@ library AccessLogs { (Memory.PhysicalAddress leafAddress, uint64 offset) = readAddress.truncateToLeaf(); - bytes8 readValue = bytes8(readData << (offset << 3)); + bytes8 readValue = getBytes8FromBytes32AtOffset(readData, offset); bytes32 expectedValHash = readLeaf(a, Memory.strideFromLeafAddress(leafAddress)); @@ -147,8 +147,9 @@ library AccessLogs { (Memory.PhysicalAddress leafAddress, uint64 offset) = writeAddress.truncateToLeaf(); - uint64 expectedNewValue = - machineWordToSolidityUint64(bytes8(writtenData << (offset << 3))); + uint64 expectedNewValue = machineWordToSolidityUint64( + getBytes8FromBytes32AtOffset(writtenData, offset) + ); require( newValue == expectedNewValue, @@ -161,4 +162,12 @@ library AccessLogs { keccak256(abi.encodePacked(writtenData)) ); } + + function getBytes8FromBytes32AtOffset(bytes32 source, uint64 offset) + internal + pure + returns (bytes8) + { + return bytes8(source << (offset << Memory.LOG2_WORD)); + } } diff --git a/templates/AccessLogs.sol.template b/templates/AccessLogs.sol.template index 67fdcc3..ba0265e 100644 --- a/templates/AccessLogs.sol.template +++ b/templates/AccessLogs.sol.template @@ -111,7 +111,7 @@ library AccessLogs { bytes32 valHash = keccak256(abi.encodePacked(readData)); (Memory.PhysicalAddress leafAddress, uint64 offset) = readAddress.truncateToLeaf(); - bytes8 readValue = bytes8(readData << (offset << 3)); + bytes8 readValue = getBytes8FromBytes32AtOffset(readData, offset); bytes32 expectedValHash = readLeaf(a, Memory.strideFromLeafAddress(leafAddress)); @@ -158,7 +158,9 @@ library AccessLogs { bytes32 writtenData = a.buffer.consumeBytes32(); (Memory.PhysicalAddress leafAddress, uint64 offset) = writeAddress.truncateToLeaf(); - uint64 expectedNewValue = machineWordToSolidityUint64(bytes8(writtenData << (offset << 3))); + uint64 expectedNewValue = + machineWordToSolidityUint64( + getBytes8FromBytes32AtOffset(writtenData, offset)); require(newValue == expectedNewValue, "Access log value does not contain the expected written value"); @@ -169,6 +171,14 @@ library AccessLogs { ); } + function getBytes8FromBytes32AtOffset(bytes32 source, uint64 offset) + internal + pure + returns (bytes8) + { + return bytes8(source << (offset << Memory.LOG2_WORD)); + } + //:#else /// @dev This library mocks the `templates/AccessLogs.sol` yet with a very different implementation.