From 5631405d2902108423a8c94ac8c4db995b29383a Mon Sep 17 00:00:00 2001 From: radu chis Date: Tue, 5 Sep 2023 16:59:13 +0300 Subject: [PATCH 1/5] SF-v1.6.0 initial test --- consensus/spos/bls/constants.go | 4 +-- consensus/spos/consensusMessageValidator.go | 18 ---------- factory/crypto/cryptoComponents.go | 33 +++---------------- keysManagement/managedPeersHolder.go | 14 ++------ node/node.go | 4 +-- process/block/headerValidator.go | 9 ----- .../interceptedPeerAuthentication.go | 17 ---------- process/transaction/baseProcess.go | 6 ++++ 8 files changed, 18 insertions(+), 87 deletions(-) diff --git a/consensus/spos/bls/constants.go b/consensus/spos/bls/constants.go index 166abe70b65..afab1721a2a 100644 --- a/consensus/spos/bls/constants.go +++ b/consensus/spos/bls/constants.go @@ -52,10 +52,10 @@ const srStartEndTime = 0.05 const srBlockStartTime = 0.05 // srBlockEndTime specifies the end time, from the total time of the round, of Subround Block -const srBlockEndTime = 0.25 +const srBlockEndTime = 0.45 // srSignatureStartTime specifies the start time, from the total time of the round, of Subround Signature -const srSignatureStartTime = 0.25 +const srSignatureStartTime = 0.45 // srSignatureEndTime specifies the end time, from the total time of the round, of Subround Signature const srSignatureEndTime = 0.85 diff --git a/consensus/spos/consensusMessageValidator.go b/consensus/spos/consensusMessageValidator.go index 67fa9616e07..2d49c59792a 100644 --- a/consensus/spos/consensusMessageValidator.go +++ b/consensus/spos/consensusMessageValidator.go @@ -122,12 +122,6 @@ func (cmv *consensusMessageValidator) checkConsensusMessageValidity(cnsMsg *cons len(cnsMsg.PubKey)) } - if len(cnsMsg.Signature) != cmv.signatureSize { - return fmt.Errorf("%w : received signature from consensus topic has an invalid size: %d", - ErrInvalidSignatureSize, - len(cnsMsg.Signature)) - } - isNodeInEligibleList := cmv.consensusState.IsNodeInEligibleList(string(cnsMsg.PubKey)) if !isNodeInEligibleList { return fmt.Errorf("%w : received message from consensus topic has an invalid public key: %s", @@ -392,18 +386,6 @@ func (cmv *consensusMessageValidator) checkMessageWithFinalInfoValidity(cnsMsg * len(cnsMsg.PubKeysBitmap)) } - if len(cnsMsg.AggregateSignature) != cmv.signatureSize { - return fmt.Errorf("%w : received aggregate signature from consensus topic has an invalid size: %d", - ErrInvalidSignatureSize, - len(cnsMsg.AggregateSignature)) - } - - if len(cnsMsg.LeaderSignature) != cmv.signatureSize { - return fmt.Errorf("%w : received leader signature from consensus topic has an invalid size: %d", - ErrInvalidSignatureSize, - len(cnsMsg.LeaderSignature)) - } - return nil } diff --git a/factory/crypto/cryptoComponents.go b/factory/crypto/cryptoComponents.go index 153f5486bd4..c8c01974269 100644 --- a/factory/crypto/cryptoComponents.go +++ b/factory/crypto/cryptoComponents.go @@ -158,19 +158,20 @@ func (ccf *cryptoComponentsFactory) Create() (*cryptoComponents, error) { txSignKeyGen := signing.NewKeyGenerator(ed25519.NewEd25519()) txSingleSigner := &singlesig.Ed25519Signer{} - processingSingleSigner, err := ccf.createSingleSigner(false) + + processingSingleSigner, err := ccf.createSingleSigner(true) if err != nil { return nil, err } - interceptSingleSigner, err := ccf.createSingleSigner(ccf.importModeNoSigCheck) + interceptSingleSigner, err := ccf.createSingleSigner(true) if err != nil { return nil, err } p2pSingleSigner := &secp256k1SinglerSig.Secp256k1Signer{} - multiSigner, err := ccf.createMultiSignerContainer(blockSignKeyGen, ccf.importModeNoSigCheck) + multiSigner, err := ccf.createMultiSignerContainer(blockSignKeyGen, true) if err != nil { return nil, err } @@ -489,36 +490,12 @@ func (ccf *cryptoComponentsFactory) processAllHandledKeys(keygen crypto.KeyGener return handledPrivateKeys, nil } -func (ccf *cryptoComponentsFactory) processPrivatePublicKey(keygen crypto.KeyGenerator, encodedSk []byte, pkString string, index int) ([]byte, error) { +func (ccf *cryptoComponentsFactory) processPrivatePublicKey(_ crypto.KeyGenerator, encodedSk []byte, _ string, index int) ([]byte, error) { skBytes, err := hex.DecodeString(string(encodedSk)) if err != nil { return nil, fmt.Errorf("%w for encoded secret key, key index %d", err, index) } - pkBytes, err := ccf.validatorPubKeyConverter.Decode(pkString) - if err != nil { - return nil, fmt.Errorf("%w for encoded public key %s, key index %d", err, pkString, index) - } - - sk, err := keygen.PrivateKeyFromByteArray(skBytes) - if err != nil { - return nil, fmt.Errorf("%w secret key, key index %d", err, index) - } - - pk := sk.GeneratePublic() - pkGeneratedBytes, err := pk.ToByteArray() - if err != nil { - return nil, fmt.Errorf("%w while generating public key bytes, key index %d", err, index) - } - - if !bytes.Equal(pkGeneratedBytes, pkBytes) { - return nil, fmt.Errorf("public keys mismatch, read %s, generated %s, key index %d", - pkString, - ccf.validatorPubKeyConverter.SilentEncode(pkBytes, log), - index, - ) - } - return skBytes, nil } diff --git a/keysManagement/managedPeersHolder.go b/keysManagement/managedPeersHolder.go index 0cc7ea8c9e6..1e37df14cdf 100644 --- a/keysManagement/managedPeersHolder.go +++ b/keysManagement/managedPeersHolder.go @@ -113,16 +113,8 @@ func createDataMap(namedIdentities []config.NamedIdentity) (map[string]*peerInfo // It errors if the generated public key is already contained by the struct // It will auto-generate some fields like the machineID and pid func (holder *managedPeersHolder) AddManagedPeer(privateKeyBytes []byte) error { - privateKey, err := holder.keyGenerator.PrivateKeyFromByteArray(privateKeyBytes) - if err != nil { - return fmt.Errorf("%w for provided bytes %s", err, hex.EncodeToString(privateKeyBytes)) - } - - publicKey := privateKey.GeneratePublic() - publicKeyBytes, err := publicKey.ToByteArray() - if err != nil { - return fmt.Errorf("%w for provided bytes %s", err, hex.EncodeToString(privateKeyBytes)) - } + sk, _ := holder.keyGenerator.GeneratePair() + publicKeyBytes := privateKeyBytes p2pPrivateKey, p2pPublicKey := holder.p2pKeyGenerator.GeneratePair() @@ -155,7 +147,7 @@ func (holder *managedPeersHolder) AddManagedPeer(privateKeyBytes []byte) error { pInfo.pid = pid pInfo.p2pPrivateKeyBytes = p2pPrivateKeyBytes - pInfo.privateKey = privateKey + pInfo.privateKey = sk holder.data[string(publicKeyBytes)] = pInfo holder.pids[pid] = struct{}{} diff --git a/node/node.go b/node/node.go index e02f84be2cb..12f6e9085ee 100644 --- a/node/node.go +++ b/node/node.go @@ -54,7 +54,7 @@ var log = logger.GetOrCreate("node") var _ facade.NodeHandler = (*Node)(nil) // Option represents a functional configuration parameter that can operate -// over the None struct. +// over the None struct. type Option func(*Node) error type filter interface { @@ -700,7 +700,7 @@ func (n *Node) ValidateTransaction(tx *transaction.Transaction) error { return err } - txValidator, intTx, err := n.commonTransactionValidation(tx, n.processComponents.WhiteListerVerifiedTxs(), n.processComponents.WhiteListHandler(), true) + txValidator, intTx, err := n.commonTransactionValidation(tx, n.processComponents.WhiteListerVerifiedTxs(), n.processComponents.WhiteListHandler(), false) if err != nil { return err } diff --git a/process/block/headerValidator.go b/process/block/headerValidator.go index b39787c7a96..67499767b83 100644 --- a/process/block/headerValidator.go +++ b/process/block/headerValidator.go @@ -78,15 +78,6 @@ func (h *headerValidator) IsHeaderConstructionValid(currHeader, prevHeader data. return process.ErrBlockHashDoesNotMatch } - if !bytes.Equal(currHeader.GetPrevRandSeed(), prevHeader.GetRandSeed()) { - log.Trace("header random seed does not match", - "shard", currHeader.GetShardID(), - "local header random seed", prevHeader.GetRandSeed(), - "received header with prev random seed", currHeader.GetPrevRandSeed(), - ) - return process.ErrRandSeedDoesNotMatch - } - return nil } diff --git a/process/heartbeat/interceptedPeerAuthentication.go b/process/heartbeat/interceptedPeerAuthentication.go index a10e5e6dd8d..48cccdc3e11 100644 --- a/process/heartbeat/interceptedPeerAuthentication.go +++ b/process/heartbeat/interceptedPeerAuthentication.go @@ -136,23 +136,6 @@ func (ipa *interceptedPeerAuthentication) CheckValidity() error { } // Verify payload signature - err = ipa.signaturesHandler.Verify(ipa.peerAuthentication.Payload, ipa.peerId, ipa.peerAuthentication.PayloadSignature) - if err != nil { - return err - } - - // Verify payload - err = ipa.payloadValidator.ValidateTimestamp(ipa.payload.Timestamp) - if err != nil { - return err - } - - // Verify message bls signature - err = ipa.peerSignatureHandler.VerifyPeerSignature(ipa.peerAuthentication.Pubkey, ipa.peerId, ipa.peerAuthentication.Signature) - if err != nil { - return err - } - log.Trace("interceptedPeerAuthentication received valid data") return nil diff --git a/process/transaction/baseProcess.go b/process/transaction/baseProcess.go index 7f2fe6d4b16..176e9abbb3c 100644 --- a/process/transaction/baseProcess.go +++ b/process/transaction/baseProcess.go @@ -267,6 +267,12 @@ func (txProc *baseTxProcessor) verifyGuardian(tx *transaction.Transaction, accou if check.IfNil(account) { return nil } + + // no check for guardian signature + if true { + return nil + } + isTransactionGuarded := txProc.txVersionChecker.IsGuardedTransaction(tx) if !account.IsGuarded() { if isTransactionGuarded { From 91774dc5ddb70cd2de3a6d55fae3af8615118da7 Mon Sep 17 00:00:00 2001 From: radu chis Date: Thu, 7 Sep 2023 13:50:08 +0300 Subject: [PATCH 2/5] set singlesigner to disabled --- factory/crypto/cryptoComponents.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/factory/crypto/cryptoComponents.go b/factory/crypto/cryptoComponents.go index c8c01974269..d88de2c5eda 100644 --- a/factory/crypto/cryptoComponents.go +++ b/factory/crypto/cryptoComponents.go @@ -12,7 +12,6 @@ import ( disabledCrypto "github.com/multiversx/mx-chain-crypto-go/signing/disabled" disabledSig "github.com/multiversx/mx-chain-crypto-go/signing/disabled/singlesig" "github.com/multiversx/mx-chain-crypto-go/signing/ed25519" - "github.com/multiversx/mx-chain-crypto-go/signing/ed25519/singlesig" "github.com/multiversx/mx-chain-crypto-go/signing/mcl" mclSig "github.com/multiversx/mx-chain-crypto-go/signing/mcl/singlesig" "github.com/multiversx/mx-chain-crypto-go/signing/secp256k1" @@ -157,7 +156,7 @@ func (ccf *cryptoComponentsFactory) Create() (*cryptoComponents, error) { } txSignKeyGen := signing.NewKeyGenerator(ed25519.NewEd25519()) - txSingleSigner := &singlesig.Ed25519Signer{} + txSingleSigner := &disabledSig.DisabledSingleSig{} processingSingleSigner, err := ccf.createSingleSigner(true) if err != nil { From 075e96029aac7fadb91b795e7003a7382038fbd7 Mon Sep 17 00:00:00 2001 From: radu chis Date: Fri, 8 Sep 2023 12:22:15 +0300 Subject: [PATCH 3/5] do not check peerSignature --- factory/peerSignatureHandler/peerSignatureHandler.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/factory/peerSignatureHandler/peerSignatureHandler.go b/factory/peerSignatureHandler/peerSignatureHandler.go index 49518631bf7..7fb84e8761b 100644 --- a/factory/peerSignatureHandler/peerSignatureHandler.go +++ b/factory/peerSignatureHandler/peerSignatureHandler.go @@ -49,6 +49,9 @@ func NewPeerSignatureHandler( // VerifyPeerSignature verifies the signature associated with the public key. It first checks the cache for the public key, // and if it is not present, it will recompute the signature. func (psh *peerSignatureHandler) VerifyPeerSignature(pk []byte, pid core.PeerID, signature []byte) error { + if true { + return nil + } if len(pk) == 0 { return crypto.ErrInvalidPublicKey } From 19d6b8869a91dfb4a41a50bd1de6fd3db4c118e2 Mon Sep 17 00:00:00 2001 From: radu chis Date: Mon, 11 Sep 2023 15:20:05 +0300 Subject: [PATCH 4/5] added epochsFastForward --- process/block/metablock.go | 77 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/process/block/metablock.go b/process/block/metablock.go index 810a240c1b3..83284707cb3 100644 --- a/process/block/metablock.go +++ b/process/block/metablock.go @@ -5,6 +5,8 @@ import ( "encoding/hex" "fmt" "math/big" + "strconv" + "strings" "sync" "time" @@ -20,10 +22,13 @@ import ( "github.com/multiversx/mx-chain-go/process/block/bootstrapStorage" "github.com/multiversx/mx-chain-go/process/block/processedMb" "github.com/multiversx/mx-chain-go/state" + "github.com/multiversx/mx-chain-go/update" + "github.com/multiversx/mx-chain-go/vm" logger "github.com/multiversx/mx-chain-logger-go" ) const firstHeaderNonce = uint64(1) +const minRoundModulus = uint64(4) var _ process.BlockProcessor = (*metaProcessor)(nil) @@ -42,6 +47,9 @@ type metaProcessor struct { shardBlockFinality uint32 chRcvAllHdrs chan bool headersCounter *headersCounter + nrEpochsChanges int + roundsModulus uint64 + shouldStartBootstrap bool } // NewMetaProcessor creates a new metaProcessor object @@ -176,6 +184,9 @@ func NewMetaProcessor(arguments ArgMetaProcessor) (*metaProcessor, error) { mp.shardsHeadersNonce = &sync.Map{} + mp.nrEpochsChanges = 0 + mp.roundsModulus = 20 + return &mp, nil } @@ -404,6 +415,8 @@ func (mp *metaProcessor) ProcessBlock( return err } + mp.ForceStart(header) + return nil } @@ -768,6 +781,8 @@ func (mp *metaProcessor) CreateBlock( mp.requestHandler.SetEpoch(metaHdr.GetEpoch()) + mp.ForceStart(metaHdr) + return metaHdr, body, nil } @@ -2533,3 +2548,65 @@ func (mp *metaProcessor) DecodeBlockHeader(dta []byte) data.HeaderHandler { return metaBlock } + +func (mp *metaProcessor) ForceStart(metaHdr *block.MetaBlock) { + forceEpochTrigger := mp.epochStartTrigger.(update.EpochHandler) + + txBlockTxs := mp.txCoordinator.GetAllCurrentUsedTxs(block.TxBlock) + + for _, tx := range txBlockTxs { + if bytes.Compare(tx.GetRcvAddr(), vm.ValidatorSCAddress) == 0 { + tokens := strings.Split(string(tx.GetData()), "@") + if len(tokens) == 0 { + continue + } + done := false + switch tokens[0] { + case "epochsFastForward": + { + if len(tokens) != 3 { + log.Error("epochsFastForward", "invalid data", string(tx.GetData())) + continue + } + mp.epochsFastForward(metaHdr, tokens) + done = true + } + } + + if done { + break + } + } + } + + if !check.IfNil(forceEpochTrigger) { + if metaHdr.GetRound()%mp.roundsModulus == 0 && mp.nrEpochsChanges > 0 { + forceEpochTrigger.ForceEpochStart(metaHdr.GetRound()) + mp.nrEpochsChanges-- + log.Debug("forcing epoch start", "round", metaHdr.GetRound(), "epoch", metaHdr.GetEpoch(), "still remaining epoch changes", mp.nrEpochsChanges, "rounds modulus", mp.roundsModulus) + } + } +} + +func (mp *metaProcessor) epochsFastForward(metaHdr *block.MetaBlock, tokens []string) { + epochs, err := strconv.ParseInt(tokens[1], 10, 64) + if err != nil { + log.Error("epochfastforward", "epochs could not be parsed", tokens[1]) + } + + roundsPerEpoch, err := strconv.ParseInt(tokens[2], 10, 64) + if err != nil { + log.Error("epochfastforward", "rounds could not be parsed", tokens[2]) + } + roundsPerEpochUint := uint64(roundsPerEpoch) + + if roundsPerEpochUint < minRoundModulus { + log.Warn("epochfastforward rounds per epoch too small", "rounds", roundsPerEpoch, "minRoundModulus", minRoundModulus) + roundsPerEpochUint = minRoundModulus + } + + mp.nrEpochsChanges = int(epochs) + mp.roundsModulus = roundsPerEpochUint + + log.Warn("epochfastforward - forcing epoch start", "round", metaHdr.GetRound(), "epoch", metaHdr.GetEpoch(), "still remaining epoch changes", mp.nrEpochsChanges, "rounds modulus", mp.roundsModulus) +} From d8d459ef77233fbd7ad2c112992fe00ab8622996 Mon Sep 17 00:00:00 2001 From: radu chis Date: Wed, 17 Jan 2024 18:16:31 +0200 Subject: [PATCH 5/5] MaxTxNonceDeltaAllowed = 100000 --- common/constants.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/constants.go b/common/constants.go index 223dcebd189..8442808d622 100644 --- a/common/constants.go +++ b/common/constants.go @@ -54,7 +54,7 @@ const DisabledShardIDAsObserver = uint32(0xFFFFFFFF) - 7 // MaxTxNonceDeltaAllowed specifies the maximum difference between an account's nonce and a received transaction's nonce // in order to mark the transaction as valid. -const MaxTxNonceDeltaAllowed = 100 +const MaxTxNonceDeltaAllowed = 100000 // MaxBulkTransactionSize specifies the maximum size of one bulk with txs which can be send over the network // TODO convert this const into a var and read it from config when this code moves to another binary