Skip to content

Backport #9267#9487

Merged
athei merged 8 commits intounstable2507from
at/revive_backports
Aug 15, 2025
Merged

Backport #9267#9487
athei merged 8 commits intounstable2507from
at/revive_backports

Conversation

pgherveou and others added 7 commits August 14, 2025 13:09
Fix seal_call benchmark, ensure that the benchmarked block actually
succeed

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
The latest XCM version is 5. A lot of parachains are still running V3 or
V4 which is why we haven't removed them, but the XCM precompile is new
and should only have to deal with versions 5 and onwards. No need to
keep dragging 3 and 4 in contracts.
On Ethereum, 1 ETH is represented as 10^18 wei (wei being the smallest
unit).
On Polkadot 1 DOT is defined as 1010 plancks. It means that any value
smaller than 10^8 wei can not be expressed with the native balance. Any
contract that attempts to use such a value currently reverts with a
DecimalPrecisionLoss error.

In theory, RPC can define a decimal representation different from
Ethereum mainnet (10^18). In practice tools (frontend libraries,
wallets, and compilers) ignore it and expect 18 decimals.

The current behaviour breaks eth compatibility and needs to be updated.
See issue #109 for more details.


Fix  paritytech/contract-issues#109
[weights
compare](https://weights.tasty.limo/compare?unit=weight&ignore_errors=true&threshold=10&method=asymptotic&repo=polkadot-sdk&old=master&new=pg/eth-decimals&path_pattern=substrate/frame/**/src/weights.rs,polkadot/runtime/*/src/weights/**/*.rs,polkadot/bridges/modules/*/src/weights.rs,cumulus/**/weights/*.rs,cumulus/**/weights/xcm/*.rs,cumulus/**/src/weights.rs)

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Alexander Theißen <[email protected]>
Co-authored-by: Oliver Tale-Yazdi <[email protected]>
The existential deposit to create a new account is part of the storage
deposit. Hence if the storage deposit limit is too low to create a new
account we fail the transaction. However, this limit was not enforced
for plain transfers. The reason is that we only enforce the limit at the
end of each frame. But for plain transfers (transferring to a non
contract) there is no frame.

This PR fixes the situation by enforcing the limit when transferring the
existential deposit in order to create a new account.

---------

Co-authored-by: PG Herveou <[email protected]>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
fix issue: paritytech/contract-issues#141

Corrects the condition for minting a new currency unit when transferring
dust. The condition was incorrectly checking
`to_info.dust.saturating_add(dust) >= plank` which could lead to
unexpected minting behavior. It now correctly checks if `to_info.dust >=
plank` before minting.
…_blake2_256` into it (#9441)

Part of closing #8572.

Just the `hash_blake2_256` in this PR, to gauge if you're fine with this
setup.

cc @athei @pgherveou

---------

Co-authored-by: Alexander Theißen <[email protected]>
…ll depth to 25 (#9267)

This PR changes the contract code limit from roughly 100KiB to exactly
1MiB. It also raises the call stack depth from 5 to 25.

Those limits were in place because of memory constraints within the
runtime. We work around them in those ways:
1) Removing the 4x safety margin for allocations which is no longer
needed due to the new allocator.
2) Limiting the size of the compilation cache to a fixed size.
3) Resetting the compilation cache and flat map every time we call into
a new contract.
4) Limiting the size of calldata and return data to 128KiB (only capped
by tx size and RAM before). While this is a breaking change nobody will
be affected since Geth effectively limits the call data to 128KiB.

This is large enough so that all known contracts won't fail for size
issues anymore.

The new limit is also much simpler to understand since it does not
depend on the number of instructions. Just those two constraints:
```
PVM_BLOB.len() < 1 MiB
PVM_BLOB.len() + (rw/ro/stack) < 1MiB + 512KiB
```

This means:
1) A contract is guaranteed to have at least 512KiB of memory available.
2) A contract that is smaller in code can use more memory.
3) Limit is exactly 1MiB unless a user manually increase the memory
usage of a contract to be larger than 512KiB.

The limit of `5` was problematic because there are use cases which
require deeper stacks. With the raise to `25` there should be no benign
use cases anymore that won't work.

Please note that even with the low limit of `25` contracts are not
vulnerable to stack depth exhaustion attacks: We do trap the caller's
context when the depth limit is reached. This is different from Eth
where this error can be handled and failure to do so leaves the contract
vulnerable.

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@athei athei requested review from a team as code owners August 14, 2025 11:57
@acatangiu acatangiu added the T7-smart_contracts This PR/Issue is related to smart contracts. label Aug 14, 2025
Copy link
Copy Markdown
Contributor

@acatangiu acatangiu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did not review substrate/frame/revive code changes, someone from contracts team make sure to review.
Everything else LGTM!

@athei athei changed the title unstable2507 SCC backports Backport #9267 Aug 15, 2025
@athei athei merged commit b83468f into unstable2507 Aug 15, 2025
240 of 243 checks passed
@athei athei deleted the at/revive_backports branch August 15, 2025 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T7-smart_contracts This PR/Issue is related to smart contracts.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants