Skip to content

Commit 1daee44

Browse files
author
chenf
committed
Modified according to audit recommendations
1 parent b64919f commit 1daee44

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

contracts/NestBatchMining.sol

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,8 @@ contract NestBatchMining is ChainConfig, NestFrequentlyUsed, INestBatchMining {
364364

365365
// Freeze token and nest
366366
// Because of the use of floating-point representation(fraction * 16 ^ exponent), it may bring some precision
367-
// loss After assets are frozen according to tokenAmountPerEth * ethNum, the part with poor accuracy may be
368-
// lost when the assets are returned, It should be frozen according to decodeFloat(fraction, exponent) * ethNum
367+
// loss After assets are frozen according to equivalent * scale, the part with poor accuracy may be
368+
// lost when the assets are returned, It should be frozen according to decodeFloat(fraction, exponent) * scale
369369
// However, considering that the loss is less than 1 / 10 ^ 14, the loss here is ignored, and the part of
370370
// precision loss can be transferred out as system income in the future
371371
mapping(address=>UINT) storage balances = _accounts[accountIndex].balances;
@@ -441,7 +441,7 @@ contract NestBatchMining is ChainConfig, NestFrequentlyUsed, INestBatchMining {
441441

442442
uint accountIndex = _addressIndex(msg.sender);
443443
// Number of nest to be pledged
444-
// sheet.token0Scales + sheet.token1Scales is always two times to sheet.ethNum
444+
// sheet.token0Scales + sheet.token1Scales is always two times to sheet.scale (a virtual variable)
445445
uint needNest1k = (takeNum << 2) * uint(sheet.nestNum1k) / (uint(sheet.token0Scales) + uint(sheet.token1Scales));
446446

447447
// 4. Calculate the number of eth, token and nest needed, and freeze them
@@ -572,7 +572,7 @@ contract NestBatchMining is ChainConfig, NestFrequentlyUsed, INestBatchMining {
572572
uint accountIndex = 0;
573573
uint reward = 0;
574574
uint nestNum1k = 0;
575-
uint ethNum = 0;
575+
uint token0Scales = 0;
576576

577577
// storage variable must given a value at declaring, this is useless
578578
mapping(address=>UINT) storage balances = _accounts[0/*accountIndex*/].balances;
@@ -631,7 +631,7 @@ contract NestBatchMining is ChainConfig, NestFrequentlyUsed, INestBatchMining {
631631
}
632632

633633
nestNum1k += uint(sheet.nestNum1k);
634-
ethNum += uint(sheet.token0Scales);
634+
token0Scales += uint(sheet.token0Scales);
635635
tokenValue += _decodeFloat(sheet.priceFloat) * uint(sheet.token1Scales);
636636

637637
// Set sheet.miner to 0, express the sheet is closed
@@ -652,7 +652,7 @@ contract NestBatchMining is ChainConfig, NestFrequentlyUsed, INestBatchMining {
652652
}
653653

654654
// Unfreeze token0
655-
_unfreeze(balances, channel.token0, ethNum * uint(channel.unit), accountIndex);
655+
_unfreeze(balances, channel.token0, token0Scales * uint(channel.unit), accountIndex);
656656

657657
// Unfreeze nest
658658
_unfreeze(balances, NEST_TOKEN_ADDRESS, nestNum1k * 1000 ether, accountIndex);
@@ -792,7 +792,7 @@ contract NestBatchMining is ChainConfig, NestFrequentlyUsed, INestBatchMining {
792792
function _create(
793793
PriceSheet[] storage sheets,
794794
uint accountIndex,
795-
uint32 ethNum,
795+
uint32 scale,
796796
uint nestNum1k,
797797
uint level_shares,
798798
uint equivalent
@@ -801,9 +801,9 @@ contract NestBatchMining is ChainConfig, NestFrequentlyUsed, INestBatchMining {
801801
sheets.push(PriceSheet(
802802
uint32(accountIndex), // uint32 miner;
803803
uint32(block.number), // uint32 height;
804-
ethNum, // uint32 remainScales;
805-
ethNum, // uint32 token0Scales;
806-
ethNum, // uint32 token1Scales;
804+
scale, // uint32 remainScales;
805+
scale, // uint32 token0Scales;
806+
scale, // uint32 token1Scales;
807807
uint24(nestNum1k), // uint32 nestNum1k;
808808
uint8(level_shares >> 8), // uint8 level;
809809
uint8(level_shares & 0xFF),
@@ -1067,7 +1067,7 @@ contract NestBatchMining is ChainConfig, NestFrequentlyUsed, INestBatchMining {
10671067

10681068
// Convert uint to uint96
10691069
function _toUInt96(uint value) internal pure returns (uint96) {
1070-
require(value < 0x1000000000000000000000000);
1070+
require(value < 0x1000000000000000000000000, "NBM:can't convert to uint96");
10711071
return uint96(value);
10721072
}
10731073

0 commit comments

Comments
 (0)