-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Optimize VerifyWitness and tx.verify #2054
Merged
erikzhang
merged 24 commits into
neo-project:master
from
Tommo-L:optimize_verify_witness
Dec 7, 2020
Merged
Changes from 17 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
ebd7bff
optimize tx.verify
61ef979
fix 1/2
caa6f3c
fix fee 2/2
9439df7
optimize
0641353
format
4a6f3ae
fix and format
420ee5c
format
ae11bca
fix conflicts
d69d849
optimize
c602f45
Merge branch 'master' into optimize_verify_witness
Tommo-L 91cf47c
Merge branch 'master' into optimize_verify_witness
Tommo-L 52520d2
Merge branch 'master' into optimize_verify_witness
Qiao-Jin ff53a7d
fix conflicts
b675ac4
Merge branch 'optimize_verify_witness' of https://github.com/Tommo-L/…
177cd44
fix
3fabce9
Revert
43324e8
Optimize
shargon c963241
Merge branch 'master' into optimize_verify_witness
Qiao-Jin 67ad746
Update src/neo/SmartContract/Helper.cs
erikzhang fda5a28
Change to Internal
f09512b
Update src/neo/SmartContract/Helper.cs
Tommo-L c340bfc
add MultiSignatureContractCost
7e62e79
Move SignatureCost to tx
cd4969b
format
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -295,17 +295,36 @@ public virtual VerifyResult VerifyStateDependent(StoreView snapshot, Transaction | |
if (!attribute.Verify(snapshot, this)) | ||
return VerifyResult.Invalid; | ||
long net_fee = NetworkFee - Size * NativeContract.Policy.GetFeePerByte(snapshot); | ||
if (!this.VerifyWitnesses(snapshot, net_fee, WitnessFlag.StateDependent)) | ||
return VerifyResult.Invalid; | ||
|
||
UInt160[] hashes = GetScriptHashesForVerifying(snapshot); | ||
if (hashes.Length != witnesses.Length) return VerifyResult.Invalid; | ||
for (int i = 0; i < hashes.Length; i++) | ||
{ | ||
if (witnesses[i].VerificationScript.IsSignatureContract()) | ||
net_fee -= SmartContract.Helper.SignatureContractCost; | ||
else if (witnesses[i].VerificationScript.IsMultiSigContract(out int m, out int n)) | ||
net_fee -= (ApplicationEngine.OpCodePrices[OpCode.PUSHDATA1] * (m + n) + ApplicationEngine.OpCodePrices[OpCode.PUSHINT8] * 2 + ApplicationEngine.OpCodePrices[OpCode.PUSHNULL] + ApplicationEngine.OpCodePrices[OpCode.SYSCALL] + ApplicationEngine.ECDsaVerifyPrice * n); | ||
else | ||
{ | ||
if (!this.VerifyWitness(null, hashes[i], witnesses[i], net_fee, out long fee)) | ||
return VerifyResult.Invalid; | ||
net_fee -= fee; | ||
} | ||
if (net_fee < 0) return VerifyResult.InsufficientFunds; | ||
} | ||
return VerifyResult.Succeed; | ||
} | ||
|
||
public virtual VerifyResult VerifyStateIndependent() | ||
{ | ||
if (Size > MaxTransactionSize) | ||
return VerifyResult.Invalid; | ||
if (!this.VerifyWitnesses(null, NetworkFee, WitnessFlag.StateIndependent)) | ||
return VerifyResult.Invalid; | ||
UInt160[] hashes = GetScriptHashesForVerifying(null); | ||
if (hashes.Length != witnesses.Length) return VerifyResult.Invalid; | ||
for (int i = 0; i < hashes.Length; i++) | ||
if (witnesses[i].VerificationScript.IsStandardContract()) | ||
erikzhang marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we can cache if it's standar inside the witness, otherwise we check it at least twice. |
||
if (!this.VerifyWitness(null, hashes[i], witnesses[i], SmartContract.Helper.MaxVerificationGas, out _)) | ||
erikzhang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return VerifyResult.Invalid; | ||
return VerifyResult.Succeed; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could be any kind of push, same price but just to take care..