Skip to content

Commit e8050dd

Browse files
GCdePaulastephenctw
authored andcommitted
fix: fix reason extration
1 parent 96a22c9 commit e8050dd

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/AccessLogs.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,20 +169,20 @@ library AccessLogs {
169169
a.currentRootHash = newRootHash;
170170
}
171171

172-
function getBytes8FromBytes32AtOffset(bytes32 source, uint64 offset)
172+
function getBytes8FromBytes32AtOffset(bytes32 source, uint64 offsetInBytes)
173173
internal
174174
pure
175175
returns (bytes8)
176176
{
177-
return bytes8(source << (offset << Memory.LOG2_WORD));
177+
return bytes8(source << (offsetInBytes << Memory.LOG2_WORD));
178178
}
179179

180180
function setBytes8ToBytes32AtOffset(
181181
bytes8 word,
182182
bytes32 leaf,
183-
uint64 offset
183+
uint64 offsetInBytes
184184
) internal pure returns (bytes32) {
185-
uint256 wordOffset = offset << Memory.LOG2_WORD;
185+
uint256 wordOffset = offsetInBytes << Memory.LOG2_WORD;
186186
bytes32 toWrite = bytes32(word) >> wordOffset;
187187

188188
bytes32 wordMask = bytes32(~bytes8(0));

src/AdvanceStatus.sol

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ library AdvanceStatus {
3939
} cmt_io_yield_t;
4040
*/
4141

42+
error InvalidReason(uint16 reason);
43+
4244
function advanceStatus(AccessLogs.Context memory a)
4345
internal
4446
pure
@@ -55,7 +57,7 @@ library AdvanceStatus {
5557

5658
uint64 tohost =
5759
EmulatorCompat.readWord(a, EmulatorConstants.HTIF_TOHOST_ADDRESS);
58-
uint16 reason = uint16((tohost >> 16) & ((1 << 16) - 1));
60+
uint16 reason = uint16(tohost >> 32);
5961

6062
if (reason == EmulatorConstants.CMIO_YIELD_MANUAL_REASON_RX_ACCEPTED) {
6163
return Status.ACCEPTED;
@@ -68,7 +70,7 @@ library AdvanceStatus {
6870
) {
6971
return Status.EXCEPTION;
7072
} else {
71-
revert("Invalid reason");
73+
revert InvalidReason(reason);
7274
}
7375
}
7476
}

0 commit comments

Comments
 (0)