forked from TrueCloudLab/neoneo-go
*: use uint*Size and SignatureLen constants where appropriate
This commit is contained in:
parent
79887f9d78
commit
317dd42513
19 changed files with 56 additions and 51 deletions
|
@ -228,13 +228,13 @@ func randomRecoveryMessage(t *testing.T) *recoveryMessage {
|
|||
{
|
||||
ViewNumber: 0,
|
||||
ValidatorIndex: 1,
|
||||
Signature: [64]byte{1, 2, 3},
|
||||
Signature: [keys.SignatureLen]byte{1, 2, 3},
|
||||
InvocationScript: random.Bytes(20),
|
||||
},
|
||||
{
|
||||
ViewNumber: 0,
|
||||
ValidatorIndex: 2,
|
||||
Signature: [64]byte{11, 3, 4, 98},
|
||||
Signature: [keys.SignatureLen]byte{11, 3, 4, 98},
|
||||
InvocationScript: random.Bytes(10),
|
||||
},
|
||||
},
|
||||
|
|
|
@ -559,9 +559,9 @@ func TestBlockchain_VerifyHashAgainstScript(t *testing.T) {
|
|||
require.True(t, errors.Is(err, core.ErrVerificationFailed))
|
||||
})
|
||||
t.Run("BadResult", func(t *testing.T) {
|
||||
verif := make([]byte, 66)
|
||||
verif := make([]byte, keys.SignatureLen+2)
|
||||
verif[0] = byte(opcode.PUSHDATA1)
|
||||
verif[1] = 64
|
||||
verif[1] = keys.SignatureLen
|
||||
w := &transaction.Witness{
|
||||
InvocationScript: []byte{byte(opcode.NOP)},
|
||||
VerificationScript: verif,
|
||||
|
@ -1634,7 +1634,7 @@ func TestBlockchain_VerifyTx(t *testing.T) {
|
|||
VerificationScript: rawScript,
|
||||
},
|
||||
{
|
||||
InvocationScript: append([]byte{byte(opcode.PUSHDATA1), 64}, notary.PrivateKey().SignHashable(uint32(netmode.UnitTestNet), tx)...),
|
||||
InvocationScript: append([]byte{byte(opcode.PUSHDATA1), keys.SignatureLen}, notary.PrivateKey().SignHashable(uint32(netmode.UnitTestNet), tx)...),
|
||||
},
|
||||
}
|
||||
return tx
|
||||
|
@ -1679,7 +1679,7 @@ func TestBlockchain_VerifyTx(t *testing.T) {
|
|||
VerificationScript: committee.Script(),
|
||||
},
|
||||
{
|
||||
InvocationScript: append([]byte{byte(opcode.PUSHDATA1), 64}, notary.PrivateKey().SignHashable(uint32(netmode.UnitTestNet), tx)...),
|
||||
InvocationScript: append([]byte{byte(opcode.PUSHDATA1), keys.SignatureLen}, notary.PrivateKey().SignHashable(uint32(netmode.UnitTestNet), tx)...),
|
||||
},
|
||||
}
|
||||
require.Error(t, bc.VerifyTx(tx))
|
||||
|
@ -1698,7 +1698,7 @@ func TestBlockchain_VerifyTx(t *testing.T) {
|
|||
}
|
||||
tx.Scripts = []transaction.Witness{
|
||||
{
|
||||
InvocationScript: append([]byte{byte(opcode.PUSHDATA1), 64}, notary.PrivateKey().SignHashable(uint32(netmode.UnitTestNet), tx)...),
|
||||
InvocationScript: append([]byte{byte(opcode.PUSHDATA1), keys.SignatureLen}, notary.PrivateKey().SignHashable(uint32(netmode.UnitTestNet), tx)...),
|
||||
},
|
||||
{
|
||||
InvocationScript: committee.SignHashable(uint32(netmode.UnitTestNet), tx),
|
||||
|
@ -1725,7 +1725,7 @@ func TestBlockchain_VerifyTx(t *testing.T) {
|
|||
VerificationScript: committee.Script(),
|
||||
},
|
||||
{
|
||||
InvocationScript: append([]byte{byte(opcode.PUSHDATA1), 64}, notary.PrivateKey().SignHashable(uint32(netmode.UnitTestNet), tx)...),
|
||||
InvocationScript: append([]byte{byte(opcode.PUSHDATA1), keys.SignatureLen}, notary.PrivateKey().SignHashable(uint32(netmode.UnitTestNet), tx)...),
|
||||
},
|
||||
}
|
||||
require.Error(t, bc.VerifyTx(tx))
|
||||
|
@ -1766,7 +1766,7 @@ func TestBlockchain_VerifyTx(t *testing.T) {
|
|||
VerificationScript: committee.Script(),
|
||||
},
|
||||
{
|
||||
InvocationScript: append([]byte{byte(opcode.PUSHDATA1), 64}, acc.SignHashable(uint32(netmode.UnitTestNet), tx)...),
|
||||
InvocationScript: append([]byte{byte(opcode.PUSHDATA1), keys.SignatureLen}, acc.SignHashable(uint32(netmode.UnitTestNet), tx)...),
|
||||
},
|
||||
}
|
||||
require.Error(t, bc.VerifyTx(tx))
|
||||
|
@ -1781,7 +1781,7 @@ func TestBlockchain_VerifyTx(t *testing.T) {
|
|||
}
|
||||
tx.Scripts = []transaction.Witness{
|
||||
{
|
||||
InvocationScript: append([]byte{byte(opcode.PUSHDATA1), 64}, notary.PrivateKey().SignHashable(uint32(netmode.UnitTestNet), tx)...),
|
||||
InvocationScript: append([]byte{byte(opcode.PUSHDATA1), keys.SignatureLen}, notary.PrivateKey().SignHashable(uint32(netmode.UnitTestNet), tx)...),
|
||||
},
|
||||
}
|
||||
require.Error(t, bc.VerifyTx(tx))
|
||||
|
@ -1831,7 +1831,7 @@ func TestBlockchain_VerifyTx(t *testing.T) {
|
|||
nativeprices.NotaryVerificationPrice*bc.GetBaseExecFee() // Notary witness verification price
|
||||
tx.Scripts = []transaction.Witness{
|
||||
{
|
||||
InvocationScript: append([]byte{byte(opcode.PUSHDATA1), 64}, make([]byte, 64)...),
|
||||
InvocationScript: append([]byte{byte(opcode.PUSHDATA1), keys.SignatureLen}, make([]byte, keys.SignatureLen)...),
|
||||
VerificationScript: []byte{},
|
||||
},
|
||||
{
|
||||
|
@ -1858,7 +1858,7 @@ func TestBlockchain_VerifyTx(t *testing.T) {
|
|||
tx.NetworkFee-- // to check that NetworkFee was set correctly in getPartiallyFilledTx
|
||||
tx.Scripts = []transaction.Witness{
|
||||
{
|
||||
InvocationScript: append([]byte{byte(opcode.PUSHDATA1), 64}, make([]byte, 64)...),
|
||||
InvocationScript: append([]byte{byte(opcode.PUSHDATA1), keys.SignatureLen}, make([]byte, keys.SignatureLen)...),
|
||||
VerificationScript: []byte{},
|
||||
},
|
||||
{
|
||||
|
|
|
@ -120,7 +120,7 @@ func TestGAS_RewardWithP2PSigExtensionsEnabled(t *testing.T) {
|
|||
}
|
||||
tx.Scripts = []transaction.Witness{
|
||||
{
|
||||
InvocationScript: append([]byte{byte(opcode.PUSHDATA1), 64}, notaryNodes[0].SignHashable(uint32(e.Chain.GetConfig().Magic), tx)...),
|
||||
InvocationScript: append([]byte{byte(opcode.PUSHDATA1), keys.SignatureLen}, notaryNodes[0].SignHashable(uint32(e.Chain.GetConfig().Magic), tx)...),
|
||||
},
|
||||
{
|
||||
InvocationScript: e.Committee.SignHashable(uint32(e.Chain.GetConfig().Magic), tx),
|
||||
|
|
|
@ -126,7 +126,7 @@ func TestManagement_ContractDeploy(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
|
||||
badManifest := cs1.Manifest
|
||||
badManifest.Groups = []manifest.Group{{PublicKey: pkey.PublicKey(), Signature: make([]byte, 64)}}
|
||||
badManifest.Groups = []manifest.Group{{PublicKey: pkey.PublicKey(), Signature: make([]byte, keys.SignatureLen)}}
|
||||
manifB, err := json.Marshal(&badManifest)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
@ -432,7 +432,7 @@ func TestManagement_ContractUpdate(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
|
||||
var badManifest = cs1.Manifest
|
||||
badManifest.Groups = []manifest.Group{{PublicKey: pkey.PublicKey(), Signature: make([]byte, 64)}}
|
||||
badManifest.Groups = []manifest.Group{{PublicKey: pkey.PublicKey(), Signature: make([]byte, keys.SignatureLen)}}
|
||||
manifB, err := json.Marshal(badManifest)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
|
|
@ -221,7 +221,7 @@ func TestNotary_NotaryNodesReward(t *testing.T) {
|
|||
}
|
||||
tx.Scripts = []transaction.Witness{
|
||||
{
|
||||
InvocationScript: append([]byte{byte(opcode.PUSHDATA1), 64}, notaryNodes[0].SignHashable(uint32(e.Chain.GetConfig().Magic), tx)...),
|
||||
InvocationScript: append([]byte{byte(opcode.PUSHDATA1), keys.SignatureLen}, notaryNodes[0].SignHashable(uint32(e.Chain.GetConfig().Magic), tx)...),
|
||||
},
|
||||
{
|
||||
InvocationScript: e.Committee.SignHashable(uint32(e.Chain.GetConfig().Magic), tx),
|
||||
|
|
|
@ -17,7 +17,7 @@ type Hashable interface {
|
|||
}
|
||||
|
||||
func getSignedData(net uint32, hh Hashable) []byte {
|
||||
var b = make([]byte, 4+32)
|
||||
var b = make([]byte, 4+util.Uint256Size)
|
||||
binary.LittleEndian.PutUint32(b, net)
|
||||
h := hh.Hash()
|
||||
copy(b[4:], h[:])
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
|
||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
||||
|
@ -73,7 +74,7 @@ func (s *signer) ScriptHash() util.Uint160 {
|
|||
|
||||
// SignHashable implements Signer interface.
|
||||
func (s *signer) SignHashable(magic uint32, item hash.Hashable) []byte {
|
||||
return append([]byte{byte(opcode.PUSHDATA1), 64},
|
||||
return append([]byte{byte(opcode.PUSHDATA1), keys.SignatureLen},
|
||||
(*wallet.Account)(s).SignHashable(netmode.Magic(magic), item)...)
|
||||
}
|
||||
|
||||
|
@ -131,7 +132,7 @@ func (m multiSigner) SignHashable(magic uint32, item hash.Hashable) []byte {
|
|||
var script []byte
|
||||
for i := 0; i < m.m; i++ {
|
||||
sign := m.accounts[i].SignHashable(netmode.Magic(magic), item)
|
||||
script = append(script, byte(opcode.PUSHDATA1), 64)
|
||||
script = append(script, byte(opcode.PUSHDATA1), keys.SignatureLen)
|
||||
script = append(script, sign...)
|
||||
}
|
||||
return script
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
|
||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
||||
|
@ -110,7 +111,7 @@ func (r *P2PNotaryRequest) isValid() error {
|
|||
}
|
||||
if len(r.FallbackTransaction.Scripts[0].InvocationScript) != 66 ||
|
||||
len(r.FallbackTransaction.Scripts[0].VerificationScript) != 0 ||
|
||||
!bytes.HasPrefix(r.FallbackTransaction.Scripts[0].InvocationScript, []byte{byte(opcode.PUSHDATA1), 64}) {
|
||||
!bytes.HasPrefix(r.FallbackTransaction.Scripts[0].InvocationScript, []byte{byte(opcode.PUSHDATA1), keys.SignatureLen}) {
|
||||
return errors.New("fallback transaction has invalid dummy Notary witness")
|
||||
}
|
||||
if !r.FallbackTransaction.HasAttribute(transaction.NotValidBeforeT) {
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
|
||||
"github.com/nspcc-dev/neo-go/internal/random"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
@ -45,21 +46,21 @@ func TestNotaryRequestIsValid(t *testing.T) {
|
|||
MainTransaction: mainTx,
|
||||
FallbackTransaction: &transaction.Transaction{
|
||||
Signers: []transaction.Signer{{Account: random.Uint160()}, {Account: random.Uint160()}},
|
||||
Scripts: []transaction.Witness{{InvocationScript: append([]byte{byte(opcode.PUSHDATA1), 65}, make([]byte, 64)...)}, {}},
|
||||
Scripts: []transaction.Witness{{InvocationScript: append([]byte{byte(opcode.PUSHDATA1), 65}, make([]byte, keys.SignatureLen)...)}, {}},
|
||||
},
|
||||
},
|
||||
"fallback tx: invalid dummy Notary witness (non-empty verification script))": {
|
||||
MainTransaction: mainTx,
|
||||
FallbackTransaction: &transaction.Transaction{
|
||||
Signers: []transaction.Signer{{Account: random.Uint160()}, {Account: random.Uint160()}},
|
||||
Scripts: []transaction.Witness{{InvocationScript: append([]byte{byte(opcode.PUSHDATA1), 64}, make([]byte, 64)...), VerificationScript: make([]byte, 1)}, {}},
|
||||
Scripts: []transaction.Witness{{InvocationScript: append([]byte{byte(opcode.PUSHDATA1), keys.SignatureLen}, make([]byte, keys.SignatureLen)...), VerificationScript: make([]byte, 1)}, {}},
|
||||
},
|
||||
},
|
||||
"fallback tx: missing NotValidBefore attribute": {
|
||||
MainTransaction: mainTx,
|
||||
FallbackTransaction: &transaction.Transaction{
|
||||
Signers: []transaction.Signer{{Account: random.Uint160()}, {Account: random.Uint160()}},
|
||||
Scripts: []transaction.Witness{{InvocationScript: append([]byte{byte(opcode.PUSHDATA1), 64}, make([]byte, 64)...), VerificationScript: make([]byte, 0)}, {}},
|
||||
Scripts: []transaction.Witness{{InvocationScript: append([]byte{byte(opcode.PUSHDATA1), keys.SignatureLen}, make([]byte, keys.SignatureLen)...), VerificationScript: make([]byte, 0)}, {}},
|
||||
},
|
||||
},
|
||||
"fallback tx: invalid number of Conflicts attributes": {
|
||||
|
@ -67,7 +68,7 @@ func TestNotaryRequestIsValid(t *testing.T) {
|
|||
FallbackTransaction: &transaction.Transaction{
|
||||
Attributes: []transaction.Attribute{{Type: transaction.NotValidBeforeT, Value: &transaction.NotValidBefore{Height: 123}}},
|
||||
Signers: []transaction.Signer{{Account: random.Uint160()}, {Account: random.Uint160()}},
|
||||
Scripts: []transaction.Witness{{InvocationScript: append([]byte{byte(opcode.PUSHDATA1), 64}, make([]byte, 64)...), VerificationScript: make([]byte, 0)}, {}},
|
||||
Scripts: []transaction.Witness{{InvocationScript: append([]byte{byte(opcode.PUSHDATA1), keys.SignatureLen}, make([]byte, keys.SignatureLen)...), VerificationScript: make([]byte, 0)}, {}},
|
||||
},
|
||||
},
|
||||
"fallback tx: does not conflicts with main tx": {
|
||||
|
@ -78,7 +79,7 @@ func TestNotaryRequestIsValid(t *testing.T) {
|
|||
{Type: transaction.ConflictsT, Value: &transaction.Conflicts{Hash: util.Uint256{}}},
|
||||
},
|
||||
Signers: []transaction.Signer{{Account: random.Uint160()}, {Account: random.Uint160()}},
|
||||
Scripts: []transaction.Witness{{InvocationScript: append([]byte{byte(opcode.PUSHDATA1), 64}, make([]byte, 64)...), VerificationScript: make([]byte, 0)}, {}},
|
||||
Scripts: []transaction.Witness{{InvocationScript: append([]byte{byte(opcode.PUSHDATA1), keys.SignatureLen}, make([]byte, keys.SignatureLen)...), VerificationScript: make([]byte, 0)}, {}},
|
||||
},
|
||||
},
|
||||
"fallback tx: missing NotaryAssisted attribute": {
|
||||
|
@ -89,7 +90,7 @@ func TestNotaryRequestIsValid(t *testing.T) {
|
|||
{Type: transaction.ConflictsT, Value: &transaction.Conflicts{Hash: mainTx.Hash()}},
|
||||
},
|
||||
Signers: []transaction.Signer{{Account: random.Uint160()}, {Account: random.Uint160()}},
|
||||
Scripts: []transaction.Witness{{InvocationScript: append([]byte{byte(opcode.PUSHDATA1), 64}, make([]byte, 64)...), VerificationScript: make([]byte, 0)}, {}},
|
||||
Scripts: []transaction.Witness{{InvocationScript: append([]byte{byte(opcode.PUSHDATA1), keys.SignatureLen}, make([]byte, keys.SignatureLen)...), VerificationScript: make([]byte, 0)}, {}},
|
||||
},
|
||||
},
|
||||
"fallback tx: non-zero NKeys": {
|
||||
|
@ -101,7 +102,7 @@ func TestNotaryRequestIsValid(t *testing.T) {
|
|||
{Type: transaction.NotaryAssistedT, Value: &transaction.NotaryAssisted{NKeys: 1}},
|
||||
},
|
||||
Signers: []transaction.Signer{{Account: random.Uint160()}, {Account: random.Uint160()}},
|
||||
Scripts: []transaction.Witness{{InvocationScript: append([]byte{byte(opcode.PUSHDATA1), 64}, make([]byte, 64)...), VerificationScript: make([]byte, 0)}, {}},
|
||||
Scripts: []transaction.Witness{{InvocationScript: append([]byte{byte(opcode.PUSHDATA1), keys.SignatureLen}, make([]byte, keys.SignatureLen)...), VerificationScript: make([]byte, 0)}, {}},
|
||||
},
|
||||
},
|
||||
"fallback tx: ValidUntilBlock mismatch": {
|
||||
|
@ -114,7 +115,7 @@ func TestNotaryRequestIsValid(t *testing.T) {
|
|||
{Type: transaction.NotaryAssistedT, Value: &transaction.NotaryAssisted{NKeys: 0}},
|
||||
},
|
||||
Signers: []transaction.Signer{{Account: random.Uint160()}, {Account: random.Uint160()}},
|
||||
Scripts: []transaction.Witness{{InvocationScript: append([]byte{byte(opcode.PUSHDATA1), 64}, make([]byte, 64)...), VerificationScript: make([]byte, 0)}, {}},
|
||||
Scripts: []transaction.Witness{{InvocationScript: append([]byte{byte(opcode.PUSHDATA1), keys.SignatureLen}, make([]byte, keys.SignatureLen)...), VerificationScript: make([]byte, 0)}, {}},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -134,7 +135,7 @@ func TestNotaryRequestIsValid(t *testing.T) {
|
|||
{Type: transaction.NotaryAssistedT, Value: &transaction.NotaryAssisted{NKeys: 0}},
|
||||
},
|
||||
Signers: []transaction.Signer{{Account: random.Uint160()}, {Account: random.Uint160()}},
|
||||
Scripts: []transaction.Witness{{InvocationScript: append([]byte{byte(opcode.PUSHDATA1), 64}, make([]byte, 64)...), VerificationScript: make([]byte, 0)}, {}},
|
||||
Scripts: []transaction.Witness{{InvocationScript: append([]byte{byte(opcode.PUSHDATA1), keys.SignatureLen}, make([]byte, keys.SignatureLen)...), VerificationScript: make([]byte, 0)}, {}},
|
||||
},
|
||||
}
|
||||
require.NoError(t, p.isValid())
|
||||
|
@ -164,7 +165,7 @@ func TestNotaryRequestBytesFromBytes(t *testing.T) {
|
|||
},
|
||||
Signers: []transaction.Signer{{Account: util.Uint160{1, 4, 7}}, {Account: util.Uint160{9, 8, 7}}},
|
||||
Scripts: []transaction.Witness{
|
||||
{InvocationScript: append([]byte{byte(opcode.PUSHDATA1), 64}, make([]byte, 64)...), VerificationScript: make([]byte, 0)},
|
||||
{InvocationScript: append([]byte{byte(opcode.PUSHDATA1), keys.SignatureLen}, make([]byte, keys.SignatureLen)...), VerificationScript: make([]byte, 0)},
|
||||
{InvocationScript: []byte{1, 2, 3}, VerificationScript: []byte{1, 2, 3}}},
|
||||
}
|
||||
_ = fallbackTx.Hash()
|
||||
|
|
|
@ -19,6 +19,7 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/core/interop"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/mpt"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||
"github.com/nspcc-dev/neo-go/pkg/network/capability"
|
||||
"github.com/nspcc-dev/neo-go/pkg/network/payload"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
|
@ -545,7 +546,7 @@ func TestGetData(t *testing.T) {
|
|||
{Type: transaction.NotaryAssistedT, Value: &transaction.NotaryAssisted{NKeys: 0}},
|
||||
},
|
||||
Signers: []transaction.Signer{{Account: random.Uint160()}, {Account: random.Uint160()}},
|
||||
Scripts: []transaction.Witness{{InvocationScript: append([]byte{byte(opcode.PUSHDATA1), 64}, make([]byte, 64)...), VerificationScript: make([]byte, 0)}, {InvocationScript: []byte{}, VerificationScript: []byte{}}},
|
||||
Scripts: []transaction.Witness{{InvocationScript: append([]byte{byte(opcode.PUSHDATA1), keys.SignatureLen}, make([]byte, keys.SignatureLen)...), VerificationScript: make([]byte, 0)}, {InvocationScript: []byte{}, VerificationScript: []byte{}}},
|
||||
}
|
||||
fallbackTx.Size()
|
||||
fallbackTx.Hash()
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"fmt"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
|
||||
"github.com/nspcc-dev/neo-go/pkg/network/payload"
|
||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient/actor"
|
||||
|
@ -278,7 +279,7 @@ func (a *Actor) SendRequest(mainTx *transaction.Transaction, fbTx *transaction.T
|
|||
if err != nil {
|
||||
return mainHash, fbHash, vub, err
|
||||
}
|
||||
fbTx.Scripts[0].InvocationScript = append([]byte{byte(opcode.PUSHDATA1), 64}, make([]byte, 64)...) // Must be present.
|
||||
fbTx.Scripts[0].InvocationScript = append([]byte{byte(opcode.PUSHDATA1), keys.SignatureLen}, make([]byte, keys.SignatureLen)...) // Must be present.
|
||||
return a.SendRequestExactly(mainTx, fbTx)
|
||||
}
|
||||
|
||||
|
@ -300,7 +301,7 @@ func (a *Actor) SendRequestExactly(mainTx *transaction.Transaction, fbTx *transa
|
|||
FallbackTransaction: fbTx,
|
||||
}
|
||||
req.Witness = transaction.Witness{
|
||||
InvocationScript: append([]byte{byte(opcode.PUSHDATA1), 64}, a.sender.SignHashable(a.GetNetwork(), req)...),
|
||||
InvocationScript: append([]byte{byte(opcode.PUSHDATA1), keys.SignatureLen}, a.sender.SignHashable(a.GetNetwork(), req)...),
|
||||
VerificationScript: a.sender.GetVerificationScript(),
|
||||
}
|
||||
actualHash, err := a.rpc.SubmitP2PNotaryRequest(req)
|
||||
|
|
|
@ -893,7 +893,7 @@ func (c *Client) SignAndPushP2PNotaryRequest(mainTx *transaction.Transaction, fa
|
|||
|
||||
fallbackTx.Scripts = []transaction.Witness{
|
||||
{
|
||||
InvocationScript: append([]byte{byte(opcode.PUSHDATA1), 64}, make([]byte, 64)...),
|
||||
InvocationScript: append([]byte{byte(opcode.PUSHDATA1), keys.SignatureLen}, make([]byte, keys.SignatureLen)...),
|
||||
VerificationScript: []byte{},
|
||||
},
|
||||
{
|
||||
|
@ -919,7 +919,7 @@ func (c *Client) SignAndPushP2PNotaryRequest(mainTx *transaction.Transaction, fa
|
|||
FallbackTransaction: fallbackTx,
|
||||
}
|
||||
req.Witness = transaction.Witness{
|
||||
InvocationScript: append([]byte{byte(opcode.PUSHDATA1), 64}, acc.SignHashable(m, req)...),
|
||||
InvocationScript: append([]byte{byte(opcode.PUSHDATA1), keys.SignatureLen}, acc.SignHashable(m, req)...),
|
||||
VerificationScript: acc.GetVerificationScript(),
|
||||
}
|
||||
actualHash, err := c.SubmitP2PNotaryRequest(req)
|
||||
|
|
|
@ -199,7 +199,7 @@ func TestNotary(t *testing.T) {
|
|||
}
|
||||
fallback.Scripts = []transaction.Witness{
|
||||
{
|
||||
InvocationScript: append([]byte{byte(opcode.PUSHDATA1), 64}, make([]byte, 64)...),
|
||||
InvocationScript: append([]byte{byte(opcode.PUSHDATA1), keys.SignatureLen}, make([]byte, keys.SignatureLen)...),
|
||||
VerificationScript: []byte{},
|
||||
},
|
||||
}
|
||||
|
@ -261,7 +261,7 @@ func TestNotary(t *testing.T) {
|
|||
for j := range main.Scripts {
|
||||
main.Scripts[j].VerificationScript = verificationScripts[j]
|
||||
if i == j {
|
||||
main.Scripts[j].InvocationScript = append([]byte{byte(opcode.PUSHDATA1), 64}, acc.PrivateKey().SignHashable(uint32(netmode.UnitTestNet), main)...)
|
||||
main.Scripts[j].InvocationScript = append([]byte{byte(opcode.PUSHDATA1), keys.SignatureLen}, acc.PrivateKey().SignHashable(uint32(netmode.UnitTestNet), main)...)
|
||||
}
|
||||
}
|
||||
main.Scripts = append(main.Scripts, transaction.Witness{}) // empty Notary witness
|
||||
|
@ -310,7 +310,7 @@ func TestNotary(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
}
|
||||
require.Equal(t, transaction.Witness{
|
||||
InvocationScript: append([]byte{byte(opcode.PUSHDATA1), 64}, acc1.PrivateKey().SignHashable(uint32(netmode.UnitTestNet), requests[0].MainTransaction)...),
|
||||
InvocationScript: append([]byte{byte(opcode.PUSHDATA1), keys.SignatureLen}, acc1.PrivateKey().SignHashable(uint32(netmode.UnitTestNet), requests[0].MainTransaction)...),
|
||||
VerificationScript: []byte{},
|
||||
}, completedTx.Scripts[len(completedTx.Scripts)-1])
|
||||
} else {
|
||||
|
@ -325,7 +325,7 @@ func TestNotary(t *testing.T) {
|
|||
require.Equal(t, 2, len(completedTx.Signers))
|
||||
require.Equal(t, 2, len(completedTx.Scripts))
|
||||
require.Equal(t, transaction.Witness{
|
||||
InvocationScript: append([]byte{byte(opcode.PUSHDATA1), 64}, acc1.PrivateKey().SignHashable(uint32(netmode.UnitTestNet), req.FallbackTransaction)...),
|
||||
InvocationScript: append([]byte{byte(opcode.PUSHDATA1), keys.SignatureLen}, acc1.PrivateKey().SignHashable(uint32(netmode.UnitTestNet), req.FallbackTransaction)...),
|
||||
VerificationScript: []byte{},
|
||||
}, completedTx.Scripts[0])
|
||||
|
||||
|
|
|
@ -392,7 +392,7 @@ func (n *Notary) PostPersist() {
|
|||
// finalize adds missing Notary witnesses to the transaction (main or fallback) and pushes it to the network.
|
||||
func (n *Notary) finalize(acc *wallet.Account, tx *transaction.Transaction, h util.Uint256) error {
|
||||
notaryWitness := transaction.Witness{
|
||||
InvocationScript: append([]byte{byte(opcode.PUSHDATA1), 64}, acc.SignHashable(n.Network, tx)...),
|
||||
InvocationScript: append([]byte{byte(opcode.PUSHDATA1), keys.SignatureLen}, acc.SignHashable(n.Network, tx)...),
|
||||
VerificationScript: []byte{},
|
||||
}
|
||||
for i, signer := range tx.Signers {
|
||||
|
@ -515,7 +515,7 @@ func (n *Notary) verifyIncompleteWitnesses(tx *transaction.Transaction, nKeysExp
|
|||
}
|
||||
// Each verification script is allowed to have either one signature or zero signatures. If signature is provided, then need to verify it.
|
||||
if len(w.InvocationScript) != 0 {
|
||||
if len(w.InvocationScript) != 66 || !bytes.HasPrefix(w.InvocationScript, []byte{byte(opcode.PUSHDATA1), 64}) {
|
||||
if len(w.InvocationScript) != 66 || !bytes.HasPrefix(w.InvocationScript, []byte{byte(opcode.PUSHDATA1), keys.SignatureLen}) {
|
||||
return nil, fmt.Errorf("witness #%d: invocation script should have length = 66 and be of the form [PUSHDATA1, 64, signatureBytes...]", i)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ func TestVerifyIncompleteRequest(t *testing.T) {
|
|||
notaryContractHash := util.Uint160{1, 2, 3}
|
||||
bc.NotaryContractScriptHash = notaryContractHash
|
||||
_, ntr, _ := getTestNotary(t, bc, "./testdata/notary1.json", "one")
|
||||
sig := append([]byte{byte(opcode.PUSHDATA1), 64}, make([]byte, 64)...) // we're not interested in signature correctness
|
||||
sig := append([]byte{byte(opcode.PUSHDATA1), keys.SignatureLen}, make([]byte, keys.SignatureLen)...) // we're not interested in signature correctness
|
||||
acc1, _ := keys.NewPrivateKey()
|
||||
acc2, _ := keys.NewPrivateKey()
|
||||
acc3, _ := keys.NewPrivateKey()
|
||||
|
|
|
@ -1089,7 +1089,7 @@ func TestSignAndPushP2PNotaryRequest(t *testing.T) {
|
|||
err = ntr.Decrypt(notaryPass, w.Scrypt)
|
||||
require.NoError(t, err)
|
||||
req.FallbackTransaction.Scripts[0] = transaction.Witness{
|
||||
InvocationScript: append([]byte{byte(opcode.PUSHDATA1), 64}, ntr.PrivateKey().SignHashable(uint32(testchain.Network()), req.FallbackTransaction)...),
|
||||
InvocationScript: append([]byte{byte(opcode.PUSHDATA1), keys.SignatureLen}, ntr.PrivateKey().SignHashable(uint32(testchain.Network()), req.FallbackTransaction)...),
|
||||
VerificationScript: []byte{},
|
||||
}
|
||||
b := testchain.NewBlock(t, chain, 1, 0, req.FallbackTransaction)
|
||||
|
|
|
@ -1782,7 +1782,7 @@ func TestSubmitNotaryRequest(t *testing.T) {
|
|||
},
|
||||
Signers: []transaction.Signer{{Account: util.Uint160{1, 4, 7}}, {Account: util.Uint160{9, 8, 7}}},
|
||||
Scripts: []transaction.Witness{
|
||||
{InvocationScript: append([]byte{byte(opcode.PUSHDATA1), 64}, make([]byte, 64)...), VerificationScript: make([]byte, 0)},
|
||||
{InvocationScript: append([]byte{byte(opcode.PUSHDATA1), keys.SignatureLen}, make([]byte, keys.SignatureLen)...), VerificationScript: make([]byte, 0)},
|
||||
{InvocationScript: []byte{1, 2, 3}, VerificationScript: []byte{1, 2, 3}}},
|
||||
}
|
||||
p := &payload.P2PNotaryRequest{
|
||||
|
@ -1833,12 +1833,12 @@ func createValidNotaryRequest(chain *core.Blockchain, sender *keys.PrivateKey, n
|
|||
},
|
||||
Signers: []transaction.Signer{{Account: chain.GetNotaryContractScriptHash()}, {Account: sender.GetScriptHash()}},
|
||||
Scripts: []transaction.Witness{
|
||||
{InvocationScript: append([]byte{byte(opcode.PUSHDATA1), 64}, make([]byte, 64)...), VerificationScript: []byte{}},
|
||||
{InvocationScript: append([]byte{byte(opcode.PUSHDATA1), keys.SignatureLen}, make([]byte, keys.SignatureLen)...), VerificationScript: []byte{}},
|
||||
},
|
||||
NetworkFee: 2_0000_0000,
|
||||
}
|
||||
fallbackTx.Scripts = append(fallbackTx.Scripts, transaction.Witness{
|
||||
InvocationScript: append([]byte{byte(opcode.PUSHDATA1), 64}, sender.SignHashable(uint32(testchain.Network()), fallbackTx)...),
|
||||
InvocationScript: append([]byte{byte(opcode.PUSHDATA1), keys.SignatureLen}, sender.SignHashable(uint32(testchain.Network()), fallbackTx)...),
|
||||
VerificationScript: sender.PublicKey().GetVerificationScript(),
|
||||
})
|
||||
p := &payload.P2PNotaryRequest{
|
||||
|
@ -1846,7 +1846,7 @@ func createValidNotaryRequest(chain *core.Blockchain, sender *keys.PrivateKey, n
|
|||
FallbackTransaction: fallbackTx,
|
||||
}
|
||||
p.Witness = transaction.Witness{
|
||||
InvocationScript: append([]byte{byte(opcode.PUSHDATA1), 64}, sender.SignHashable(uint32(testchain.Network()), p)...),
|
||||
InvocationScript: append([]byte{byte(opcode.PUSHDATA1), keys.SignatureLen}, sender.SignHashable(uint32(testchain.Network()), p)...),
|
||||
VerificationScript: sender.PublicKey().GetVerificationScript(),
|
||||
}
|
||||
return p
|
||||
|
|
|
@ -43,11 +43,11 @@ func TestContextItem_MarshalJSON(t *testing.T) {
|
|||
Script: []byte{1, 2, 3},
|
||||
Parameters: []smartcontract.Parameter{{
|
||||
Type: smartcontract.SignatureType,
|
||||
Value: random.Bytes(64),
|
||||
Value: random.Bytes(keys.SignatureLen),
|
||||
}},
|
||||
Signatures: map[string][]byte{
|
||||
hex.EncodeToString(priv1.PublicKey().Bytes()): random.Bytes(64),
|
||||
hex.EncodeToString(priv2.PublicKey().Bytes()): random.Bytes(64),
|
||||
hex.EncodeToString(priv1.PublicKey().Bytes()): random.Bytes(keys.SignatureLen),
|
||||
hex.EncodeToString(priv2.PublicKey().Bytes()): random.Bytes(keys.SignatureLen),
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -116,7 +116,7 @@ func (a *Account) SignTx(net netmode.Magic, t *transaction.Transaction) error {
|
|||
}
|
||||
sign := a.privateKey.SignHashable(uint32(net), t)
|
||||
|
||||
invoc := append([]byte{byte(opcode.PUSHDATA1), 64}, sign...)
|
||||
invoc := append([]byte{byte(opcode.PUSHDATA1), keys.SignatureLen}, sign...)
|
||||
if len(a.Contract.Parameters) == 1 {
|
||||
t.Scripts[pos].InvocationScript = invoc
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue