chore: return statement optimization (#406)

This commit is contained in:
Banana-J 2024-01-28 16:58:41 +11:00 committed by GitHub
parent a3c392cdde
commit 743fc8500b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 29 additions and 60 deletions

View file

@ -588,17 +588,16 @@ func (XDCX *XDCX) GetEmptyTradingState() (*tradingstate.TradingStateDB, error) {
func (XDCx *XDCX) GetStateCache() tradingstate.Database {
return XDCx.StateCache
}
func (XDCx *XDCX) HasTradingState(block *types.Block, author common.Address) bool {
root, err := XDCx.GetTradingStateRoot(block, author)
if err != nil {
return false
}
_, err = XDCx.StateCache.OpenTrie(root)
if err != nil {
return false
}
return true
return err == nil
}
func (XDCx *XDCX) GetTriegc() *prque.Prque {
return XDCx.Triegc
}

View file

@ -41,10 +41,7 @@ func IsResignedRelayer(relayer common.Address, statedb *state.StateDB) bool {
slot := RelayerMappingSlot["RESIGN_REQUESTS"]
locBig := GetLocMappingAtKey(relayer.Hash(), slot)
locHash := common.BigToHash(locBig)
if statedb.GetState(common.HexToAddress(common.RelayerRegistrationSMC), locHash) != (common.Hash{}) {
return true
}
return false
return statedb.GetState(common.HexToAddress(common.RelayerRegistrationSMC), locHash) != (common.Hash{})
}
func GetBaseTokenLength(relayer common.Address, statedb *state.StateDB) uint64 {

View file

@ -32,7 +32,6 @@ import (
var (
// ErrInvalidLengdingSig invalidate signer
ErrInvalidLengdingSig = errors.New("invalid transaction v, r, s values")
errNoSignerLengding = errors.New("missing signing methods")
)
const (
@ -86,50 +85,32 @@ type lendingtxdata struct {
// IsCreatedLending check if tx is cancelled transaction
func (tx *LendingTransaction) IsCreatedLending() bool {
if (tx.IsLoTypeLending() || tx.IsMoTypeLending()) && tx.Status() == LendingStatusNew {
return true
}
return false
return (tx.IsLoTypeLending() || tx.IsMoTypeLending()) && tx.Status() == LendingStatusNew
}
// IsCancelledLending check if tx is cancelled transaction
func (tx *LendingTransaction) IsCancelledLending() bool {
if tx.Status() == LendingStatusCancelled {
return true
}
return false
return tx.Status() == LendingStatusCancelled
}
// IsRepayLending check if tx is repay lending transaction
func (tx *LendingTransaction) IsRepayLending() bool {
if tx.Type() == LendingRePay {
return true
}
return false
return tx.Type() == LendingRePay
}
// IsTopupLending check if tx is repay lending transaction
func (tx *LendingTransaction) IsTopupLending() bool {
if tx.Type() == LendingTopup {
return true
}
return false
return tx.Type() == LendingTopup
}
// IsMoTypeLending check if tx type is MO lending
func (tx *LendingTransaction) IsMoTypeLending() bool {
if tx.Type() == LendingTypeMo {
return true
}
return false
return tx.Type() == LendingTypeMo
}
// IsLoTypeLending check if tx type is LO lending
func (tx *LendingTransaction) IsLoTypeLending() bool {
if tx.Type() == LendingTypeLo {
return true
}
return false
return tx.Type() == LendingTypeLo
}
// EncodeRLP implements rlp.Encoder
@ -363,7 +344,7 @@ func (s *LendingTxByNonce) Pop() interface{} {
return x
}
//LendingTransactionByNonce sort transaction by nonce
// LendingTransactionByNonce sort transaction by nonce
type LendingTransactionByNonce struct {
txs map[common.Address]LendingTransactions
heads LendingTxByNonce

View file

@ -32,7 +32,6 @@ import (
var (
// ErrInvalidOrderSig invalidate signer
ErrInvalidOrderSig = errors.New("invalid transaction v, r, s values")
errNoSignerOrder = errors.New("missing signing methods")
)
const (
@ -77,26 +76,17 @@ type ordertxdata struct {
// IsCancelledOrder check if tx is cancelled transaction
func (tx *OrderTransaction) IsCancelledOrder() bool {
if tx.Status() == OrderStatusCancelled {
return true
}
return false
return tx.Status() == OrderStatusCancelled
}
// IsMoTypeOrder check if tx type is MO Order
func (tx *OrderTransaction) IsMoTypeOrder() bool {
if tx.Type() == OrderTypeMo {
return true
}
return false
return tx.Type() == OrderTypeMo
}
// IsLoTypeOrder check if tx type is LO Order
func (tx *OrderTransaction) IsLoTypeOrder() bool {
if tx.Type() == OrderTypeLo {
return true
}
return false
return tx.Type() == OrderTypeLo
}
// EncodeRLP implements rlp.Encoder
@ -166,7 +156,6 @@ func (tx *OrderTransaction) WithSignature(signer OrderSigner, sig []byte) (*Orde
// ImportSignature make order tx with specific signature
func (tx *OrderTransaction) ImportSignature(V, R, S *big.Int) *OrderTransaction {
if V != nil {
tx.data.V = V
}

View file

@ -274,7 +274,9 @@ func GenerateNewParams(G, H []ECPoint, x *big.Int, L, R, P ECPoint) ([]ECPoint,
return Gprime, Hprime, Pprime
}
/* Inner Product Argument
/*
Inner Product Argument
Proves that <a,b>=c
This is a building block for BulletProofs
*/
@ -323,7 +325,7 @@ func InnerProductProveSub(proof InnerProdArg, G, H []ECPoint, a []*big.Int, b []
return InnerProductProveSub(proof, Gprime, Hprime, aprime, bprime, u, Pprime)
}
//rpresult.IPP = InnerProductProve(left, right, that, P, EC.U, EC.BPG, HPrime)
// rpresult.IPP = InnerProductProve(left, right, that, P, EC.U, EC.BPG, HPrime)
func InnerProductProve(a []*big.Int, b []*big.Int, c *big.Int, P, U ECPoint, G, H []ECPoint) InnerProdArg {
loglen := int(math.Log2(float64(len(a))))
@ -353,7 +355,9 @@ func InnerProductProve(a []*big.Int, b []*big.Int, c *big.Int, P, U ECPoint, G,
return InnerProductProveSub(runningProof, G, H, a, b, ux, Pprime)
}
/* Inner Product Verify
/*
Inner Product Verify
Given a inner product proof, verifies the correctness of the proof
Since we're using the Fiat-Shamir transform, we need to verify all x hash computations,
all g' and h' computations
@ -416,11 +420,7 @@ func InnerProductVerify(c *big.Int, P, U ECPoint, G, H []ECPoint, ipp InnerProdA
Pcalc3 := ux.Mult(ccalc)
Pcalc := Pcalc1.Add(Pcalc2).Add(Pcalc3)
if !Pprime.Equal(Pcalc) {
return false
}
return true
return Pprime.Equal(Pcalc)
}
/* Inner Product Verify Fast
@ -961,11 +961,14 @@ MultiRangeProof Prove
Takes in a list of values and provides an aggregate
range proof for all the values.
changes:
all values are concatenated
r(x) is computed differently
tau_x calculation is different
delta calculation is different
all values are concatenated
r(x) is computed differently
tau_x calculation is different
delta calculation is different
{(g, h \in G, \textbf{V} \in G^m ; \textbf{v, \gamma} \in Z_p^m) :
V_j = h^{\gamma_j}g^{v_j} \wedge v_j \in [0, 2^n - 1] \forall j \in [1, m]}
*/
var bitsPerValue = 64