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

Wallet: allow to use invocation script for contract-based witness verification inside CalculateNetworkFee method #2412

Closed
AnnaShaleva opened this issue Mar 26, 2021 · 0 comments · Fixed by #2414
Labels
Discussion Initial issue state - proposed but not yet accepted

Comments

@AnnaShaleva
Copy link
Member

Summary or problem description
calculatenetworkfee RPC method can provide transaction with partially-filled witnesses to Wallet.CalculateNetworkFee. But in case of contract-based witness verification, only a contract verification script will be used, although we can easily get invocation script from the provided transaction witnesses.

I.e. here we don't load invocation script and use only contract verification script:

// Check verify cost
using ApplicationEngine engine = ApplicationEngine.Create(TriggerType.Verification, tx, snapshot.CreateSnapshot(), settings: ProtocolSettings);
engine.LoadContract(contract, md, CallFlags.ReadOnly);
if (engine.Execute() == VMState.FAULT) throw new ArgumentException($"Smart contract {contract.Hash} verification fault.");
if (!engine.ResultStack.Pop().GetBoolean()) throw new ArgumentException($"Smart contract {contract.Hash} returns false.");

networkFee += engine.GasConsumed;

As a result, if the contract-based witness requires arguments for verify method (i.e. has non-zero invocation script), then we can't calculate network fee for this witness.

Do you have any solution you want to propose?
Lat's use invocation script from the provided transaction's witness for contract-based verification inside Wallet.CalculateNetworkFee:

// Check verify cost
using ApplicationEngine engine = ApplicationEngine.Create(TriggerType.Verification, tx, snapshot.CreateSnapshot(), settings: ProtocolSettings);
engine.LoadContract(contract, md, CallFlags.ReadOnly);

engine.LoadScript(tx.Witnesses[i].InvocationScript, configureState: p => p.CallFlags = CallFlags.None);

if (engine.Execute() == VMState.FAULT) throw new ArgumentException($"Smart contract {contract.Hash} verification fault.");
if (!engine.ResultStack.Pop().GetBoolean()) throw new ArgumentException($"Smart contract {contract.Hash} returns false.");

networkFee += engine.GasConsumed;

Neo Version

  • Neo 3

Where in the software does this update applies to?

  • RPC (HTTP): calculatenetworkfee method
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Discussion Initial issue state - proposed but not yet accepted
Projects
None yet
1 participant