Skip to content

Copy Abi into nef file and use nef for scriptHash#1973

Closed
shargon wants to merge 42 commits intomasterfrom
abi-to-nef
Closed

Copy Abi into nef file and use nef for scriptHash#1973
shargon wants to merge 42 commits intomasterfrom
abi-to-nef

Conversation

@shargon
Copy link
Member

@shargon shargon commented Sep 25, 2020

Related to #1961 (comment)
Produce changes in neo-project/proposals#121 (review)
Close #2002

@shargon shargon requested a review from erikzhang September 25, 2020 13:47
@shargon
Copy link
Member Author

shargon commented Sep 25, 2020

@erikzhang please take a look, I included only the Abi, the manifest it was thought to be modified in order to add some rights, but the abi should be changed only if the script change. So how can the developer change the manifest before create the nef file?

We can remove Abi from the manifest and add the Abi inside ContractState, what do you think?

@shargon shargon requested a review from erikzhang September 30, 2020 09:40
@shargon
Copy link
Member Author

shargon commented Sep 30, 2020

Any update?

@erikzhang
Copy link
Member

There is no way to compute the hash in the ABI. Maybe we should remove it.

Copy link
Contributor

@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.

If we're to go this route then maybe it's easier to put full manifest inside NEF, it'd simplify things a bit for deployment/updates and ContractState will have it too.

There is a more wild idea wrt #1961/#1964 though (or maybe that was meant by #1961 (comment)). Every deployed contract has an ID, storage is using that for keys since #1400, maybe it's time to use it also for invocations/verifications/addresses? We get contracts by hash in the following situations:

  • to create a callback
  • to perform a call
  • to find witness script
  • to create/update contract
  • to return it to the script from GetContract interop
  • to check it for IsStandard interop
  • to check for existence in oracle contract
  • to answer an RPC request

We delete them on update or destroy. Imagine all of the above use cases with an ID instead of a hash (for calls that would be 4-byte IDs, for witnesses 20-byte with lots of zeroes). The only problematic case I see is IsStandard, but even that is probably OK (and this patch breaks it too anyway).

Script (ABI/NEF/whatever) hash is also an address and contracts can receive some tokens to it, but NKuyBkoGdZZSLyPbJEetheRhMjezqzTxcW/NKuyBkoGdZZSLyPbJEetheRhMjezwhg9vh/NKuyBkoGdZZSLyPbJEetheRhMjf17rTWMC/etc are good enough for that purpose.

Collisions? Probably not that different to the current situation.

Maybe I'm missing something, but using IDs can also be an option and it will allow to keep scripts/abi/nefs as is.

@shargon
Copy link
Member Author

shargon commented Sep 30, 2020

There is no way to compute the hash in the ABI. Maybe we should remove it.

Done, but we need it in manifest for check if it's a valid call so I moved it to Manifest.

@shargon
Copy link
Member Author

shargon commented Sep 30, 2020

@roman-khimov

If we're to go this route then maybe it's easier to put full manifest inside NEF, it'd simplify things a bit for deployment/updates and ContractState will have it too.

If you want to update only the manifest, for change rights, you will need a new script?

We delete them on update or destroy. Imagine all of the above use cases with an ID instead of a hash (for calls that would be 4-byte IDs, for witnesses 20-byte with lots of zeroes). The only problematic case I see is IsStandard, but even that is probably OK (and this patch breaks it too anyway).

I like the idea of use the id instead of the hash in some cases (for optimization), but how it solves the main problem?

@roman-khimov
Copy link
Contributor

If you want to update only the manifest, for change rights, you will need a new script?

I thought we're to change from script hash to NEF hash effectively (at least that's my interpretation of #1961 (comment)), thus change in the manifest changes the NEF and the hash. Am I missing something?

I like the idea of use the id instead of the hash in some cases (for optimization), but how it solves the main problem?

By the ability to differentiate script hashes from IDs? I mean regular scripts would have script hash as a signer, for example NTZJ91cwZWiad8uj8sLMF7X6j8Ed41Cim6 (41546d4fee9fe73744a08fc5055d76a88b17d853), this can't be contract ID, thus it must have a corresponding verification script attached and we won't look into the DB for it. Now NKuyBkoGdZZSLyPbJEetheRhMjezqzTxcW (0100000000000000000000000000000000000000) is the opposite, it can't be a hash (sure, technically it can, but good luck with that), so it must not have any verification script and we will take contract №1 to verify that. I know it sounds a bit fishy, but I can't find where this approach breaks.

@erikzhang
Copy link
Member

Then we need to remove ABI from manifest.

@superboyiii
Copy link
Member

@neo-project/ngd-shanghai please, could you test it?

I'll test this after neo-devpack-dotnet is updated.

@shargon
Copy link
Member Author

shargon commented Oct 21, 2020

Please take a look to neo-project/neo-devpack-dotnet#378

@superboyiii
Copy link
Member

superboyiii commented Oct 22, 2020

@superboyiii
Copy link
Member

Compile it successfully and try to deploy it on neo-cli, find magic unmatch...
image

superboyiii added a commit to neo-project/neo-node that referenced this pull request Oct 22, 2020
@shargon
Copy link
Member Author

shargon commented Oct 22, 2020

Compile it successfully and try to deploy it on neo-cli, find magic unmatch...

Did you use a nef file?

@superboyiii
Copy link
Member

superboyiii commented Oct 23, 2020

Compile it successfully and try to deploy it on neo-cli, find magic unmatch...

Did you use a nef file?

Yes, of course.
image

@shargon
Copy link
Member Author

shargon commented Oct 23, 2020

@superboyiii It's a new generated nef file? Could you send me by discord your nef and manifest?

@erikzhang
Copy link
Member

erikzhang commented Oct 25, 2020

I have a simpler idea. We don't need to modify the core, we can make the compiler add an instruction "return false;" before the generated contract to solve this problem.

@superboyiii
Copy link
Member

superboyiii commented Oct 26, 2020

@superboyiii It's a new generated nef file? Could you send me by discord your nef and manifest?

Sure. I upload the whole project here so that you could find the issue clearly. https://packet.azureedge.net/neochain/neo3/neo-PR#1973.zip
I'm using #1973, neo-project/neo-node#676 and neo-project/neo-devpack-dotnet#378. There's a privatenet inside and I'm using nep5 template for test. admin.json is the owner and password is 1. Nef and manifest are all in debug path of neo-cli which is an external node for test and you can rebuild it in ./neo-devpack-dotnet/templates/Template.NEP5.CSharp as well.

@ProDog
Copy link
Contributor

ProDog commented Oct 26, 2020

Compile it successfully and try to deploy it on neo-cli, find magic unmatch...

Yes, reader.ReadUInt32() was 2013333335 when I tested it.

@superboyiii
Copy link
Member

Compile it successfully and try to deploy it on neo-cli, find magic unmatch...

Yes, reader.ReadUInt32() was 2013333335 when I tested it.

Yes, for me is 135056913, it's changing due to different sc. And it should always be 860243278.
@shargon

@shargon
Copy link
Member Author

shargon commented Oct 27, 2020

@superboyiii I will wait for #2021 because maybe we choose a different fix

@superboyiii
Copy link
Member

@superboyiii I will wait for #2021 because maybe we choose a different fix

Fine. But I think this feature might be included in the version after Preview4 because not much time left for release. Do you think it's OK?

@shargon
Copy link
Member Author

shargon commented Oct 29, 2020

Fine. But I think this feature might be included in the version after Preview4 because not much time left for release. Do you think it's OK?

I think that it's the most important one in preview4 🤣

@superboyiii
Copy link
Member

Fine. But I think this feature might be included in the version after Preview4 because not much time left for release. Do you think it's OK?

I think that it's the most important one in preview4 🤣

Then we have to delay Preview4 for several weeks. Only one week left.🤣

@shargon
Copy link
Member Author

shargon commented Oct 29, 2020

@superboyiii We only need to discuss #2021 and we can move foreward.

@roman-khimov
Copy link
Contributor

This or #2021 are very invasive things, so independent of what's going to be the accepted solution it needs as much testing as we could provide. And preview4 is exactly for that, testing in a wider setting, so I'd rather wait a little, but settle this before preview4.

@shargon
Copy link
Member Author

shargon commented Nov 12, 2020

Closed in favor of #2044

@shargon shargon closed this Nov 12, 2020
@shargon shargon deleted the abi-to-nef branch November 12, 2020 17:47
shargon added a commit to neo-project/neo-node that referenced this pull request Dec 1, 2020
* Copy abi to nef

Related: neo-project/neo#1973, neo-project/neo-devpack-dotnet#378

* Update neo-cli/CLI/MainService.cs

* Fix deploy

* fix contract hash (#680)

* update to neo

* Use helper

* Clean usings

Co-authored-by: Shargon <shargon@gmail.com>
Co-authored-by: Vitor Nazário Coelho <vncoelho@gmail.com>
Co-authored-by: Luchuan <luchuan@ngd.neo.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Increase ContractManifest.MaxLength

7 participants