Skip to content

Commit

Permalink
fixup! fixup! feat: increase leaf size
Browse files Browse the repository at this point in the history
  • Loading branch information
mpernambuco committed Aug 1, 2024
1 parent 1ba38d9 commit fb79fe8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
6 changes: 3 additions & 3 deletions helper_scripts/generate_UArchConstants.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 12 additions & 3 deletions src/AccessLogs.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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,
Expand All @@ -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));
}
}
14 changes: 12 additions & 2 deletions templates/AccessLogs.sol.template
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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");

Expand All @@ -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.
Expand Down

0 comments on commit fb79fe8

Please sign in to comment.