PopInt now guarantees that number will be 32 bit.
So remove later checks that need this.
This commit is contained in:
parent
c7d5102954
commit
f80c3255a3
3 changed files with 16 additions and 22 deletions
19
opcode.go
19
opcode.go
|
@ -1258,10 +1258,7 @@ func opcodePick(op *parsedOpcode, s *Script) error {
|
|||
return err
|
||||
}
|
||||
|
||||
if pidx.BitLen() > 32 {
|
||||
return StackErrNumberTooBig
|
||||
}
|
||||
|
||||
// PopInt promises that the int returned is 32 bit.
|
||||
val := int(pidx.Int64())
|
||||
|
||||
return s.dstack.PickN(val)
|
||||
|
@ -1275,10 +1272,7 @@ func opcodeRoll(op *parsedOpcode, s *Script) error {
|
|||
return err
|
||||
}
|
||||
|
||||
if ridx.BitLen() > 32 {
|
||||
return StackErrNumberTooBig
|
||||
}
|
||||
|
||||
// PopInt promises that the int returned is 32 bit.
|
||||
val := int(ridx.Int64())
|
||||
|
||||
return s.dstack.RollN(val)
|
||||
|
@ -1823,10 +1817,7 @@ func opcodeCheckMultiSig(op *parsedOpcode, s *Script) error {
|
|||
// XXX arbitrary limits
|
||||
// nore more than 20 pubkeyhs, or 201 operations
|
||||
|
||||
if numPubkeys.BitLen() > 32 {
|
||||
return StackErrNumberTooBig
|
||||
}
|
||||
|
||||
// PopInt promises that the int returned is 32 bit.
|
||||
npk := int(numPubkeys.Int64())
|
||||
if npk < 0 || npk > MaxPubKeysPerMultiSig {
|
||||
return StackErrTooManyPubkeys
|
||||
|
@ -1848,10 +1839,8 @@ func opcodeCheckMultiSig(op *parsedOpcode, s *Script) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if numSignatures.BitLen() > 32 {
|
||||
return StackErrNumberTooBig
|
||||
}
|
||||
|
||||
// PopInt promises that the int returned is 32 bit.
|
||||
nsig := int(numSignatures.Int64())
|
||||
|
||||
sigStrings := make([][]byte, nsig)
|
||||
|
|
|
@ -872,12 +872,13 @@ var detailedTests = []detailedTest{
|
|||
disassembly: "OP_IFDUP",
|
||||
},
|
||||
{
|
||||
name: "toaltastack",
|
||||
// alt stack is purged at the end of execution
|
||||
name: "toaltstack",
|
||||
before: [][]byte{{1}},
|
||||
altbefore: [][]byte{},
|
||||
script: []byte{btcscript.OP_TOALTSTACK},
|
||||
after: [][]byte{},
|
||||
altafter: [][]byte{{1}},
|
||||
altafter: [][]byte{},
|
||||
disassembly: "OP_TOALTSTACK",
|
||||
},
|
||||
{
|
||||
|
|
14
stack.go
14
stack.go
|
@ -10,9 +10,13 @@ import (
|
|||
|
||||
// asInt converts a byte array to a bignum by treating it as a little endian
|
||||
// number with sign bit.
|
||||
func asInt(v []byte) *big.Int {
|
||||
func asInt(v []byte) (*big.Int, error) {
|
||||
// Only 32bit numbers allowed.
|
||||
if len(v) > 4 {
|
||||
return nil, StackErrNumberTooBig
|
||||
}
|
||||
if len(v) == 0 {
|
||||
return big.NewInt(0)
|
||||
return big.NewInt(0), nil
|
||||
}
|
||||
negative := false
|
||||
origlen := len(v)
|
||||
|
@ -44,7 +48,7 @@ func asInt(v []byte) *big.Int {
|
|||
if negative {
|
||||
num = num.Neg(num)
|
||||
}
|
||||
return num
|
||||
return num, nil
|
||||
}
|
||||
|
||||
// fromInt provies a Big.Int in little endian format with the high bit of the
|
||||
|
@ -127,7 +131,7 @@ func (s *Stack) PopInt() (*big.Int, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return asInt(so), nil
|
||||
return asInt(so)
|
||||
}
|
||||
|
||||
// PopBool pops the value off the top of the stack, converts it into a bool and
|
||||
|
@ -155,7 +159,7 @@ func (s *Stack) PeekInt(idx int) (i *big.Int, err error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return asInt(so), nil
|
||||
return asInt(so)
|
||||
}
|
||||
|
||||
// PeekBool returns the nth item on the stack as a bool without removing it.
|
||||
|
|
Loading…
Reference in a new issue