Skip to content

Commit

Permalink
Merge pull request #727 from nspcc-dev/fix-wrong-endian-in-interop-ha…
Browse files Browse the repository at this point in the history
…shes

core: fix wrong endian used in interop functions
  • Loading branch information
roman-khimov committed Mar 6, 2020
2 parents 6543f20 + a9abd3d commit 0e8ff55
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions pkg/core/interop_neo.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (ic *interopContext) headerGetMerkleRoot(v *vm.VM) error {
if err != nil {
return err
}
v.Estack().PushVal(header.MerkleRoot.BytesLE())
v.Estack().PushVal(header.MerkleRoot.BytesBE())
return nil
}

Expand All @@ -70,7 +70,7 @@ func (ic *interopContext) headerGetNextConsensus(v *vm.VM) error {
if err != nil {
return err
}
v.Estack().PushVal(header.NextConsensus.BytesLE())
v.Estack().PushVal(header.NextConsensus.BytesBE())
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/core/interop_neo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func TestHeaderGetMerkleRoot(t *testing.T) {
err := context.headerGetMerkleRoot(v)
require.NoError(t, err)
value := v.Estack().Pop().Value()
require.Equal(t, block.MerkleRoot.BytesLE(), value)
require.Equal(t, block.MerkleRoot.BytesBE(), value)
}

func TestHeaderGetNextConsensus(t *testing.T) {
Expand All @@ -157,7 +157,7 @@ func TestHeaderGetNextConsensus(t *testing.T) {
err := context.headerGetNextConsensus(v)
require.NoError(t, err)
value := v.Estack().Pop().Value()
require.Equal(t, block.NextConsensus.BytesLE(), value)
require.Equal(t, block.NextConsensus.BytesBE(), value)
}

func TestTxGetAttributes(t *testing.T) {
Expand Down
10 changes: 5 additions & 5 deletions pkg/core/interop_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func getBlockHashFromElement(bc Blockchainer, element *vm.Element) (util.Uint256
}
hash = bc.GetHeaderHash(int(hashint))
} else {
return util.Uint256DecodeBytesLE(hashbytes)
return util.Uint256DecodeBytesBE(hashbytes)
}
return hash, nil
}
Expand Down Expand Up @@ -102,7 +102,7 @@ func (ic *interopContext) bcGetHeight(v *vm.VM) error {
// returns transaction and its height if it's present in the blockchain.
func getTransactionAndHeight(cd *cachedDao, v *vm.VM) (*transaction.Transaction, uint32, error) {
hashbytes := v.Estack().Pop().Bytes()
hash, err := util.Uint256DecodeBytesLE(hashbytes)
hash, err := util.Uint256DecodeBytesBE(hashbytes)
if err != nil {
return nil, 0, err
}
Expand Down Expand Up @@ -161,7 +161,7 @@ func (ic *interopContext) headerGetHash(v *vm.VM) error {
if err != nil {
return err
}
v.Estack().PushVal(header.Hash().BytesLE())
v.Estack().PushVal(header.Hash().BytesBE())
return nil
}

Expand All @@ -171,7 +171,7 @@ func (ic *interopContext) headerGetPrevHash(v *vm.VM) error {
if err != nil {
return err
}
v.Estack().PushVal(header.PrevHash.BytesLE())
v.Estack().PushVal(header.PrevHash.BytesBE())
return nil
}

Expand Down Expand Up @@ -238,7 +238,7 @@ func (ic *interopContext) txGetHash(v *vm.VM) error {
if !ok {
return errors.New("value is not a transaction")
}
v.Estack().PushVal(tx.Hash().BytesLE())
v.Estack().PushVal(tx.Hash().BytesBE())
return nil
}

Expand Down

0 comments on commit 0e8ff55

Please sign in to comment.