Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

native: fix contract hashes #1616

Merged
merged 2 commits into from
Dec 15, 2020
Merged

native: fix contract hashes #1616

merged 2 commits into from
Dec 15, 2020

Conversation

fyrchik
Copy link
Contributor

@fyrchik fyrchik commented Dec 14, 2020

They use fictive sender now.

@codecov
Copy link

codecov bot commented Dec 14, 2020

Codecov Report

Merging #1616 (dda4ba8) into master (42be00b) will increase coverage by 0.18%.
The diff coverage is 77.77%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1616      +/-   ##
==========================================
+ Coverage   82.35%   82.54%   +0.18%     
==========================================
  Files         241      241              
  Lines       19022    19018       -4     
==========================================
+ Hits        15666    15698      +32     
+ Misses       2366     2335      -31     
+ Partials      990      985       -5     
Impacted Files Coverage Δ
pkg/core/state/contract.go 82.53% <71.42%> (-1.39%) ⬇️
pkg/core/interop/context.go 95.74% <100.00%> (-0.34%) ⬇️
pkg/core/native/oracle.go 81.46% <100.00%> (+0.80%) ⬆️
pkg/network/metrics/metrics.go 63.63% <0.00%> (-18.19%) ⬇️
pkg/vm/vm.go 93.88% <0.00%> (+0.09%) ⬆️
pkg/consensus/consensus.go 68.50% <0.00%> (+0.64%) ⬆️
pkg/crypto/keys/publickey.go 85.00% <0.00%> (+1.11%) ⬆️
pkg/core/interop/crypto/ecdsa.go 100.00% <0.00%> (+38.09%) ⬆️
pkg/core/interop/crypto/hash.go 100.00% <0.00%> (+84.21%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 42be00b...dda4ba8. Read the comment docs.

@@ -1657,12 +1657,12 @@ var (
func (bc *Blockchain) initVerificationVM(ic *interop.Context, hash util.Uint160, witness *transaction.Witness) error {
v := ic.VM
if len(witness.VerificationScript) != 0 {
if witness.ScriptHash() != hash {
return ErrWitnessHashMismatch
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change really needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this was only to get a specific error in test. I think we can remove the second check now, while leaving the test.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any test being changed, so we either need that change or don't need this one.

@@ -113,7 +114,7 @@ func NewContractMD(name string) *ContractMD {
emit.Syscall(w.BinWriter, interopnames.NeoNativeCall)

c.Script = w.Bytes()
c.Hash = hash.Hash160(c.Script)
c.Hash = state.CreateContractHash(hash.Hash160([]byte{byte(opcode.PUSH1)}), c.Script)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We better merge #1610 now first and then this one. And add some test that specifically checks for native contract's hashes and compares them to known values from C# devpack (see neo-project/neo-devpack-dotnet#391).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can also add some method like CreateNativeContractHash(name string) to reduce code duplication between native contracts.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took it directly from C# node, devpack has outdated values. Fixed.

Copy link
Member

@roman-khimov roman-khimov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking change and we need it to be merged ASAP.

@@ -119,7 +118,7 @@ func NewContractMD(name string) *ContractMD {
emit.Syscall(w.BinWriter, interopnames.SystemContractCallNative)

c.Script = w.Bytes()
c.Hash = hash.Hash160(c.Script)
c.Hash = state.CreateNativeContractHash(c.Script)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CreateNativeContractHash(name string), move all these binwriter things into the function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@@ -1657,12 +1657,12 @@ var (
func (bc *Blockchain) initVerificationVM(ic *interop.Context, hash util.Uint160, witness *transaction.Witness) error {
v := ic.VM
if len(witness.VerificationScript) != 0 {
if witness.ScriptHash() != hash {
return ErrWitnessHashMismatch
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any test being changed, so we either need that change or don't need this one.

@roman-khimov roman-khimov added this to the v0.92.0 milestone Dec 15, 2020
@roman-khimov roman-khimov merged commit 7c22578 into master Dec 15, 2020
@roman-khimov roman-khimov deleted the fix/nativehash branch December 15, 2020 10:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants