diff --git a/pkg/consensus/block.go b/pkg/consensus/block.go index ab4449b53..31b6a5e15 100644 --- a/pkg/consensus/block.go +++ b/pkg/consensus/block.go @@ -20,7 +20,7 @@ var _ block.Block = (*neoBlock)(nil) // Sign implements block.Block interface. func (n *neoBlock) Sign(key crypto.PrivateKey) error { - data := n.Base.GetHashableData() + data := n.Base.GetSignedPart() sig, err := key.Sign(data[:]) if err != nil { return err @@ -33,7 +33,7 @@ func (n *neoBlock) Sign(key crypto.PrivateKey) error { // Verify implements block.Block interface. func (n *neoBlock) Verify(key crypto.PublicKey, sign []byte) error { - data := n.Base.GetHashableData() + data := n.Base.GetSignedPart() return key.Verify(data, sign) } diff --git a/pkg/core/block/block_base.go b/pkg/core/block/block_base.go index e2dc11cbf..bfd5e4ab4 100644 --- a/pkg/core/block/block_base.go +++ b/pkg/core/block/block_base.go @@ -90,8 +90,8 @@ func (b *Base) EncodeBinary(bw *io.BinWriter) { b.Script.EncodeBinary(bw) } -// GetHashableData returns serialized hashable data of the block. -func (b *Base) GetHashableData() []byte { +// GetSignedPart returns serialized hashable data of the block. +func (b *Base) GetSignedPart() []byte { buf := io.NewBufBinWriter() // No error can occure while encoding hashable fields. b.encodeHashableFields(buf.BinWriter) @@ -106,7 +106,7 @@ func (b *Base) GetHashableData() []byte { // Since MerkleRoot already contains the hash value of all transactions, // the modification of transaction will influence the hash value of the block. func (b *Base) createHash() { - bb := b.GetHashableData() + bb := b.GetSignedPart() b.verificationHash = hash.Sha256(bb) b.hash = hash.Sha256(b.verificationHash.BytesBE()) } diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index f8dad727a..3ddb1796e 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -2057,5 +2057,12 @@ func (bc *Blockchain) secondsPerBlock() int { } func (bc *Blockchain) newInteropContext(trigger trigger.Type, d dao.DAO, block *block.Block, tx *transaction.Transaction) *interop.Context { - return interop.NewContext(trigger, bc, d, block, tx, bc.log) + ic := interop.NewContext(trigger, bc, d, block, tx, bc.log) + switch { + case tx != nil: + ic.Container = tx + case block != nil: + ic.Container = block + } + return ic } diff --git a/pkg/core/helper_test.go b/pkg/core/helper_test.go index b1a69871f..198145cf2 100644 --- a/pkg/core/helper_test.go +++ b/pkg/core/helper_test.go @@ -79,7 +79,7 @@ func newBlock(cfg config.ProtocolConfiguration, index uint32, prev util.Uint256, if err != nil { panic(err) } - b := b.GetHashableData() + b := b.GetSignedPart() sig := pKey.Sign(b) if len(sig) != 64 { panic("wrong signature length") diff --git a/pkg/core/interop_system.go b/pkg/core/interop_system.go index 116a65b54..396534c8a 100644 --- a/pkg/core/interop_system.go +++ b/pkg/core/interop_system.go @@ -246,7 +246,7 @@ func txGetHash(ic *interop.Context, v *vm.VM) error { // engineGetScriptContainer returns transaction that contains the script being // run. func engineGetScriptContainer(ic *interop.Context, v *vm.VM) error { - v.Estack().PushVal(vm.NewInteropItem(ic.Tx)) + v.Estack().PushVal(vm.NewInteropItem(ic.Container)) return nil }