CityOfZion / neon-js

Javascript libraries that allow the applications to interact with NEO blockchain
https://docs.coz.io/neo3/neon-js/index.html
MIT License
183 stars 165 forks source link

Invalid checksum error when deploy contract(version3.6.2) #928

Open Tobeyw opened 3 months ago

Tobeyw commented 3 months ago

When we deployed the 3.6.2 version contract withneonjs, aninvalid checksum error occurred. I found that the latest version of n3 compiler 3.6.2 deleted the MaxScriptLength field of the nefFile file, which changed the calculation method of chenkSum. I guess it may be related to this. https://github.com/neo-project/neo/commit/efa86592d080ebfde685bc87a26177c5bed5431f#diff-e5a9d7d849aceff46a01663d9e6246d09c4c82e49af60f21dc879d05c40481ee

image

ixje commented 3 months ago

The format of the NEF hasn't changed with that commit. It seems to only change the allowed size of the script field from 512*1024 (as defined by MaxScriptLength) to ushort.max * 2 (as defined by ExecutionEngineLimits.Default.MaxItemSize).

I'll try out the new 3.6.2. compiler and see if I can reproduce

luc10921 commented 3 months ago

I tried running the fromBuffer method using my NEF file generated with the 3.6.2 compiler and it worked.

    const myNef = sc.NEF.fromBuffer(
      readFileSync(
        "path\\to\\nef\\file"
      )
    )

Do you know which neon-js version you are using?

Tobeyw commented 3 months ago

@cityofzion/neon-js": "^5.5.1", This is the compiled file of the tested contract. contract.zip I tried to deploy the contract using other methods and it worked.

ixje commented 3 months ago

Can you please share the code snippet used that caused the error and also what you now use that works? The checksum in the file seems correct, so this is a strange case and we need a bit more information to investigate.

Tobeyw commented 3 months ago

This is the code I deploy the contract with neon-js. neonjs

This is the code I deploy the contract with C# and it worked.

ixje commented 3 months ago

The neonjs code is loading a different file (\Neo3ContractTest.nef) than what the C# code is loading (SampleHelloWorld, link). You previously shared SampleHelloWorld and that file is correct. I can't say anything about Neo3ContractTest.nef

Tobeyw commented 3 months ago

This is what I tested with other versions of the contract. It has not been updated. The code is the same, just the files are different. Please ignore it.

luc10921 commented 3 months ago

The problem was occurring because neon-js had a problem when deserializing a compiler that uses all 64 available characters

And since the compiler you are using is probably some version from the master branch instead of the one at NuGet, the compiler name occupies all 64 chars (Neo.Compiler.CSharp 3.6.2+c9ccbb646657240053065ec7c7ff02f106d...).

I created a PR to fix this problem.