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 NotaryAssisted transaction attribute #3175

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

Conversation

AnnaShaleva
Copy link
Member

@AnnaShaleva AnnaShaleva commented Mar 6, 2024

Description

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.

Type of change

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

How Has This Been Tested?

  • A group of unit tests for NotaryAssisted attribute.

Checklist:

Close neo-project#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 <[email protected]>
AnnaShaleva added a commit to AnnaShaleva/neo-devpack-dotnet that referenced this pull request Mar 6, 2024
AnnaShaleva added a commit to AnnaShaleva/neo-modules that referenced this pull request Mar 6, 2024
@AnnaShaleva
Copy link
Member Author

I'm not allowed to request review, set labels or resolve conversations. Maybe someone from neo-project with access rights can allow me at least to request review?

@shargon
Copy link
Member

shargon commented Mar 6, 2024

I'm not allowed to request review, set labels or resolve conversations. Maybe someone from neo-project with access rights can allow me at least to request review?

You didn't accept your role xD, I sent you an invitation time ago... Time to review your email? 😄

@Jim8y
Copy link
Contributor

Jim8y commented Mar 6, 2024

Hi @AnnaShaleva , we are trying to add as much comments in the core as possible, may you please add comments to explain CalculateNetworkFee.

@AnnaShaleva
Copy link
Member Author

may you please add comments to explain CalculateNetworkFee.

Sure, fixed.

@AnnaShaleva AnnaShaleva requested review from shargon and Jim8y March 6, 2024 15:12
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.

GAS.OnPersist change is missing for the attribute.

Transactions network fee should be split between Primary node and Notary
nodes.

Signed-off-by: Anna Shaleva <[email protected]>
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 <[email protected]>
@AnnaShaleva
Copy link
Member Author

GAS.OnPersist change is missing for the attribute.

Completely forgot about it, fixed.

@AnnaShaleva AnnaShaleva requested a review from roman-khimov March 7, 2024 09:41
@vncoelho
Copy link
Member

vncoelho commented Mar 7, 2024

Maybe this PR we merge after next release.

@AnnaShaleva
Copy link
Member Author

Maybe this PR we merge after next release.

This PR doesn't hurt because currently in real network NotaryAssisted attribute is always invalid since transaction must have Notary contract as a signer, and Notary contract is not implemented yet.

Thus, I vote to merge it before 3.7. What do you think?

@roman-khimov
Copy link
Contributor

It goes step by step, @vncoelho. What this delay would buy us? The attribute logic is rather simple on its own.

roman-khimov
roman-khimov previously approved these changes Mar 7, 2024
Copy link
Member

@shargon shargon left a comment

Choose a reason for hiding this comment

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

I need more time to review the notary proposal, honestly, I didn't expect it to be merged in 3.7 and it is already beginning to produce changes in the core

AnnaShaleva and others added 2 commits January 23, 2025 17:00
Related to additional storage entries added by the previous changes.

Signed-off-by: Anna Shaleva <[email protected]>
var notaryAssisted = tx.GetAttribute<NotaryAssisted>();
if (notaryAssisted is not null)
{
totalNetworkFee -= (notaryAssisted.NKeys + 1) * Policy.GetAttributeFee(engine.SnapshotCache, (byte)notaryAssisted.Type);
Copy link
Member

Choose a reason for hiding this comment

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

@AnnaShaleva AttributeFee in memory pool can be 1, and during the block persistence can be changed to 2, this could underflow totalNetworkFee and produce a denial of service.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can't happen. It's OnPersist and it's executed before any in-block transaction, the value is the same as was used when verifying the transaction.

Copy link
Contributor

Choose a reason for hiding this comment

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

BTW, it's pretty similar to tx.Sender having enough GAS on his account to pay for tx.SystemFee + tx.NetworkFee, same guarantee level.

Copy link
Member Author

Choose a reason for hiding this comment

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

@shargon, do you still have any concern about this issue?

Copy link
Member

Choose a reason for hiding this comment

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

I'm agree with @roman-khimov, it will be the same as other attributes, and other fees, but i'm not sure if this is the best way to recollect fees, why not deposit the Gas in the contract as a fee during the execution of the contract (like a regular contract can do)?

var notaryAssisted = tx.GetAttribute<NotaryAssisted>();
if (notaryAssisted is not null)
{
totalNetworkFee -= (notaryAssisted.NKeys + 1) * Policy.GetAttributeFee(engine, (byte)notaryAssisted.Type);
Copy link
Member

Choose a reason for hiding this comment

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

I'm agree with @roman-khimov, it will be the same as other attributes, and other fees, but i'm not sure if this is the best way to recollect fees, why not deposit the Gas in the contract as a fee during the execution of the contract (like a regular contract can do)?

Copy link
Contributor

Choose a reason for hiding this comment

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

You mean deducting this GAS from the user's balance in Notary? This doesn't work in a scenario when third party pays for execution or any other when user is not even signing (as in being a proper signer) the main transaction. Our FS chain transactions are routinely created with the following set of signers:

  • proxy contract (holding a lot of GAS)
  • alphabet (~validators) multisig
  • (optionally) SN key

Transactions generated by IR have two signers, transactions generated by SNs can have three. Either way Proxy contract pays for execution and that's one of the core features for us (hi, #2577), if that wasn't the case we'd have a lot of problems with GAS distribution and spending between all parties (IR/SN). We do have some distribution still, but mostly that's just moving all GAS to proxy because normally IR and SN shouldn't spend any GAS at all from their accounts. Once they've deposited some to the Notary contract and if they're sending correct transactions (IR checks them before approval of course) everything is paid for by the Proxy contract.

So we want to get this fee from the network fee and not some notary account, it's not possible in some cases. We also have a concept of paid attributes now and this just redistributes this attribute fee in a bit more specific manner.

shargon and others added 6 commits February 19, 2025 20:20
* EC Recover

* Clean code

* Fix ut

* Fix ut

* Unify hashing

* Allow HashAlgorithm.None

* Clean comment

* Update src/Neo/Cryptography/Crypto.cs

* Fix merge

* Add None check

* Fix GetHash

* fix unit testing issues

* Clean code

* Update src/Neo/SmartContract/Native/CryptoLib.cs

---------

Co-authored-by: Jimmy <[email protected]>
* tests: add UT for nested WitnessCondition

This just works as the code works.

Signed-off-by: Roman Khimov <[email protected]>

* WitnessCondition: unify nesting checks, fix MaxNestingDepth

1. We have some duplication around "maxNestDepth <= 0" checks.
2. If we're to fix them by moving to DeserializeFrom() and thereby affecting
   all types of conditions we can discover a simple truth about conditions
   that was hidden previously: our real supported MaxNestingDepth is 3, not 2.
3. Test_WitnessCondition_Nesting works as before, check it there, we have
   And->And->Boolean and other nesting cases, 3-4 elements in the chain,
   not 2.

Signed-off-by: Roman Khimov <[email protected]>

* WitnessCondition: unify JSON parsing as well

Signed-off-by: Roman Khimov <[email protected]>

* tests: s/WitnessContition/WitnessCondition/

Fix typo.

Signed-off-by: Roman Khimov <[email protected]>

* Format header

* Format arrays in UT_WitnessCondition.cs

---------

Signed-off-by: Roman Khimov <[email protected]>
Co-authored-by: Shargon <[email protected]>
Co-authored-by: Christopher Schuchardt <[email protected]>
Co-authored-by: NGD Admin <[email protected]>
* Add Support for plugin loading

* Added @shargon request of changes

---------

Co-authored-by: Shargon <[email protected]>
Co-authored-by: NGD Admin <[email protected]>
* Optimize key builder

* Optimize with GetSpan

* Use Span

* Clean

* Rename

* Update src/Neo/SmartContract/KeyBuilder.cs

Co-authored-by: nan01ab <[email protected]>

* Update KeyBuilder.cs

* @cschuchardt88 feedback

* Avoid ToArray in StorageKey constructor

* Use sizeof

* Optimize ECPoint

* Optimize ECPoint

* Add ISerializableSpan

* Move to StorageKey

* Use ReadOnlySpan

---------

Co-authored-by: nan01ab <[email protected]>
Co-authored-by: Christopher Schuchardt <[email protected]>
* Add some stuff to hope once and for all fix the linux workflows

* update workflow

* update nuget.yml

* Change dig to detailed, log too big

* Fix targets

* revert main.yml

* Update .github/workflows/main.yml

* disable BuildInParallel

---------

Co-authored-by: Jimmy <[email protected]>
Co-authored-by: Shargon <[email protected]>
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.

Add a NotaryAssisted transaction attribute
8 participants