@@ -315,10 +315,10 @@ abstract contract StdCheatsSafe {
315315 txDetail.data = rawDetail.data;
316316 txDetail.from = rawDetail.from;
317317 txDetail.to = rawDetail.to;
318- txDetail.nonce = bytesToUint (rawDetail.nonce);
319- txDetail.txType = bytesToUint (rawDetail.txType);
320- txDetail.value = bytesToUint (rawDetail.value);
321- txDetail.gas = bytesToUint (rawDetail.gas);
318+ txDetail.nonce = _bytesToUint (rawDetail.nonce);
319+ txDetail.txType = _bytesToUint (rawDetail.txType);
320+ txDetail.value = _bytesToUint (rawDetail.value);
321+ txDetail.gas = _bytesToUint (rawDetail.gas);
322322 txDetail.accessList = rawDetail.accessList;
323323 return txDetail;
324324 }
@@ -368,12 +368,12 @@ abstract contract StdCheatsSafe {
368368 receipt.to = rawReceipt.to;
369369 receipt.from = rawReceipt.from;
370370 receipt.contractAddress = rawReceipt.contractAddress;
371- receipt.effectiveGasPrice = bytesToUint (rawReceipt.effectiveGasPrice);
372- receipt.cumulativeGasUsed = bytesToUint (rawReceipt.cumulativeGasUsed);
373- receipt.gasUsed = bytesToUint (rawReceipt.gasUsed);
374- receipt.status = bytesToUint (rawReceipt.status);
375- receipt.transactionIndex = bytesToUint (rawReceipt.transactionIndex);
376- receipt.blockNumber = bytesToUint (rawReceipt.blockNumber);
371+ receipt.effectiveGasPrice = _bytesToUint (rawReceipt.effectiveGasPrice);
372+ receipt.cumulativeGasUsed = _bytesToUint (rawReceipt.cumulativeGasUsed);
373+ receipt.gasUsed = _bytesToUint (rawReceipt.gasUsed);
374+ receipt.status = _bytesToUint (rawReceipt.status);
375+ receipt.transactionIndex = _bytesToUint (rawReceipt.transactionIndex);
376+ receipt.blockNumber = _bytesToUint (rawReceipt.blockNumber);
377377 receipt.logs = rawToConvertedReceiptLogs (rawReceipt.logs);
378378 receipt.logsBloom = rawReceipt.logsBloom;
379379 receipt.transactionHash = rawReceipt.transactionHash;
@@ -390,12 +390,12 @@ abstract contract StdCheatsSafe {
390390 for (uint256 i; i < rawLogs.length ; i++ ) {
391391 logs[i].logAddress = rawLogs[i].logAddress;
392392 logs[i].blockHash = rawLogs[i].blockHash;
393- logs[i].blockNumber = bytesToUint (rawLogs[i].blockNumber);
393+ logs[i].blockNumber = _bytesToUint (rawLogs[i].blockNumber);
394394 logs[i].data = rawLogs[i].data;
395- logs[i].logIndex = bytesToUint (rawLogs[i].logIndex);
395+ logs[i].logIndex = _bytesToUint (rawLogs[i].logIndex);
396396 logs[i].topics = rawLogs[i].topics;
397- logs[i].transactionIndex = bytesToUint (rawLogs[i].transactionIndex);
398- logs[i].transactionLogIndex = bytesToUint (rawLogs[i].transactionLogIndex);
397+ logs[i].transactionIndex = _bytesToUint (rawLogs[i].transactionIndex);
398+ logs[i].transactionLogIndex = _bytesToUint (rawLogs[i].transactionLogIndex);
399399 logs[i].removed = rawLogs[i].removed;
400400 }
401401 return logs;
@@ -466,12 +466,9 @@ abstract contract StdCheatsSafe {
466466 who = vm.rememberKey (privateKey);
467467 }
468468
469- function bytesToUint (bytes memory b ) private pure returns (uint256 ) {
470- uint256 number;
471- for (uint256 i = 0 ; i < b.length ; i++ ) {
472- number = number + uint256 (uint8 (b[i])) * (2 ** (8 * (b.length - (i + 1 ))));
473- }
474- return number;
469+ function _bytesToUint (bytes memory b ) private pure returns (uint256 ) {
470+ require (b.length <= 32 , "StdCheats _bytesToUint(bytes): Bytes length exceeds 32. " );
471+ return abi.decode (abi.encodePacked (new bytes (32 - b.length ), b), (uint256 ));
475472 }
476473}
477474
0 commit comments