Commit 0156e75
authored
[CON-126] Do not return error string on precompile error (#2563)
## Describe your changes and provide context
### Context
Different precompile error messages lead to app hash.
Reproduction suite:
https://github.com/sei-protocol/sei-chain/pull/2545/files
### Mechanism
`resultsHash` which is part of consensus is derived by hashing
marshalled transaction results, only deterministic fields should be
included during the marshalling
[operation](https://github.com/sei-protocol/sei-chain/blob/fe95a1ff76a108ff37347a16ee6139509322e058/sei-tendermint/abci/types/types.go#L199-L214)
- [error
code](https://github.com/sei-protocol/sei-chain/blob/fe95a1ff76a108ff37347a16ee6139509322e058/sei-tendermint/proto/tendermint/abci/types.proto#L429),
[data](https://github.com/sei-protocol/sei-chain/blob/fe95a1ff76a108ff37347a16ee6139509322e058/sei-tendermint/proto/tendermint/abci/types.proto#L430),
[gas_wanted](https://github.com/sei-protocol/sei-chain/blob/fe95a1ff76a108ff37347a16ee6139509322e058/sei-tendermint/proto/tendermint/abci/types.proto#L433),
[gas_used](https://github.com/sei-protocol/sei-chain/blob/fe95a1ff76a108ff37347a16ee6139509322e058/sei-tendermint/proto/tendermint/abci/types.proto#L434).
Initially I thought that the error code is being [decoded
indeterministically](https://github.com/sei-protocol/sei-chain/blob/06a4e242bf80fff303be607734e121bd2f0f6916/sei-cosmos/types/errors/abci.go#L39)
which turned out
[untrue](https://github.com/sei-protocol/sei-chain/blob/fe95a1ff76a108ff37347a16ee6139509322e058/sei-cosmos/baseapp/abci.go#L283-L289).
It turned out that the data field is indeterministic.
Return data gets [populated with a stringified error
](https://github.com/sei-protocol/sei-chain/blob/07441d7bfcd7f9fc69119cf3002be7d6912b3a87/precompiles/common/precompiles.go#L159-L166)if
the precompile errors out, this bubbles up as aforementioned
[data](https://github.com/sei-protocol/sei-chain/blob/fe95a1ff76a108ff37347a16ee6139509322e058/sei-tendermint/proto/tendermint/abci/types.proto#L430),
stringified error can among other things contain the path to executable
by way of including the call stack.
PR that introduced the issue -
#1757.
### Potential Solutions
One of the reasons ABCI decodes errors and excludes
[log](https://github.com/sei-protocol/sei-chain/blob/fe95a1ff76a108ff37347a16ee6139509322e058/sei-tendermint/proto/tendermint/abci/types.proto#L293),
[info](https://github.com/sei-protocol/sei-chain/blob/fe95a1ff76a108ff37347a16ee6139509322e058/sei-tendermint/proto/tendermint/abci/types.proto#L294),
[events](https://github.com/sei-protocol/sei-chain/blob/fe95a1ff76a108ff37347a16ee6139509322e058/sei-tendermint/proto/tendermint/abci/types.proto#L297)
fields from consensus is to guard from indeterminism.
Ethereum on the other side discerns between two types of errors during
transaction execution - vmerrors and consensus/client errors - vmerrors
are not part of consensus in any way and errors coming from precompile
runs fall into this category.
Broadly there are a couple of ways to solve this:
1. Remove all inderterminism from errors - do not wrap errors, etc. -
short term this will work for the specific scenario we encountered, long
term we will have exactly the same issue because we will forget that
changing an error message is an app hash break
2. Populate return data deterministically if a precompile errors out -
this approach would be similar to what ABCI does by reducing errors to
codes/codespaces by decoding them
3. Do not populate return data if a precompile errors out - precompiles
that error out should never have side effects (to be confirmed) which
makes this approach viable and it is the most right/Ethereum equivalent
way of doing things
### Solution
[1.] is a hotfix - which we already have - but not a long running
solution as every precompile error message diff would lead to app hash
break.
[2.] does work but we've got no additional benefits from reducing
precompile errors to error codes/spaces.
Therefore picked [3.]
What we lose by this solution is visibility into the specific error that
happened - we can retain that by concatenate the error string to the
execution reverted error.
Comment on security concerns (proof by negation):
This won't affect security - the only way in which including a
precompile error message into consensus can boost security is by making
sure the precompile run of every actor ended at exactly the same point -
this can easily be bypassed (both with or without this PR) by a
malicious actor executing the actual precompile and additional code
besides that so guardrails should be elsewhere.
## Testing performed to validate your change
Ran a local chain against the testing suite, also CI/CD.1 parent cc5bd64 commit 0156e75
File tree
9 files changed
+20
-22
lines changed- precompiles
- addr
- common
- distribution
- gov
- ibc
- json
- staking
- wasmd
9 files changed
+20
-22
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
167 | 167 | | |
168 | 168 | | |
169 | 169 | | |
170 | | - | |
| 170 | + | |
171 | 171 | | |
172 | 172 | | |
173 | 173 | | |
| |||
358 | 358 | | |
359 | 359 | | |
360 | 360 | | |
361 | | - | |
| 361 | + | |
362 | 362 | | |
363 | 363 | | |
364 | 364 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
69 | | - | |
70 | 69 | | |
71 | 70 | | |
72 | 71 | | |
| |||
159 | 158 | | |
160 | 159 | | |
161 | 160 | | |
162 | | - | |
163 | 161 | | |
164 | 162 | | |
165 | 163 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
89 | | - | |
| 89 | + | |
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
| |||
127 | 127 | | |
128 | 128 | | |
129 | 129 | | |
130 | | - | |
| 130 | + | |
131 | 131 | | |
132 | 132 | | |
133 | 133 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
502 | 502 | | |
503 | 503 | | |
504 | 504 | | |
505 | | - | |
| 505 | + | |
506 | 506 | | |
507 | 507 | | |
508 | 508 | | |
| |||
663 | 663 | | |
664 | 664 | | |
665 | 665 | | |
666 | | - | |
| 666 | + | |
667 | 667 | | |
668 | 668 | | |
669 | 669 | | |
| |||
839 | 839 | | |
840 | 840 | | |
841 | 841 | | |
842 | | - | |
| 842 | + | |
843 | 843 | | |
844 | 844 | | |
845 | 845 | | |
| |||
1136 | 1136 | | |
1137 | 1137 | | |
1138 | 1138 | | |
1139 | | - | |
| 1139 | + | |
1140 | 1140 | | |
1141 | 1141 | | |
1142 | 1142 | | |
| |||
1235 | 1235 | | |
1236 | 1236 | | |
1237 | 1237 | | |
1238 | | - | |
| 1238 | + | |
1239 | 1239 | | |
1240 | 1240 | | |
1241 | 1241 | | |
| |||
1376 | 1376 | | |
1377 | 1377 | | |
1378 | 1378 | | |
1379 | | - | |
| 1379 | + | |
1380 | 1380 | | |
1381 | 1381 | | |
1382 | 1382 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
312 | 312 | | |
313 | 313 | | |
314 | 314 | | |
315 | | - | |
| 315 | + | |
316 | 316 | | |
317 | 317 | | |
318 | 318 | | |
| |||
751 | 751 | | |
752 | 752 | | |
753 | 753 | | |
754 | | - | |
| 754 | + | |
755 | 755 | | |
756 | 756 | | |
757 | 757 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
337 | 337 | | |
338 | 338 | | |
339 | 339 | | |
340 | | - | |
| 340 | + | |
341 | 341 | | |
342 | 342 | | |
343 | 343 | | |
| |||
538 | 538 | | |
539 | 539 | | |
540 | 540 | | |
541 | | - | |
| 541 | + | |
542 | 542 | | |
543 | 543 | | |
544 | 544 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
281 | 281 | | |
282 | 282 | | |
283 | 283 | | |
284 | | - | |
| 284 | + | |
285 | 285 | | |
286 | 286 | | |
287 | 287 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
473 | 473 | | |
474 | 474 | | |
475 | 475 | | |
476 | | - | |
| 476 | + | |
477 | 477 | | |
478 | 478 | | |
479 | 479 | | |
| |||
691 | 691 | | |
692 | 692 | | |
693 | 693 | | |
694 | | - | |
| 694 | + | |
695 | 695 | | |
696 | 696 | | |
697 | 697 | | |
| |||
752 | 752 | | |
753 | 753 | | |
754 | 754 | | |
755 | | - | |
| 755 | + | |
756 | 756 | | |
757 | 757 | | |
758 | 758 | | |
| |||
809 | 809 | | |
810 | 810 | | |
811 | 811 | | |
812 | | - | |
| 812 | + | |
813 | 813 | | |
814 | 814 | | |
815 | 815 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
156 | 156 | | |
157 | 157 | | |
158 | 158 | | |
159 | | - | |
| 159 | + | |
160 | 160 | | |
161 | 161 | | |
162 | 162 | | |
| |||
0 commit comments