Merge pull request #1251 from nspcc-dev/smartcontract/nef_checksum

smartcontract: calculate double-SHA256 for .nef files
This commit is contained in:
Roman Khimov 2020-08-03 17:29:41 +03:00 committed by GitHub
commit c114c4dd1c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -25,7 +25,7 @@ import (
// | Version | 16 bytes | Compiler version (Major, Minor, Build, Version) |
// | ScriptHash | 20 bytes | ScriptHash for the script (BE) |
// +------------+-----------+------------------------------------------------------------+
// | Checksum | 4 bytes | Sha256 of the header (CRC) |
// | Checksum | 4 bytes | First four bytes of double SHA256 hash of the header |
// +------------+-----------+------------------------------------------------------------+
// | Script | Var bytes | Var bytes for the payload |
// +------------+-----------+------------------------------------------------------------+
@ -177,14 +177,14 @@ func (h *Header) DecodeBinary(r *io.BinReader) {
h.ScriptHash.DecodeBinary(r)
}
// CalculateChecksum returns first 4 bytes of SHA256(Header) converted to uint32.
// CalculateChecksum returns first 4 bytes of double-SHA256(Header) converted to uint32.
func (h *Header) CalculateChecksum() uint32 {
buf := io.NewBufBinWriter()
h.EncodeBinary(buf.BinWriter)
if buf.Err != nil {
panic(buf.Err)
}
return binary.LittleEndian.Uint32(hash.Sha256(buf.Bytes()).BytesBE())
return binary.LittleEndian.Uint32(hash.Checksum(buf.Bytes()))
}
// EncodeBinary implements io.Serializable interface.