Commit 2863b7a
Fix generated address returned by Substrate RPC runtime call (#8504)
## Description
When dry-running a contract deployment through the runtime API, the
returned address does not match the actual address that will be used
when the transaction is submitted. This inconsistency occurs because the
address derivation logic doesn't properly account for the difference
between transaction execution and dry-run execution contexts.
The issue stems from the `create1` address derivation logic in
`exec.rs`:
```rust
address::create1(
&deployer,
// the Nonce from the origin has been incremented pre-dispatch, so we
// need to subtract 1 to get the nonce at the time of the call.
if origin_is_caller {
account_nonce.saturating_sub(1u32.into()).saturated_into()
} else {
account_nonce.saturated_into()
},
)
```
The code correctly subtracts 1 from the account nonce during a
transaction execution (because the nonce is incremented pre-dispatch),
but doesn't account for execution context - whether it's a real
transaction or a dry run through the RPC.
## Review Notes
This PR adds a new condition to check for the `IncrementOnce` when
calculating the nonce for address derivation:
```rust
address::create1(
&deployer,
// the Nonce from the origin has been incremented pre-dispatch, so we
// need to subtract 1 to get the nonce at the time of the call.
if origin_is_caller && matches!(exec_context, IncrementOnce::AlreadyIncremented) {
account_nonce.saturating_sub(1u32.into()).saturated_into()
} else {
account_nonce.saturated_into()
},
)
```
## Before Fix
- Dry-run contract deployment returns address derived with nonce N
- Actual transaction deployment creates contract at address derived with
nonce N-1
- Result: Inconsistent addresses between simulation and actual execution
## After Fix
- Dry-run and actual transaction deployments both create contracts at
the same address
- Result: Consistent contract addresses regardless of execution context
- Added test case to verify nonce handling in different execution
contexts
This fix ensures that users can rely on the address returned by a dry
run to match the actual address that will be used when the transaction
is submitted.
Fixes paritytech/contract-issues#37
# Checklist
* [x] My PR includes a detailed description as outlined in the
"Description" and its two subsections above.
* [x] My PR follows the [labeling requirements](
https://github.com/paritytech/polkadot-sdk/blob/master/docs/contributor/CONTRIBUTING.md#Process
) of this project (at minimum one label for `T` required)
* External contributors: ask maintainers to put the right label on your
PR.
* [x] I have made corresponding changes to the documentation (if
applicable)
* [x] I have added tests that prove my fix is effective or that my
feature works (if applicable)
---------
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: pgherveou <[email protected]>1 parent ff5c67c commit 2863b7a
9 files changed
Lines changed: 168 additions & 10 deletions
File tree
- cumulus/parachains/runtimes/assets/asset-hub-westend/src
- prdoc
- substrate
- bin/node/runtime/src
- frame/revive/src
- exec
- test_utils
Lines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
65 | | - | |
| 65 | + | |
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
| |||
2364 | 2364 | | |
2365 | 2365 | | |
2366 | 2366 | | |
| 2367 | + | |
2367 | 2368 | | |
2368 | 2369 | | |
2369 | 2370 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
88 | | - | |
| 88 | + | |
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
| |||
3443 | 3443 | | |
3444 | 3444 | | |
3445 | 3445 | | |
| 3446 | + | |
3446 | 3447 | | |
3447 | 3448 | | |
3448 | 3449 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
| 36 | + | |
| 37 | + | |
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
| |||
270 | 271 | | |
271 | 272 | | |
272 | 273 | | |
| 274 | + | |
273 | 275 | | |
274 | 276 | | |
275 | 277 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
| 29 | + | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| |||
614 | 614 | | |
615 | 615 | | |
616 | 616 | | |
| 617 | + | |
617 | 618 | | |
618 | 619 | | |
619 | 620 | | |
| |||
807 | 808 | | |
808 | 809 | | |
809 | 810 | | |
| 811 | + | |
810 | 812 | | |
811 | 813 | | |
812 | 814 | | |
813 | 815 | | |
814 | 816 | | |
815 | 817 | | |
816 | 818 | | |
| 819 | + | |
817 | 820 | | |
818 | 821 | | |
819 | 822 | | |
| |||
874 | 877 | | |
875 | 878 | | |
876 | 879 | | |
877 | | - | |
878 | 880 | | |
879 | 881 | | |
880 | 882 | | |
| |||
908 | 910 | | |
909 | 911 | | |
910 | 912 | | |
911 | | - | |
912 | 913 | | |
913 | 914 | | |
914 | 915 | | |
| |||
972 | 973 | | |
973 | 974 | | |
974 | 975 | | |
975 | | - | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
976 | 983 | | |
977 | 984 | | |
978 | 985 | | |
| |||
983 | 990 | | |
984 | 991 | | |
985 | 992 | | |
986 | | - | |
| 993 | + | |
987 | 994 | | |
988 | 995 | | |
989 | 996 | | |
| |||
1059 | 1066 | | |
1060 | 1067 | | |
1061 | 1068 | | |
1062 | | - | |
1063 | 1069 | | |
1064 | 1070 | | |
1065 | 1071 | | |
| |||
1665 | 1671 | | |
1666 | 1672 | | |
1667 | 1673 | | |
| 1674 | + | |
1668 | 1675 | | |
1669 | 1676 | | |
1670 | 1677 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
566 | 566 | | |
567 | 567 | | |
568 | 568 | | |
| 569 | + | |
569 | 570 | | |
570 | 571 | | |
571 | 572 | | |
| |||
1069 | 1070 | | |
1070 | 1071 | | |
1071 | 1072 | | |
| 1073 | + | |
1072 | 1074 | | |
1073 | 1075 | | |
1074 | 1076 | | |
| |||
1104 | 1106 | | |
1105 | 1107 | | |
1106 | 1108 | | |
| 1109 | + | |
1107 | 1110 | | |
1108 | 1111 | | |
1109 | 1112 | | |
| |||
1150 | 1153 | | |
1151 | 1154 | | |
1152 | 1155 | | |
| 1156 | + | |
1153 | 1157 | | |
1154 | 1158 | | |
1155 | 1159 | | |
| |||
1313 | 1317 | | |
1314 | 1318 | | |
1315 | 1319 | | |
| 1320 | + | |
1316 | 1321 | | |
1317 | 1322 | | |
1318 | 1323 | | |
| |||
1441 | 1446 | | |
1442 | 1447 | | |
1443 | 1448 | | |
| 1449 | + | |
1444 | 1450 | | |
1445 | 1451 | | |
1446 | 1452 | | |
| |||
1802 | 1808 | | |
1803 | 1809 | | |
1804 | 1810 | | |
| 1811 | + | |
1805 | 1812 | | |
1806 | 1813 | | |
1807 | 1814 | | |
| |||
1815 | 1822 | | |
1816 | 1823 | | |
1817 | 1824 | | |
| 1825 | + | |
1818 | 1826 | | |
1819 | 1827 | | |
1820 | 1828 | | |
| |||
1827 | 1835 | | |
1828 | 1836 | | |
1829 | 1837 | | |
| 1838 | + | |
1830 | 1839 | | |
1831 | 1840 | | |
1832 | 1841 | | |
| |||
1839 | 1848 | | |
1840 | 1849 | | |
1841 | 1850 | | |
| 1851 | + | |
1842 | 1852 | | |
1843 | 1853 | | |
1844 | 1854 | | |
| |||
2825 | 2835 | | |
2826 | 2836 | | |
2827 | 2837 | | |
| 2838 | + | |
2828 | 2839 | | |
2829 | 2840 | | |
2830 | 2841 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
513 | 513 | | |
514 | 514 | | |
515 | 515 | | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
516 | 528 | | |
517 | 529 | | |
518 | 530 | | |
| |||
797 | 809 | | |
798 | 810 | | |
799 | 811 | | |
| 812 | + | |
800 | 813 | | |
801 | 814 | | |
802 | 815 | | |
| |||
861 | 874 | | |
862 | 875 | | |
863 | 876 | | |
| 877 | + | |
864 | 878 | | |
865 | 879 | | |
866 | 880 | | |
| |||
1075 | 1089 | | |
1076 | 1090 | | |
1077 | 1091 | | |
| 1092 | + | |
1078 | 1093 | | |
1079 | 1094 | | |
1080 | 1095 | | |
| |||
1117 | 1132 | | |
1118 | 1133 | | |
1119 | 1134 | | |
| 1135 | + | |
1120 | 1136 | | |
1121 | 1137 | | |
1122 | 1138 | | |
| |||
1286 | 1302 | | |
1287 | 1303 | | |
1288 | 1304 | | |
| 1305 | + | |
1289 | 1306 | | |
1290 | 1307 | | |
1291 | 1308 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| |||
138 | 138 | | |
139 | 139 | | |
140 | 140 | | |
| 141 | + | |
141 | 142 | | |
142 | 143 | | |
143 | 144 | | |
| |||
165 | 166 | | |
166 | 167 | | |
167 | 168 | | |
| 169 | + | |
168 | 170 | | |
169 | 171 | | |
170 | 172 | | |
| |||
0 commit comments