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

fix hardfork issues #3234

Merged
merged 11 commits into from
May 16, 2024
Merged

fix hardfork issues #3234

merged 11 commits into from
May 16, 2024

Conversation

Jim8y
Copy link
Contributor

@Jim8y Jim8y commented May 15, 2024

Description

This pr fixes the hardfork issue in the 3.7.

Fixes # (issue)

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Test Configuration:

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

@Jim8y Jim8y marked this pull request as draft May 15, 2024 00:24
@Jim8y Jim8y requested a review from NGDAdmin May 15, 2024 00:25
@Jim8y Jim8y marked this pull request as ready for review May 15, 2024 00:44
@vang1ong7ang
Copy link
Contributor

is the manifests of native contracts fixed?

@vang1ong7ang
Copy link
Contributor

@Jim8y I think the commit c1af443 introduces trouble

src/Neo/SmartContract/Native/NativeContract.cs Outdated Show resolved Hide resolved
@@ -43,6 +43,9 @@ public ECPoint[] GetDesignatedByRole(DataCache snapshot, Role role, uint index)
throw new ArgumentOutOfRangeException(nameof(role));
if (Ledger.CurrentIndex(snapshot) + 1 < index)
throw new ArgumentOutOfRangeException(nameof(index));
// Fix hardfork for https://github.com/neo-project/neo/pull/3172
if (role == Role.P2PNotary && !ProtocolSettings.Custom.IsHardforkEnabled(Hardfork.HF_Cockatrice, Ledger.CurrentIndex(snapshot)))
Copy link
Contributor

Choose a reason for hiding this comment

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

Breaks NeoFS chains immediately. I've tried to explain why we're doing it this way numerous times, but looks like no one cares about NeoFS and compatibility.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

breaks neofs or break the mainnet, this is a problem. We will have it but can not make it take effect untill we have the fork.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please, revert #3172 then. It causes more problems than it solves with this HF logic.

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 can only be exploited by committee. Nasty committee.

Copy link
Member

@AnnaShaleva AnnaShaleva May 15, 2024

Choose a reason for hiding this comment

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

BTW, it can only be exploited by committee. Nasty committee.

Hardly ever committee will designate this role before Notary subsystem implementation is finished. Thus, I'd vote for keeping P2PNotary role without binding to hardfork.

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 can only be exploited by committee

Sorry, not exactly. getDesignatedByRole will return empty array instead of failing.

Copy link
Contributor

@vang1ong7ang vang1ong7ang May 15, 2024

Choose a reason for hiding this comment

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

Please, revert #3172 then. It causes more problems than it solves with this HF logic.

I think reverting #3172 is better than fixing. maybe #3172 can be introduced back after there's good way for node upgrading

@@ -23,12 +23,19 @@ internal class ContractMethodAttribute : Attribute
public long CpuFee { get; init; }
public long StorageFee { get; init; }
public Hardfork? ActiveIn { get; init; } = null;
public Hardfork? DeprecatedIn { get; init; } = null;
Copy link
Member

Choose a reason for hiding this comment

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

BTW, this is a part of #3210. Add a reference to the PR description, please.

Copy link
Member

Choose a reason for hiding this comment

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

Also, we need the same functionality to be implemented for events. It's not hard to extend it, read the original issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This pr is a hotpatch for the hf issues, i prefer to keep it as simple as possible.

Copy link
Member

Choose a reason for hiding this comment

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

Ref. #3210 (comment) as TODO.

Copy link
Member

Choose a reason for hiding this comment

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

Rename to ActiveTil?


public ContractMethodAttribute() { }

public ContractMethodAttribute(Hardfork activeIn)
{
ActiveIn = activeIn;
}

public ContractMethodAttribute(bool isDeprecated, Hardfork deprecatedIn)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public ContractMethodAttribute(bool isDeprecated, Hardfork deprecatedIn)
public ContractMethodAttribute(Hardfork? activeIn, Hardfork deprecatedIn)

I'd suggest to use this option, and just put null as the first argument for those methods that were always active but need to be deprecated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Existing solution already works, i may update it after we have confirmed that this pr works fine.

Copy link
Member

Choose a reason for hiding this comment

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

Ref. #3210 (comment) as TODO.


// This is for solving the hardfork issue in https://github.com/neo-project/neo/pull/3209
[ContractMethod(true, Hardfork.HF_Cockatrice, CpuFee = 1 << 15)]
public static bool VerifyWithECDsa(byte[] message, byte[] pubkey, byte[] signature, NamedCurve curve)
Copy link
Member

Choose a reason for hiding this comment

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

You may safely get rid of NamedCurve type here and use NamedCurveHash, just check that curve falls within the expected range (22 or 23) and throw if not. You can do this because NamedCurveHash is compatible. If you implement this, then no 'NamedCurve' is obsolete linter warnings will be raised.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a hotpatch, i prefer to keep it simple and use original logic as much as possible.

Copy link
Member

Choose a reason for hiding this comment

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

Every TODO is an issue, otherwise it won't be done. See #3236.

src/Neo/SmartContract/Native/NeoToken.cs Show resolved Hide resolved
@vang1ong7ang
Copy link
Contributor

manifest of NeoToken contract still causes fork

event CommitteeChanged should be fixed

Copy link
Member

@superboyiii superboyiii left a comment

Choose a reason for hiding this comment

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

Tested OK. This fixed.

cschuchardt88
cschuchardt88 previously approved these changes May 16, 2024

// This is for solving the hardfork issue in https://github.com/neo-project/neo/pull/3209
[ContractMethod(true, Hardfork.HF_Cockatrice, CpuFee = 1 << 15)]
public static bool VerifyWithECDsa(byte[] message, byte[] pubkey, byte[] signature, NamedCurve curve)
Copy link
Member

Choose a reason for hiding this comment

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

Every TODO is an issue, otherwise it won't be done. See #3236.

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.

Seems good to me, only the rename to ActiveTil, but also it's ok like this

@NGDAdmin NGDAdmin merged commit d56d4eb into neo-project:master May 16, 2024
6 checks passed

if (!newCommittee.SequenceEqual(prevCommittee))
// Hardfork check for https://github.com/neo-project/neo/pull/3158
// New notification will case 3.7.0 and 3.6.0 have different behavior
Copy link
Member

Choose a reason for hiding this comment

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

will case?

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.

Good job @Jim8y

The deprecatedIn function was really needed for many cases and pending to be done!

AnnaShaleva added a commit that referenced this pull request May 20, 2024
DeprecatedIn hardfork of every native method (if not null) should be
included into the set of used hardforks, otherwise no contract update
will be performed on this hardfork activation:

https://github.com/neo-project/neo/blob/08f2dfc56762bb43be33e873bc3659bad368d4d6/src/Neo/SmartContract/Native/NativeContract.cs#L284

This commit should be a part of #3234 and a part of 3.7.4. Luckily, this new
DeprecatedIn functionality is used only for the old native CryptoLib's
verifyWithECDsa method with Cockatrice hardfork. And luckily, there are other
CryptoLib's methods with ActiveIn set to Cockatrice hardfork. Due to
these two facts this bug does not affect mainnet/testnet, and thus we don't
need 3.7.5 with this fixincluded, so this fix may safely be postponed to 3.8.0.

Signed-off-by: Anna Shaleva <[email protected]>
AnnaShaleva added a commit that referenced this pull request May 20, 2024
DeprecatedIn hardfork of every native method (if not null) should be
included into the set of used hardforks, otherwise no contract update
will be performed on this hardfork activation:

https://github.com/neo-project/neo/blob/08f2dfc56762bb43be33e873bc3659bad368d4d6/src/Neo/SmartContract/Native/NativeContract.cs#L284

This commit should be a part of #3234 and a part of 3.7.4. Luckily, this new
DeprecatedIn functionality is used only for the old native CryptoLib's
verifyWithECDsa method with Cockatrice hardfork. And luckily, there are other
CryptoLib's methods with ActiveIn set to Cockatrice hardfork. Due to
these two facts this bug does not affect mainnet/testnet, and thus we don't
need 3.7.5 with this fix included. So this fix may safely be postponed to 3.8.0.

Signed-off-by: Anna Shaleva <[email protected]>
AnnaShaleva added a commit that referenced this pull request May 20, 2024
DeprecatedIn hardfork of every native method (if not null) should be
included into the set of used hardforks, otherwise no contract update
will be performed on this hardfork activation:

https://github.com/neo-project/neo/blob/08f2dfc56762bb43be33e873bc3659bad368d4d6/src/Neo/SmartContract/Native/NativeContract.cs#L279-L284

https://github.com/neo-project/neo/blob/08f2dfc56762bb43be33e873bc3659bad368d4d6/src/Neo/SmartContract/Native/ContractManagement.cs#L69-L73

This commit should be a part of #3234 and a part of 3.7.4. Luckily, this new
DeprecatedIn functionality is used only for the old native CryptoLib's
verifyWithECDsa method with Cockatrice hardfork. And luckily, there are other
CryptoLib's methods with ActiveIn set to Cockatrice hardfork. Due to
these two facts this bug does not affect mainnet/testnet, and thus we don't
need 3.7.5 with this fix included. So this fix may safely be postponed to 3.8.0.

Signed-off-by: Anna Shaleva <[email protected]>
shargon added a commit that referenced this pull request May 21, 2024
DeprecatedIn hardfork of every native method (if not null) should be
included into the set of used hardforks, otherwise no contract update
will be performed on this hardfork activation:

https://github.com/neo-project/neo/blob/08f2dfc56762bb43be33e873bc3659bad368d4d6/src/Neo/SmartContract/Native/NativeContract.cs#L279-L284

https://github.com/neo-project/neo/blob/08f2dfc56762bb43be33e873bc3659bad368d4d6/src/Neo/SmartContract/Native/ContractManagement.cs#L69-L73

This commit should be a part of #3234 and a part of 3.7.4. Luckily, this new
DeprecatedIn functionality is used only for the old native CryptoLib's
verifyWithECDsa method with Cockatrice hardfork. And luckily, there are other
CryptoLib's methods with ActiveIn set to Cockatrice hardfork. Due to
these two facts this bug does not affect mainnet/testnet, and thus we don't
need 3.7.5 with this fix included. So this fix may safely be postponed to 3.8.0.

Signed-off-by: Anna Shaleva <[email protected]>
Co-authored-by: Shargon <[email protected]>
Jim8y added a commit to Jim8y/neo that referenced this pull request May 25, 2024
…gins

* 'latest-plugins' of github.com:Jim8y/neo: (21 commits)
  fix: custom plugins won't shown by command `plugins` (neo-project#3269)
  COVERALL: Improve maintenance and readbility of some variables (neo-project#3248)
  Update nuget (neo-project#3262)
  [**Part-2**] Neo module/master fixes (neo-project#3244)
  Fix `dotnet pack` error (neo-project#3266)
  Fix and Update devcontainer.json to use Dockerfile  (neo-project#3259)
  Add optimization to template (neo-project#3247)
  Optimize plugin's models (neo-project#3246)
  fix CancelTransaction !signers.Any() (neo-project#3263)
  COVERALL: fix broken by changing report from lcov to cobertura (neo-project#3252)
  fix TraverseIterator count (neo-project#3261)
  Native: include DeprecatedIn hardfork into usedHardforks (neo-project#3245)
  [**Part-1**] `neo-module/master` (neo-project#3232)
  Make `ApplicationEngine.LoadContext` protection level `public` (neo-project#3243)
  improve parse method in neo-cli (neo-project#3204)
  Fix neo-project#3239 (neo-project#3242)
  Neo.CLI: enable hardforks for NeoFS mainnet (neo-project#3240)
  v3.7.4 (neo-project#3237)
  fix hardfork issues (neo-project#3234)
  Update src/Neo.CLI/CLI/MainService.Plugins.cs
  ...

# Conflicts:
#	src/Neo.CLI/CLI/MainService.Plugins.cs
@AnnaShaleva AnnaShaleva mentioned this pull request Jun 28, 2024
15 tasks
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.

9 participants