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

[master-2.x] Fix Transaction verify #2009

Merged
merged 2 commits into from
Oct 26, 2020

Conversation

Qiao-Jin
Copy link
Contributor

Close #1999

@ProDog
Copy link
Contributor

ProDog commented Oct 20, 2020

Tesed OK.

request:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "sendrawtransaction",
  "params": ["d1003314ac61af17b4970b71e7a0317fb50d04b85dde410751c106726566756e64670ef656d72483fab3804c41ea0f052dab8138da170220ac61af17b4970b71e7a0317fb50d04b85dde4107f1207358baa8ddab0186203f06cdf67f9c8e9f90554269fce6d5b5aaa43e792e78840107512de83ec6dd6018f6567591a5e81ecaf68c88b9f9af92394728c19720a9e00100019b7cffdaa674beae0f930ebe6085af9093e5fe56b34a5c220ccdcf6efc336fc500e1f505000000000ef656d72483fab3804c41ea0f052dab8138da17024140604cb63f5f4306124599327ecb6232fe420f22c0a36bc9ebdd2b751d3dc152ce0ef1addcb26b4deee4c1741ee868cb76d127cff898ec971d7ffe8689830905a7232102d9552f201a06e4103a90bdae0caec2def340d721a298bbed3b635d6f70f3dc01ac0352013100"]
}

result:

{
    "jsonrpc": "2.0",
    "id": 1,
    "error": {
        "code": -504,
        "message": "Block or transaction validation failed."
    }
}

@Qiao-Jin Qiao-Jin changed the title Fix Transaction verify [master-2.x] Fix Transaction verify Oct 20, 2020
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.

What about add the try/catch in

Output = tx.Outputs[p.PrevIndex]
and return null

@ZhangTao1596
Copy link
Contributor

ZhangTao1596 commented Oct 20, 2020

base.Verify() before check NetworkFee?
No need add try/catch in Transaction.Verify. It will be check in IsDoubleSpend.

public static bool IsDoubleSpend(this IPersistence persistence, Transaction tx)
{
if (tx.Inputs.Length == 0) return false;
foreach (var group in tx.Inputs.GroupBy(p => p.PrevHash))
{
UnspentCoinState state = persistence.UnspentCoins.TryGet(group.Key);
if (state == null) return true;
if (group.Any(p => p.PrevIndex >= state.Items.Length || state.Items[p.PrevIndex].HasFlag(CoinState.Spent)))
return true;
}
return false;

Or we can split UTXO verify and witness verify. We need UTXO verify before get references.

@Qiao-Jin
Copy link
Contributor Author

What about add the try/catch in

Output = tx.Outputs[p.PrevIndex]

and return null

Fixed

@ProDog
Copy link
Contributor

ProDog commented Oct 23, 2020

Tested OK.

@Qiao-Jin
Copy link
Contributor Author

@shargon @erikzhang Can we merge this one?

@shargon shargon merged commit 9b0391d into neo-project:master-2.x Oct 26, 2020
Qiao-Jin pushed a commit to Qiao-Jin/neo that referenced this pull request Nov 18, 2020
shargon pushed a commit that referenced this pull request Nov 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants