Skip to content

Commit

Permalink
limit transaction signature length (DNAProject#415)
Browse files Browse the repository at this point in the history
Signed-off-by: laizy <[email protected]>
  • Loading branch information
laizy authored Jun 25, 2018
1 parent 8a149c6 commit 45de04e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
6 changes: 3 additions & 3 deletions common/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ const (
)

var NETWORK_MAGIC = map[uint32]uint32{
NETWORK_ID_MAIN_NET: constants.NETWORK_MAIGIC_MAINNET, //Network main
NETWORK_ID_POLARIS_NET: constants.NETWORK_MAIGIC_POLARIS, //Network polaris
NETWORK_ID_SOLO_NET: 0, //Network solo
NETWORK_ID_MAIN_NET: constants.NETWORK_MAGIC_MAINNET, //Network main
NETWORK_ID_POLARIS_NET: constants.NETWORK_MAGIC_POLARIS, //Network polaris
NETWORK_ID_SOLO_NET: 0, //Network solo
}

var NETWORK_NAME = map[uint32]string{
Expand Down
10 changes: 7 additions & 3 deletions common/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,13 @@ var UNBOUND_DEADLINE = (func() uint32 {
})()

// multi-sig constants
const MULTI_SIG_MAX_PUBKEY_SIZE = 1024
const MULTI_SIG_MAX_PUBKEY_SIZE = 16

// transaction constants
const TX_MAX_SIG_SIZE = 16

// network magic number
const (
NETWORK_MAIGIC_MAINNET = 0x74746e41
NETWORK_MAIGIC_POLARIS = 0x74746e41
NETWORK_MAGIC_MAINNET = 0x74746e41
NETWORK_MAGIC_POLARIS = 0x74746e41
)
5 changes: 5 additions & 0 deletions core/types/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

"github.com/ontio/ontology-crypto/keypair"
"github.com/ontio/ontology/common"
"github.com/ontio/ontology/common/constants"
"github.com/ontio/ontology/common/serialization"
"github.com/ontio/ontology/core/payload"
"github.com/ontio/ontology/core/program"
Expand Down Expand Up @@ -211,6 +212,10 @@ func (tx *Transaction) Deserialize(r io.Reader) error {
return errors.NewDetailErr(err, errors.ErrNoCode, "[Deserialize], Transaction sigs length deserialize error.")
}

if length > constants.TX_MAX_SIG_SIZE {
return fmt.Errorf("transaction signature number %d execced %d", length, constants.TX_MAX_SIG_SIZE)
}

for i := 0; i < int(length); i++ {
sig := new(Sig)
err := sig.Deserialize(r)
Expand Down
6 changes: 6 additions & 0 deletions core/validation/transaction_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ func VerifyTransactionWithLedger(tx *types.Transaction, ledger *ledger.Ledger) o

func checkTransactionSignatures(tx *types.Transaction) error {
hash := tx.Hash()

lensig := len(tx.Sigs)
if lensig > constants.TX_MAX_SIG_SIZE {
return fmt.Errorf("transaction signature number %d execced %d", lensig, constants.TX_MAX_SIG_SIZE)
}

address := make(map[common.Address]bool, len(tx.Sigs))
for _, sig := range tx.Sigs {
m := int(sig.M)
Expand Down

0 comments on commit 45de04e

Please sign in to comment.