Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move maxPublicKeysPerMultiSig to Consensus #167

Merged
merged 1 commit into from May 31, 2018
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -1,7 +1,6 @@
package org.bitcoins.core.gen

import org.bitcoins.core.crypto._
import org.bitcoins.core.script.ScriptSettings
import org.bitcoins.core.script.crypto.HashType
import org.bitcoins.core.util.CryptoUtil
import org.scalacheck.Gen
@@ -6,7 +6,7 @@ import org.bitcoins.core.number.UInt32
import org.bitcoins.core.policy.Policy
import org.bitcoins.core.protocol.script.{ P2SHScriptPubKey, _ }
import org.bitcoins.core.protocol.transaction._
import org.bitcoins.core.script.ScriptSettings
import org.bitcoins.core.consensus.Consensus
import org.bitcoins.core.script.constant.{ ScriptNumber, _ }
import org.bitcoins.core.script.crypto.HashType
import org.bitcoins.core.util.BitcoinSLogger
@@ -37,7 +37,7 @@ sealed abstract class ScriptGenerators extends BitcoinSLogger {

def multiSignatureScriptSignature: Gen[MultiSignatureScriptSignature] = {
val signatures: Gen[Seq[ECDigitalSignature]] = for {
numKeys <- Gen.choose(1, ScriptSettings.maxPublicKeysPerMultiSig)
numKeys <- Gen.choose(1, Consensus.maxPublicKeysPerMultiSig)
hash <- CryptoGenerators.doubleSha256Digest
} yield for {
_ <- 0 until numKeys
@@ -24,6 +24,14 @@ sealed abstract class Consensus {
def maxSigOps = 80000

def maxMoney: CurrencyUnit = Satoshis(Int64(2100000000000000L))

/**
* A integer representing the maximum number of public keys you can have in a
* OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY operation
* https://github.com/bitcoin/bitcoin/blob/master/src/script/interpreter.cpp#L903
* @return
*/
def maxPublicKeysPerMultiSig = 20
}

object Consensus extends Consensus
@@ -4,7 +4,7 @@ import org.bitcoins.core.crypto._
import org.bitcoins.core.protocol._
import org.bitcoins.core.protocol.blockchain.Block
import org.bitcoins.core.protocol.transaction.WitnessTransaction
import org.bitcoins.core.script.ScriptSettings
import org.bitcoins.core.consensus.Consensus
import org.bitcoins.core.script.bitwise.{ OP_EQUAL, OP_EQUALVERIFY }
import org.bitcoins.core.script.constant.{ BytesToPushOntoStack, _ }
import org.bitcoins.core.script.control.{ OP_ELSE, OP_ENDIF, OP_IF, OP_RETURN }
@@ -95,7 +95,7 @@ sealed trait MultiSignatureScriptPubKey extends ScriptPubKey {
val numSigsRequired = asmWithoutPushOps(opCheckMultiSigIndex - maxSigs.toInt - 2)
numSigsRequired match {
case x: ScriptNumber => x.toInt
case c: ScriptConstant if ScriptNumber(c.hex).toLong <= ScriptSettings.maxPublicKeysPerMultiSig =>
case c: ScriptConstant if ScriptNumber(c.hex).toLong <= Consensus.maxPublicKeysPerMultiSig =>
ScriptNumber(c.hex).toInt
case _ => throw new RuntimeException("The first element of the multisignature pubkey must be a script number operation\n" +
"operation: " + numSigsRequired +
@@ -111,7 +111,7 @@ sealed trait MultiSignatureScriptPubKey extends ScriptPubKey {
} else {
asm(checkMultiSigIndex - 1) match {
case x: ScriptNumber => x.toInt
case c: ScriptConstant if ScriptNumber(c.hex).toLong <= ScriptSettings.maxPublicKeysPerMultiSig =>
case c: ScriptConstant if ScriptNumber(c.hex).toLong <= Consensus.maxPublicKeysPerMultiSig =>
ScriptNumber(c.hex).toInt
case x => throw new RuntimeException("The element preceding a OP_CHECKMULTISIG operation in a multisignature pubkey must be a script number operation, got: " + x)
}
@@ -136,10 +136,10 @@ object MultiSignatureScriptPubKey extends ScriptFactory[MultiSignatureScriptPubK
}

def apply(requiredSigs: Int, pubKeys: Seq[ECPublicKey]): MultiSignatureScriptPubKey = {
require(requiredSigs <= ScriptSettings.maxPublicKeysPerMultiSig, "We cannot have more required signatures than: " +
ScriptSettings.maxPublicKeysPerMultiSig + " got: " + requiredSigs)
require(pubKeys.length <= ScriptSettings.maxPublicKeysPerMultiSig, "We cannot have more public keys than " +
ScriptSettings.maxPublicKeysPerMultiSig + " got: " + pubKeys.length)
require(requiredSigs <= Consensus.maxPublicKeysPerMultiSig, "We cannot have more required signatures than: " +
Consensus.maxPublicKeysPerMultiSig + " got: " + requiredSigs)
require(pubKeys.length <= Consensus.maxPublicKeysPerMultiSig, "We cannot have more public keys than " +
Consensus.maxPublicKeysPerMultiSig + " got: " + pubKeys.length)

val required = ScriptNumberOperation.fromNumber(requiredSigs) match {
case Some(scriptNumOp) => Seq(scriptNumOp)
@@ -212,7 +212,7 @@ object MultiSignatureScriptPubKey extends ScriptFactory[MultiSignatureScriptPubK
private def isValidPubKeyNumber(token: ScriptToken): Boolean = token match {
case constant: ScriptConstant =>
constant.isInstanceOf[ScriptNumber] ||
ScriptNumber(constant.bytes) <= ScriptNumber(ScriptSettings.maxPublicKeysPerMultiSig)
ScriptNumber(constant.bytes) <= ScriptNumber(Consensus.maxPublicKeysPerMultiSig)
case _: ScriptToken => false
}
}

This file was deleted.

@@ -6,6 +6,7 @@ import org.bitcoins.core.script.control.{ ControlOperationsInterpreter, OP_VERIF
import org.bitcoins.core.script.flag.ScriptFlagUtil
import org.bitcoins.core.script.result._
import org.bitcoins.core.script.{ ScriptProgram, _ }
import org.bitcoins.core.consensus.Consensus
import org.bitcoins.core.util.{ BitcoinSLogger, BitcoinScriptUtil, CryptoUtil }

import scala.annotation.tailrec
@@ -188,7 +189,7 @@ sealed abstract class CryptoInterpreter {
//this contains the extra Script OP that is required for OP_CHECKMULTISIG
val stackWithoutPubKeysAndSignatures = stackWithoutPubKeys.tail.slice(mRequiredSignatures.toInt, stackWithoutPubKeys.tail.size)
logger.debug("stackWithoutPubKeysAndSignatures: " + stackWithoutPubKeysAndSignatures)
if (pubKeys.size > ScriptSettings.maxPublicKeysPerMultiSig) {
if (pubKeys.size > Consensus.maxPublicKeysPerMultiSig) {
logger.error("We have more public keys than the maximum amount of public keys allowed")
ScriptProgram(executionInProgressScriptProgram, ScriptErrorPubKeyCount)
} else if (signatures.size > pubKeys.size) {
@@ -1,13 +1,14 @@
package org.bitcoins.core.util

import org.bitcoins.core.consensus.Consensus
import org.bitcoins.core.crypto._
import org.bitcoins.core.number.UInt32
import org.bitcoins.core.protocol.script.{ CLTVScriptPubKey, CSVScriptPubKey, EmptyScriptPubKey, _ }
import org.bitcoins.core.script.constant._
import org.bitcoins.core.script.crypto.{ OP_CHECKMULTISIG, OP_CHECKMULTISIGVERIFY, OP_CHECKSIG, OP_CHECKSIGVERIFY }
import org.bitcoins.core.script.flag.{ ScriptFlag, ScriptFlagUtil }
import org.bitcoins.core.script.result.{ ScriptError, ScriptErrorPubKeyType, ScriptErrorWitnessPubKeyType }
import org.bitcoins.core.script.{ ExecutionInProgressScriptProgram, ScriptProgram, ScriptSettings }
import org.bitcoins.core.script.{ ExecutionInProgressScriptProgram, ScriptProgram }

import scala.annotation.tailrec

@@ -62,7 +63,7 @@ trait BitcoinScriptUtil extends BitcoinSLogger {
script(index - 1) match {
case scriptNum: ScriptNumber => scriptNum.toLong
case scriptConstant: ScriptConstant => ScriptNumberUtil.toLong(scriptConstant.hex)
case _: ScriptToken => ScriptSettings.maxPublicKeysPerMultiSig
case _: ScriptToken => Consensus.maxPublicKeysPerMultiSig
}
} else 0
}.sum
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.