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

Implement native Notary contract #3178

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open

Implement native Notary contract #3178

wants to merge 30 commits into from

Conversation

AnnaShaleva
Copy link
Member

@AnnaShaleva AnnaShaleva commented Mar 19, 2024

Description

Implement native Notary contract.

Close #2425. Depends on #3175 (will rebase this PR after #3175 merge). Tests are in progress, but the code is ready for review.

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

  • Native Gas contract unit tests;
  • Native Notary contract unit tests.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules:
    • neo-modules update
    • neo-devpack-dotnet-update

AnnaShaleva and others added 8 commits March 6, 2024 12:00
Close #2896. Use a stub for native Notary contract hash since this
contract is not implemented yet. Thus, technically, NotaryAssisted
attribute verification will always fail on real network until native
Notary is implemented.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
…ribute

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
Transactions network fee should be split between Primary node and Notary
nodes.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
Once Notary contract is implemented, this hash will be replaced by a
proper Notary contract hash. The exact value won't be changed since
Notary contract has constant hash as any other native contract.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
No functional changes, just a refactoring for better code readability.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
Close #2897. Depends on #3175.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
@vncoelho
Copy link
Member

Is this PR to be merged now or after next release?
I was planning to review current release and then merge these next feature.

@roman-khimov
Copy link
Contributor

Is this PR to be merged now or after next release?

https://github.com/neo-project/neo/milestone/2

src/Neo/SmartContract/Native/GasToken.cs Show resolved Hide resolved
src/Neo/SmartContract/Native/Notary.cs Show resolved Hide resolved
src/Neo/SmartContract/Native/Notary.cs Show resolved Hide resolved
src/Neo/SmartContract/Native/Notary.cs Outdated Show resolved Hide resolved
src/Neo/SmartContract/Native/Notary.cs Show resolved Hide resolved
@dusmart
Copy link

dusmart commented Mar 21, 2024

This contract has a Verify method which is very dangerous.

private bool Verify(ApplicationEngine engine, byte[] sig)

In this method, we verify that tx.Signers[1] has enough balance stored in the contract. Plus, we verify that a signature from any notary is provided.

Here is an attack vector. A malicious notary can sign as many transactions as it wants and then publish at most 500 txs on chain while tx.Signers[1] has a little balance only sufficient for one tx.

If it's not a malicious notary, someone could still get a chance to make the notary sign something multiple times and cache them then publish them at once.

By the way, do you know how many core modules will be affected by this notary feature? Is this the last PR?

Copy link
Member

@vncoelho vncoelho left a comment

Choose a reason for hiding this comment

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

I am not seeing the part of the code we discussed on Discord, @AnnaShaleva, you mentioned about a delegated powered notary signing.
"The contract itself don't send the transactions. It's a designated Notary node who is powered to send transactions on behalf of notary service users. "

I want to check that because it should be, at least, similar to the oracles design.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
No functional changes, just a refactoring.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
@AnnaShaleva
Copy link
Member Author

By the way, do you know how many core modules will be affected by this notary feature? Is this the last PR?

To be able to process existing NeoFS chains that use Notary - yes, it's the last PR. But ideally in future we'd like to implement P2PNotaryRequest payload with pool (ref. nspcc-dev/neo-go#1546) and Notary service plugin (ref. nspcc-dev/neo-go#1547). We'll add related issues to neo-project later.

"The contract itself don't send the transactions. It's a designated Notary node who is powered to send transactions on behalf of notary service users. "
I want to check that because it should be, at least, similar to the oracles design.

It's a part of Notary service plugin. See the example implementation in https://github.com/nspcc-dev/neo-go/blob/master/pkg/services/notary/notary.go.

Copy link
Contributor

@vang1ong7ang vang1ong7ang left a comment

Choose a reason for hiding this comment

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

as @dusmart said , verify method should be used with extreme caution. and is there a fork introduced?

@roman-khimov
Copy link
Contributor

verify method should be used with extreme caution

That's a valid concern, but there are multiple ways to handle it, we'll get to it after #3175 merge.

@AnnaShaleva
Copy link
Member Author

Updated to fresh master, more tests added.

No functional changes, I just finally made my code analizer work
properly.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
Co-authored-by: Shargon <shargon@gmail.com>
cschuchardt88
cschuchardt88 previously approved these changes Apr 11, 2024
cschuchardt88 and others added 2 commits May 23, 2024 05:57
Fetch changes from the fresh master and fix build errors.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
@AnnaShaleva
Copy link
Member Author

@neo-project/core, a batch of tests is added, rebased onto fresh master and ready for review.

@vang1ong7ang
Copy link
Contributor

me not in favor of this pr but me won't stop other people from liking it

however, at least, maintain it as a hardfork

same as #3175

@roman-khimov
Copy link
Contributor

#3175 is HF-free to me (in that it can't be probed from contracts), but what I've said numerous times about these PRs (and the reason I wanted them in 3.7) is that we want to ensure C# node can process NeoFS chains. We've got two of them:

https://github.com/neo-project/neo/blob/master/src/Neo.CLI/config.fs.testnet.json
https://github.com/neo-project/neo/blob/master/src/Neo.CLI/config.fs.mainnet.json

And they can't be processed unless Notary is available (from the genesis for testnet and at some height around a year ago for mainnet). That's why I specifically wanted to have this contract enabled at the genesis block. However, testnet likely can survive another HF enabled at 0 (like it has all of A/B/C at 0 now and it's not a problem). I have an idea about mainnet FS chain as well, luckily it switches to the notary at some height after the Aspidochelone HF, so maybe we can move B/C HF heights retrospectively and if D is to be compatible with FS chain (likely it'll be) then we could arrange safe (for FS chain) enablement of this contract at D. No guarantees, but we'll try to check it.

@AnnaShaleva
Copy link
Member Author

however, at least, maintain it as a hardfork

Good, then let us check if NeoFS networks are compatible with hardfork-dependent Notary contract. I'll write the results here and update this PR to enable Notary contract starting from the D hardfork.

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.

None yet

9 participants