Merge pull request #692 from gzliudan/fix-sa4006

all: fix staticcheck warning SA4006: never used value
This commit is contained in:
Daniel Liu 2024-10-25 15:26:38 +08:00 committed by GitHub
commit bd4bb14b5e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 46 additions and 78 deletions

View file

@ -656,9 +656,10 @@ func (XDCx *XDCX) ProcessCancelOrder(header *types.Header, tradingStateDB *tradi
} }
log.Debug("ProcessCancelOrder", "baseToken", originOrder.BaseToken, "quoteToken", originOrder.QuoteToken) log.Debug("ProcessCancelOrder", "baseToken", originOrder.BaseToken, "quoteToken", originOrder.QuoteToken)
feeRate := tradingstate.GetExRelayerFee(originOrder.ExchangeAddress, statedb) feeRate := tradingstate.GetExRelayerFee(originOrder.ExchangeAddress, statedb)
tokenCancelFee, tokenPriceInXDC := common.Big0, common.Big0 var tokenCancelFee, tokenPriceInXDC *big.Int
if !chain.Config().IsTIPXDCXCancellationFee(header.Number) { if !chain.Config().IsTIPXDCXCancellationFee(header.Number) {
tokenCancelFee = getCancelFeeV1(baseTokenDecimal, feeRate, &originOrder) tokenCancelFee = getCancelFeeV1(baseTokenDecimal, feeRate, &originOrder)
tokenPriceInXDC = common.Big0
} else { } else {
tokenCancelFee, tokenPriceInXDC = XDCx.getCancelFee(chain, statedb, tradingStateDB, &originOrder, feeRate) tokenCancelFee, tokenPriceInXDC = XDCx.getCancelFee(chain, statedb, tradingStateDB, &originOrder, feeRate)
} }
@ -721,7 +722,7 @@ func (XDCx *XDCX) ProcessCancelOrder(header *types.Header, tradingStateDB *tradi
// cancellation fee = 1/10 trading fee // cancellation fee = 1/10 trading fee
// deprecated after hardfork at TIPXDCXCancellationFee // deprecated after hardfork at TIPXDCXCancellationFee
func getCancelFeeV1(baseTokenDecimal *big.Int, feeRate *big.Int, order *tradingstate.OrderItem) *big.Int { func getCancelFeeV1(baseTokenDecimal *big.Int, feeRate *big.Int, order *tradingstate.OrderItem) *big.Int {
cancelFee := big.NewInt(0) var cancelFee *big.Int
if order.Side == tradingstate.Ask { if order.Side == tradingstate.Ask {
// SELL 1 BTC => XDC ,, // SELL 1 BTC => XDC ,,
// order.Quantity =1 && fee rate =2 // order.Quantity =1 && fee rate =2
@ -748,8 +749,7 @@ func (XDCx *XDCX) getCancelFee(chain consensus.ChainContext, statedb *state.Stat
if feeRate == nil || feeRate.Sign() == 0 { if feeRate == nil || feeRate.Sign() == 0 {
return common.Big0, common.Big0 return common.Big0, common.Big0
} }
cancelFee := big.NewInt(0) var cancelFee, tokenPriceInXDC *big.Int
tokenPriceInXDC := big.NewInt(0)
var err error var err error
if order.Side == tradingstate.Ask { if order.Side == tradingstate.Ask {
cancelFee, tokenPriceInXDC, err = XDCx.ConvertXDCToToken(chain, statedb, tradingStateDb, order.BaseToken, common.RelayerCancelFee) cancelFee, tokenPriceInXDC, err = XDCx.ConvertXDCToToken(chain, statedb, tradingStateDb, order.BaseToken, common.RelayerCancelFee)

View file

@ -311,7 +311,7 @@ func (l *Lending) SyncDataToSDKNode(chain consensus.ChainContext, statedb *state
} }
// maker dirty order // maker dirty order
makerFilledAmount := big.NewInt(0) makerFilledAmount := big.NewInt(0)
makerOrderHash := common.Hash{} var makerOrderHash common.Hash
if updatedTakerLendingItem.Side == lendingstate.Borrowing { if updatedTakerLendingItem.Side == lendingstate.Borrowing {
makerOrderHash = tradeRecord.InvestingOrderHash makerOrderHash = tradeRecord.InvestingOrderHash
} else { } else {

View file

@ -411,7 +411,7 @@ func VerifyBalance(isXDCXLendingFork bool, statedb *state.StateDB, lendingStateD
if lendTokenXDCPrice != nil && lendTokenXDCPrice.Sign() > 0 { if lendTokenXDCPrice != nil && lendTokenXDCPrice.Sign() > 0 {
defaultFee := new(big.Int).Mul(quantity, new(big.Int).SetUint64(DefaultFeeRate)) defaultFee := new(big.Int).Mul(quantity, new(big.Int).SetUint64(DefaultFeeRate))
defaultFee = new(big.Int).Div(defaultFee, common.XDCXBaseFee) defaultFee = new(big.Int).Div(defaultFee, common.XDCXBaseFee)
defaultFeeInXDC := common.Big0 var defaultFeeInXDC *big.Int
if lendingToken != common.XDCNativeAddressBinary { if lendingToken != common.XDCNativeAddressBinary {
defaultFeeInXDC = new(big.Int).Mul(defaultFee, lendTokenXDCPrice) defaultFeeInXDC = new(big.Int).Mul(defaultFee, lendTokenXDCPrice)
defaultFeeInXDC = new(big.Int).Div(defaultFeeInXDC, lendingTokenDecimal) defaultFeeInXDC = new(big.Int).Div(defaultFeeInXDC, lendingTokenDecimal)
@ -429,8 +429,7 @@ func VerifyBalance(isXDCXLendingFork bool, statedb *state.StateDB, lendingStateD
// make sure actualBalance >= cancel fee // make sure actualBalance >= cancel fee
lendingBook := GetLendingOrderBookHash(lendingToken, term) lendingBook := GetLendingOrderBookHash(lendingToken, term)
item := lendingStateDb.GetLendingOrder(lendingBook, common.BigToHash(new(big.Int).SetUint64(lendingId))) item := lendingStateDb.GetLendingOrder(lendingBook, common.BigToHash(new(big.Int).SetUint64(lendingId)))
cancelFee := big.NewInt(0) cancelFee := new(big.Int).Mul(item.Quantity, borrowingFeeRate)
cancelFee = new(big.Int).Mul(item.Quantity, borrowingFeeRate)
cancelFee = new(big.Int).Div(cancelFee, common.XDCXBaseCancelFee) cancelFee = new(big.Int).Div(cancelFee, common.XDCXBaseCancelFee)
actualBalance := GetTokenBalance(userAddress, lendingToken, statedb) actualBalance := GetTokenBalance(userAddress, lendingToken, statedb)
@ -459,9 +458,8 @@ func VerifyBalance(isXDCXLendingFork bool, statedb *state.StateDB, lendingStateD
case LendingStatusCancelled: case LendingStatusCancelled:
lendingBook := GetLendingOrderBookHash(lendingToken, term) lendingBook := GetLendingOrderBookHash(lendingToken, term)
item := lendingStateDb.GetLendingOrder(lendingBook, common.BigToHash(new(big.Int).SetUint64(lendingId))) item := lendingStateDb.GetLendingOrder(lendingBook, common.BigToHash(new(big.Int).SetUint64(lendingId)))
cancelFee := big.NewInt(0)
// Fee == quantityToLend/base lend token decimal *price*borrowFee/LendingCancelFee // Fee == quantityToLend/base lend token decimal *price*borrowFee/LendingCancelFee
cancelFee = new(big.Int).Div(item.Quantity, collateralPrice) cancelFee := new(big.Int).Div(item.Quantity, collateralPrice)
cancelFee = new(big.Int).Mul(cancelFee, borrowingFeeRate) cancelFee = new(big.Int).Mul(cancelFee, borrowingFeeRate)
cancelFee = new(big.Int).Div(cancelFee, common.XDCXBaseCancelFee) cancelFee = new(big.Int).Div(cancelFee, common.XDCXBaseCancelFee)
actualBalance := GetTokenBalance(userAddress, collateralToken, statedb) actualBalance := GetTokenBalance(userAddress, collateralToken, statedb)

View file

@ -727,9 +727,10 @@ func (l *Lending) ProcessCancelOrder(header *types.Header, lendingStateDB *lendi
} }
} }
feeRate := lendingstate.GetFee(statedb, originOrder.Relayer) feeRate := lendingstate.GetFee(statedb, originOrder.Relayer)
tokenCancelFee, tokenPriceInXDC := common.Big0, common.Big0 var tokenCancelFee, tokenPriceInXDC *big.Int
if !chain.Config().IsTIPXDCXCancellationFee(header.Number) { if !chain.Config().IsTIPXDCXCancellationFee(header.Number) {
tokenCancelFee = getCancelFeeV1(collateralTokenDecimal, collateralPrice, feeRate, &originOrder) tokenCancelFee = getCancelFeeV1(collateralTokenDecimal, collateralPrice, feeRate, &originOrder)
tokenPriceInXDC = common.Big0
} else { } else {
tokenCancelFee, tokenPriceInXDC = l.getCancelFee(chain, statedb, tradingStateDb, &originOrder, feeRate) tokenCancelFee, tokenPriceInXDC = l.getCancelFee(chain, statedb, tradingStateDb, &originOrder, feeRate)
} }
@ -927,7 +928,7 @@ func (l *Lending) LiquidationTrade(lendingStateDB *lendingstate.LendingStateDB,
// cancellation fee = 1/10 borrowing fee // cancellation fee = 1/10 borrowing fee
// deprecated after hardfork at TIPXDCXCancellationFee // deprecated after hardfork at TIPXDCXCancellationFee
func getCancelFeeV1(collateralTokenDecimal *big.Int, collateralPrice, borrowFee *big.Int, order *lendingstate.LendingItem) *big.Int { func getCancelFeeV1(collateralTokenDecimal *big.Int, collateralPrice, borrowFee *big.Int, order *lendingstate.LendingItem) *big.Int {
cancelFee := big.NewInt(0) var cancelFee *big.Int
if order.Side == lendingstate.Investing { if order.Side == lendingstate.Investing {
// cancel fee = quantityToLend*borrowFee/LendingCancelFee // cancel fee = quantityToLend*borrowFee/LendingCancelFee
cancelFee = new(big.Int).Mul(order.Quantity, borrowFee) cancelFee = new(big.Int).Mul(order.Quantity, borrowFee)
@ -947,7 +948,7 @@ func (l *Lending) getCancelFee(chain consensus.ChainContext, statedb *state.Stat
if feeRate == nil || feeRate.Sign() == 0 { if feeRate == nil || feeRate.Sign() == 0 {
return common.Big0, common.Big0 return common.Big0, common.Big0
} }
cancelFee, tokenPriceInXDC := common.Big0, common.Big0 var cancelFee, tokenPriceInXDC *big.Int
var err error var err error
if order.Side == lendingstate.Investing { if order.Side == lendingstate.Investing {
cancelFee, tokenPriceInXDC, err = l.XDCx.ConvertXDCToToken(chain, statedb, tradingStateDb, order.LendingToken, common.RelayerLendingCancelFee) cancelFee, tokenPriceInXDC, err = l.XDCx.ConvertXDCToToken(chain, statedb, tradingStateDb, order.LendingToken, common.RelayerLendingCancelFee)

View file

@ -394,7 +394,7 @@ func (self *Hasher) ReadFrom(r io.Reader) (m int64, err error) {
if err != nil { if err != nil {
break break
} }
n, err = self.Write(buf[:n]) _, err = self.Write(buf[:n])
if err != nil { if err != nil {
break break
} }

View file

@ -43,7 +43,7 @@ func airDropTokenToAccountNoXDC() {
fmt.Println("wait 10s to airdrop success ", tx.Hash().Hex()) fmt.Println("wait 10s to airdrop success ", tx.Hash().Hex())
time.Sleep(10 * time.Second) time.Sleep(10 * time.Second)
_, receiptRpc, err := client.GetTransactionReceiptResult(context.Background(), tx.Hash()) _, receiptRpc, _ := client.GetTransactionReceiptResult(context.Background(), tx.Hash())
receipt := map[string]interface{}{} receipt := map[string]interface{}{}
err = json.Unmarshal(receiptRpc, &receipt) err = json.Unmarshal(receiptRpc, &receipt)
if err != nil { if err != nil {
@ -80,8 +80,8 @@ func testTransferTRC21TokenWithAccountNoXDC() {
trc21IssuerInstance, _ := trc21issuer.NewTRC21Issuer(airDropAccount, common.TRC21IssuerSMC, client) trc21IssuerInstance, _ := trc21issuer.NewTRC21Issuer(airDropAccount, common.TRC21IssuerSMC, client)
remainFee, _ := trc21IssuerInstance.GetTokenCapacity(trc21TokenAddr) remainFee, _ := trc21IssuerInstance.GetTokenCapacity(trc21TokenAddr)
airDropBalanceBefore, err := trc21Instance.BalanceOf(simulation.AirdropAddr) airDropBalanceBefore, _ := trc21Instance.BalanceOf(simulation.AirdropAddr)
receiverBalanceBefore, err := trc21Instance.BalanceOf(simulation.ReceiverAddr) receiverBalanceBefore, _ := trc21Instance.BalanceOf(simulation.ReceiverAddr)
// execute transferAmount trc to other address // execute transferAmount trc to other address
tx, err := trc21Instance.Transfer(simulation.ReceiverAddr, simulation.TransferAmount) tx, err := trc21Instance.Transfer(simulation.ReceiverAddr, simulation.TransferAmount)
if err != nil { if err != nil {
@ -105,7 +105,7 @@ func testTransferTRC21TokenWithAccountNoXDC() {
if err != nil || balance.Cmp(remainAirDrop) != 0 { if err != nil || balance.Cmp(remainAirDrop) != 0 {
log.Fatal("check balance after fail transferAmount in tr21: ", err, "get", balance, "wanted", remainAirDrop) log.Fatal("check balance after fail transferAmount in tr21: ", err, "get", balance, "wanted", remainAirDrop)
} }
_, receiptRpc, err := client.GetTransactionReceiptResult(context.Background(), tx.Hash()) _, receiptRpc, _ := client.GetTransactionReceiptResult(context.Background(), tx.Hash())
receipt := map[string]interface{}{} receipt := map[string]interface{}{}
err = json.Unmarshal(receiptRpc, &receipt) err = json.Unmarshal(receiptRpc, &receipt)
if err != nil { if err != nil {
@ -140,15 +140,15 @@ func testTransferTrc21Fail() {
airDropAccount.GasPrice = big.NewInt(0).Mul(common.TRC21GasPrice, big.NewInt(2)) airDropAccount.GasPrice = big.NewInt(0).Mul(common.TRC21GasPrice, big.NewInt(2))
trc21Instance, _ := trc21issuer.NewTRC21(airDropAccount, trc21TokenAddr, client) trc21Instance, _ := trc21issuer.NewTRC21(airDropAccount, trc21TokenAddr, client)
trc21IssuerInstance, _ := trc21issuer.NewTRC21Issuer(airDropAccount, common.TRC21IssuerSMC, client) trc21IssuerInstance, _ := trc21issuer.NewTRC21Issuer(airDropAccount, common.TRC21IssuerSMC, client)
balanceIssuerFee, err := trc21IssuerInstance.GetTokenCapacity(trc21TokenAddr) balanceIssuerFee, _ := trc21IssuerInstance.GetTokenCapacity(trc21TokenAddr)
minFee, err := trc21Instance.MinFee() minFee, err := trc21Instance.MinFee()
if err != nil { if err != nil {
log.Fatal("can't get minFee of trc21 smart contract:", err) log.Fatal("can't get minFee of trc21 smart contract:", err)
} }
ownerBalance, err := trc21Instance.BalanceOf(simulation.MainAddr) ownerBalance, _ := trc21Instance.BalanceOf(simulation.MainAddr)
remainFee, err := trc21IssuerInstance.GetTokenCapacity(trc21TokenAddr) remainFee, _ := trc21IssuerInstance.GetTokenCapacity(trc21TokenAddr)
airDropBalanceBefore, err := trc21Instance.BalanceOf(simulation.AirdropAddr) airDropBalanceBefore, _ := trc21Instance.BalanceOf(simulation.AirdropAddr)
tx, err := trc21Instance.Transfer(common.Address{}, big.NewInt(1)) tx, err := trc21Instance.Transfer(common.Address{}, big.NewInt(1))
if err != nil { if err != nil {
@ -171,7 +171,7 @@ func testTransferTrc21Fail() {
if err != nil || balance.Cmp(ownerBalance) != 0 { if err != nil || balance.Cmp(ownerBalance) != 0 {
log.Fatal("can't get balance token fee in smart contract: ", err, "got", balanceIssuerFee, "wanted", remainFee) log.Fatal("can't get balance token fee in smart contract: ", err, "got", balanceIssuerFee, "wanted", remainFee)
} }
_, receiptRpc, err := client.GetTransactionReceiptResult(context.Background(), tx.Hash()) _, receiptRpc, _ := client.GetTransactionReceiptResult(context.Background(), tx.Hash())
receipt := map[string]interface{}{} receipt := map[string]interface{}{}
err = json.Unmarshal(receiptRpc, &receipt) err = json.Unmarshal(receiptRpc, &receipt)
if err != nil { if err != nil {

View file

@ -1271,8 +1271,6 @@ func (bc *BlockChain) WriteBlockWithState(block *types.Block, receipts []*types.
if current := block.NumberU64(); current > triesInMemory { if current := block.NumberU64(); current > triesInMemory {
// Find the next state trie we need to commit // Find the next state trie we need to commit
chosen := current - triesInMemory chosen := current - triesInMemory
oldTradingRoot := common.Hash{}
oldLendingRoot := common.Hash{}
// Only write to disk if we exceeded our memory allowance *and* also have at // Only write to disk if we exceeded our memory allowance *and* also have at
// least a given number of tries gapped. // least a given number of tries gapped.
// //
@ -1308,8 +1306,8 @@ func (bc *BlockChain) WriteBlockWithState(block *types.Block, receipts []*types.
if tradingTrieDb != nil && lendingTrieDb != nil { if tradingTrieDb != nil && lendingTrieDb != nil {
b := bc.GetBlock(header.Hash(), current-triesInMemory) b := bc.GetBlock(header.Hash(), current-triesInMemory)
author, _ := bc.Engine().Author(b.Header()) author, _ := bc.Engine().Author(b.Header())
oldTradingRoot, _ = tradingService.GetTradingStateRoot(b, author) oldTradingRoot, _ := tradingService.GetTradingStateRoot(b, author)
oldLendingRoot, _ = lendingService.GetLendingStateRoot(b, author) oldLendingRoot, _ := lendingService.GetLendingStateRoot(b, author)
tradingTrieDb.Commit(oldTradingRoot, true) tradingTrieDb.Commit(oldTradingRoot, true)
lendingTrieDb.Commit(oldLendingRoot, true) lendingTrieDb.Commit(oldLendingRoot, true)
} }
@ -1647,8 +1645,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, []
} }
// liquidate / finalize open lendingTrades // liquidate / finalize open lendingTrades
if block.Number().Uint64()%bc.chainConfig.XDPoS.Epoch == common.LiquidateLendingTradeBlock { if block.Number().Uint64()%bc.chainConfig.XDPoS.Epoch == common.LiquidateLendingTradeBlock {
finalizedTrades := map[common.Hash]*lendingstate.LendingTrade{} finalizedTrades, _, _, _, _, err := lendingService.ProcessLiquidationData(block.Header(), bc, statedb, tradingState, lendingState)
finalizedTrades, _, _, _, _, err = lendingService.ProcessLiquidationData(block.Header(), bc, statedb, tradingState, lendingState)
if err != nil { if err != nil {
return i, events, coalescedLogs, fmt.Errorf("failed to ProcessLiquidationData. Err: %v ", err) return i, events, coalescedLogs, fmt.Errorf("failed to ProcessLiquidationData. Err: %v ", err)
} }

View file

@ -527,7 +527,7 @@ func testInsertNonceError(t *testing.T, full bool) {
blockchain.engine = ethash.NewFakeFailer(failNum) blockchain.engine = ethash.NewFakeFailer(failNum)
blockchain.hc.engine = blockchain.engine blockchain.hc.engine = blockchain.engine
failRes, err = blockchain.InsertHeaderChain(headers, 1) failRes, _ = blockchain.InsertHeaderChain(headers, 1)
// Check that the returned error indicates the failure. // Check that the returned error indicates the failure.
if failRes != failAt { if failRes != failAt {
t.Errorf("test %d: failure index mismatch: have %d, want %d", i, failRes, failAt) t.Errorf("test %d: failure index mismatch: have %d, want %d", i, failRes, failAt)

View file

@ -58,7 +58,7 @@ func getLendingNonce(userAddress common.Address) (uint64, error) {
s := result.(string) s := result.(string)
s = strings.TrimPrefix(s, "0x") s = strings.TrimPrefix(s, "0x")
n, err := strconv.ParseUint(s, 16, 32) n, err := strconv.ParseUint(s, 16, 32)
return uint64(n), nil return uint64(n), err
} }
func (l *LendingMsg) computeHash() common.Hash { func (l *LendingMsg) computeHash() common.Hash {

View file

@ -49,7 +49,6 @@ var (
EOSAddress = common.HexToAddress("0xd9bb01454c85247B2ef35BB5BE57384cC275a8cf") EOSAddress = common.HexToAddress("0xd9bb01454c85247B2ef35BB5BE57384cC275a8cf")
USDAddress = common.HexToAddress("0x45c25041b8e6CBD5c963E7943007187C3673C7c9") USDAddress = common.HexToAddress("0x45c25041b8e6CBD5c963E7943007187C3673C7c9")
_1E18 = new(big.Int).Mul(big.NewInt(10000000000000000), big.NewInt(100)) _1E18 = new(big.Int).Mul(big.NewInt(10000000000000000), big.NewInt(100))
_1E17 = new(big.Int).Mul(big.NewInt(10000000000000000), big.NewInt(10))
_1E8 = big.NewInt(100000000) _1E8 = big.NewInt(100000000)
_1E7 = big.NewInt(10000000) _1E7 = big.NewInt(10000000)
) )
@ -72,7 +71,7 @@ func getNonce(t *testing.T, userAddress common.Address) (uint64, error) {
s := result.(string) s := result.(string)
s = strings.TrimPrefix(s, "0x") s = strings.TrimPrefix(s, "0x")
n, err := strconv.ParseUint(s, 16, 32) n, err := strconv.ParseUint(s, 16, 32)
return uint64(n), nil return uint64(n), err
} }
func testSendOrder(t *testing.T, amount, price *big.Int, side string, status string, orderID uint64) { func testSendOrder(t *testing.T, amount, price *big.Int, side string, status string, orderID uint64) {

View file

@ -608,8 +608,6 @@ Delta is a helper function that is used in the range proof
*/ */
func Delta(y []*big.Int, z *big.Int) *big.Int { func Delta(y []*big.Int, z *big.Int) *big.Int {
result := big.NewInt(0)
// (z-z^2)<1^n, y^n> // (z-z^2)<1^n, y^n>
z2 := new(big.Int).Mod(new(big.Int).Mul(z, z), EC.N) z2 := new(big.Int).Mod(new(big.Int).Mul(z, z), EC.N)
t1 := new(big.Int).Mod(new(big.Int).Sub(z, z2), EC.N) t1 := new(big.Int).Mod(new(big.Int).Sub(z, z2), EC.N)
@ -620,21 +618,14 @@ func Delta(y []*big.Int, z *big.Int) *big.Int {
po2sum := new(big.Int).Sub(new(big.Int).Exp(big.NewInt(2), big.NewInt(int64(EC.V)), EC.N), big.NewInt(1)) po2sum := new(big.Int).Sub(new(big.Int).Exp(big.NewInt(2), big.NewInt(int64(EC.V)), EC.N), big.NewInt(1))
t3 := new(big.Int).Mod(new(big.Int).Mul(z3, po2sum), EC.N) t3 := new(big.Int).Mod(new(big.Int).Mul(z3, po2sum), EC.N)
result = new(big.Int).Mod(new(big.Int).Sub(t2, t3), EC.N) return new(big.Int).Mod(new(big.Int).Sub(t2, t3), EC.N)
return result
} }
// Calculates (aL - z*1^n) + sL*x // Calculates (aL - z*1^n) + sL*x
func CalculateL(aL, sL []*big.Int, z, x *big.Int) []*big.Int { func CalculateL(aL, sL []*big.Int, z, x *big.Int) []*big.Int {
result := make([]*big.Int, len(aL))
tmp1 := VectorAddScalar(aL, new(big.Int).Neg(z)) tmp1 := VectorAddScalar(aL, new(big.Int).Neg(z))
tmp2 := ScalarVectorMul(sL, x) tmp2 := ScalarVectorMul(sL, x)
return VectorAdd(tmp1, tmp2)
result = VectorAdd(tmp1, tmp2)
return result
} }
func CalculateR(aR, sR, y, po2 []*big.Int, z, x *big.Int) []*big.Int { func CalculateR(aR, sR, y, po2 []*big.Int, z, x *big.Int) []*big.Int {
@ -642,29 +633,20 @@ func CalculateR(aR, sR, y, po2 []*big.Int, z, x *big.Int) []*big.Int {
log.Info("CalculateR: Arrays not of the same length") log.Info("CalculateR: Arrays not of the same length")
} }
result := make([]*big.Int, len(aR))
z2 := new(big.Int).Exp(z, big.NewInt(2), EC.N) z2 := new(big.Int).Exp(z, big.NewInt(2), EC.N)
tmp11 := VectorAddScalar(aR, z) tmp11 := VectorAddScalar(aR, z)
tmp12 := ScalarVectorMul(sR, x) tmp12 := ScalarVectorMul(sR, x)
tmp1 := VectorHadamard(y, VectorAdd(tmp11, tmp12)) tmp1 := VectorHadamard(y, VectorAdd(tmp11, tmp12))
tmp2 := ScalarVectorMul(po2, z2) tmp2 := ScalarVectorMul(po2, z2)
result = VectorAdd(tmp1, tmp2) return VectorAdd(tmp1, tmp2)
return result
} }
// Calculates (aL - z*1^n) + sL*x // Calculates (aL - z*1^n) + sL*x
func CalculateLMRP(aL, sL []*big.Int, z, x *big.Int) []*big.Int { func CalculateLMRP(aL, sL []*big.Int, z, x *big.Int) []*big.Int {
result := make([]*big.Int, len(aL))
tmp1 := VectorAddScalar(aL, new(big.Int).Neg(z)) tmp1 := VectorAddScalar(aL, new(big.Int).Neg(z))
tmp2 := ScalarVectorMul(sL, x) tmp2 := ScalarVectorMul(sL, x)
return VectorAdd(tmp1, tmp2)
result = VectorAdd(tmp1, tmp2)
return result
} }
func CalculateRMRP(aR, sR, y, zTimesTwo []*big.Int, z, x *big.Int) []*big.Int { func CalculateRMRP(aR, sR, y, zTimesTwo []*big.Int, z, x *big.Int) []*big.Int {
@ -672,15 +654,11 @@ func CalculateRMRP(aR, sR, y, zTimesTwo []*big.Int, z, x *big.Int) []*big.Int {
log.Info("CalculateRMRP: Arrays not of the same length") log.Info("CalculateRMRP: Arrays not of the same length")
} }
result := make([]*big.Int, len(aR))
tmp11 := VectorAddScalar(aR, z) tmp11 := VectorAddScalar(aR, z)
tmp12 := ScalarVectorMul(sR, x) tmp12 := ScalarVectorMul(sR, x)
tmp1 := VectorHadamard(y, VectorAdd(tmp11, tmp12)) tmp1 := VectorHadamard(y, VectorAdd(tmp11, tmp12))
result = VectorAdd(tmp1, zTimesTwo) return VectorAdd(tmp1, zTimesTwo)
return result
} }
/* /*
@ -689,8 +667,6 @@ DeltaMRP is a helper function that is used in the multi range proof
*/ */
func DeltaMRP(y []*big.Int, z *big.Int, m int) *big.Int { func DeltaMRP(y []*big.Int, z *big.Int, m int) *big.Int {
result := big.NewInt(0)
// (z-z^2)<1^n, y^n> // (z-z^2)<1^n, y^n>
z2 := new(big.Int).Mod(new(big.Int).Mul(z, z), EC.N) z2 := new(big.Int).Mod(new(big.Int).Mul(z, z), EC.N)
t1 := new(big.Int).Mod(new(big.Int).Sub(z, z2), EC.N) t1 := new(big.Int).Mod(new(big.Int).Sub(z, z2), EC.N)
@ -709,9 +685,7 @@ func DeltaMRP(y []*big.Int, z *big.Int, m int) *big.Int {
t3 = new(big.Int).Mod(new(big.Int).Add(t3, tmp1), EC.N) t3 = new(big.Int).Mod(new(big.Int).Add(t3, tmp1), EC.N)
} }
result = new(big.Int).Mod(new(big.Int).Sub(t2, t3), EC.N) return new(big.Int).Mod(new(big.Int).Sub(t2, t3), EC.N)
return result
} }
type MultiRangeProof struct { type MultiRangeProof struct {

View file

@ -21,7 +21,7 @@ func TestSign(t *testing.T) {
ringSize := 10 ringSize := 10
s := 9 s := 9
fmt.Println("Generate random ring parameter ") fmt.Println("Generate random ring parameter ")
rings, privkeys, m, err := GenerateMultiRingParams(numRing, ringSize, s) rings, privkeys, m, _ := GenerateMultiRingParams(numRing, ringSize, s)
fmt.Println("numRing ", numRing) fmt.Println("numRing ", numRing)
fmt.Println("ringSize ", ringSize) fmt.Println("ringSize ", ringSize)
@ -57,7 +57,7 @@ func TestDeserialize(t *testing.T) {
numRing := 5 numRing := 5
ringSize := 10 ringSize := 10
s := 5 s := 5
rings, privkeys, m, err := GenerateMultiRingParams(numRing, ringSize, s) rings, privkeys, m, _ := GenerateMultiRingParams(numRing, ringSize, s)
ringSignature, err := Sign(m, rings, privkeys, s) ringSignature, err := Sign(m, rings, privkeys, s)
if err != nil { if err != nil {
@ -235,7 +235,7 @@ func TestOnCurveVerify(t *testing.T) {
numRing := 5 numRing := 5
ringSize := 10 ringSize := 10
s := 5 s := 5
rings, privkeys, m, err := GenerateMultiRingParams(numRing, ringSize, s) rings, privkeys, m, _ := GenerateMultiRingParams(numRing, ringSize, s)
ringSignature, err := Sign(m, rings, privkeys, s) ringSignature, err := Sign(m, rings, privkeys, s)
if err != nil { if err != nil {
t.Error("Failed to create Ring signature") t.Error("Failed to create Ring signature")
@ -259,7 +259,7 @@ func TestOnCurveDeserialize(t *testing.T) {
numRing := 5 numRing := 5
ringSize := 10 ringSize := 10
s := 5 s := 5
rings, privkeys, m, err := GenerateMultiRingParams(numRing, ringSize, s) rings, privkeys, m, _ := GenerateMultiRingParams(numRing, ringSize, s)
ringSignature, err := Sign(m, rings, privkeys, s) ringSignature, err := Sign(m, rings, privkeys, s)
if err != nil { if err != nil {
t.Error("Failed to create Ring signature") t.Error("Failed to create Ring signature")
@ -304,7 +304,7 @@ func TestNilPointerDereferencePanic(t *testing.T) {
numRing := 5 numRing := 5
ringSize := 10 ringSize := 10
s := 7 s := 7
rings, privkeys, m, err := GenerateMultiRingParams(numRing, ringSize, s) rings, privkeys, m, _ := GenerateMultiRingParams(numRing, ringSize, s)
ringSig, err := Sign(m, rings, privkeys, s) ringSig, err := Sign(m, rings, privkeys, s)
if err != nil { if err != nil {
@ -318,7 +318,7 @@ func TestNilPointerDereferencePanic(t *testing.T) {
t.Error("Failed to Serialize input Ring signature") t.Error("Failed to Serialize input Ring signature")
} }
_ , err = Deserialize(sig) _, err = Deserialize(sig)
// Should failed to verify Ring signature as the signature is invalid // Should failed to verify Ring signature as the signature is invalid
assert.EqualError(t, err, "failed to deserialize, invalid ring signature") assert.EqualError(t, err, "failed to deserialize, invalid ring signature")
} }

View file

@ -199,9 +199,8 @@ func miller(q *twistPoint, p *curvePoint) *gfP12 {
r = newR r = newR
r2.Square(&minusQ2.y) r2.Square(&minusQ2.y)
a, b, c, newR = lineFunctionAdd(r, minusQ2, bAffine, r2) a, b, c, _ = lineFunctionAdd(r, minusQ2, bAffine, r2)
mulLine(ret, a, b, c) mulLine(ret, a, b, c)
r = newR
return ret return ret
} }

View file

@ -270,7 +270,7 @@ func TestChildPrefixedRegistryOfChildRegister(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err.Error()) t.Fatal(err.Error())
} }
err = r2.Register("baz", NewCounter()) r2.Register("baz", NewCounter())
c := NewCounter() c := NewCounter()
Register("bars", c) Register("bars", c)
@ -293,7 +293,7 @@ func TestWalkRegistries(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err.Error()) t.Fatal(err.Error())
} }
err = r2.Register("baz", NewCounter()) r2.Register("baz", NewCounter())
c := NewCounter() c := NewCounter()
Register("bars", c) Register("bars", c)

View file

@ -169,7 +169,7 @@ func singleRequest(t *testing.T, server *WMailServer, env *whisper.Envelope, p *
} }
src[0]++ src[0]++
ok, lower, upper, bloom = server.validateRequest(src, request) ok, lower, upper, _ = server.validateRequest(src, request)
if !ok { if !ok {
// request should be valid regardless of signature // request should be valid regardless of signature
t.Fatalf("request validation false negative, seed: %d (lower: %d, upper: %d).", seed, lower, upper) t.Fatalf("request validation false negative, seed: %d (lower: %d, upper: %d).", seed, lower, upper)

View file

@ -309,7 +309,7 @@ func TestMatchEnvelope(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("failed to create new message with seed %d: %s.", seed, err) t.Fatalf("failed to create new message with seed %d: %s.", seed, err)
} }
env, err := msg.Wrap(params) _, err = msg.Wrap(params)
if err != nil { if err != nil {
t.Fatalf("failed Wrap with seed %d: %s.", seed, err) t.Fatalf("failed Wrap with seed %d: %s.", seed, err)
} }
@ -322,7 +322,7 @@ func TestMatchEnvelope(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("failed to create new message with seed %d: %s.", seed, err) t.Fatalf("failed to create new message with seed %d: %s.", seed, err)
} }
env, err = msg.Wrap(params) env, err := msg.Wrap(params)
if err != nil { if err != nil {
t.Fatalf("failed Wrap() with seed %d: %s.", seed, err) t.Fatalf("failed Wrap() with seed %d: %s.", seed, err)
} }