core: fix PrevHash calculation for MPTRoot
This was differing from C# notion of PrevHash. It's not a previous root, but rather a hash of the previous serialized MPTRoot structure (that is to be signed by CNs). Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
caea6d6ca8
commit
58b7e16e0e
1 changed files with 3 additions and 2 deletions
|
@ -17,6 +17,7 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/storage"
|
||||
"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/encoding/bigint"
|
||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||
|
@ -648,7 +649,7 @@ func (bc *Blockchain) storeBlock(block *block.Block) error {
|
|||
if err != nil {
|
||||
return errors.WithMessagef(err, "can't get previous state root")
|
||||
}
|
||||
prevHash = prev.Root
|
||||
prevHash = hash.DoubleSha256(prev.GetSignedPart())
|
||||
}
|
||||
err := bc.AddStateRoot(&state.MPTRoot{
|
||||
MPTRootBase: state.MPTRootBase{
|
||||
|
@ -1264,7 +1265,7 @@ func (bc *Blockchain) verifyStateRoot(r *state.MPTRoot) error {
|
|||
prev, err := bc.GetStateRoot(r.Index - 1)
|
||||
if err != nil {
|
||||
return errors.New("can't get previous state root")
|
||||
} else if !prev.Root.Equals(r.PrevHash) {
|
||||
} else if !r.PrevHash.Equals(hash.DoubleSha256(prev.GetSignedPart())) {
|
||||
return errors.New("previous hash mismatch")
|
||||
} else if prev.Version != r.Version {
|
||||
return errors.New("version mismatch")
|
||||
|
|
Loading…
Reference in a new issue