Skip to content

Commit ae8c335

Browse files
authored
Merge pull request #351 from /issues/347/execute_v1
issues/347: qfpolkavm's pallet execute ADR
2 parents 707a458 + 0daebd3 commit ae8c335

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
## Title: Design of Polka VM pallet's execute() extrinsic
2+
3+
## Date
4+
2025-05-20
5+
Last status update: 2025-05-21
6+
7+
## Status
8+
- [X] Proposed
9+
- [X] Accepted
10+
- [ ] Rejected
11+
- [ ] Deprecated
12+
- [ ] Superseded by ADR #X
13+
14+
### Implementation Status
15+
- [ ] Planned
16+
- [X] In Development
17+
- [ ] Implemented
18+
- [ ] Verified
19+
- [ ] Discontinued
20+
21+
## People
22+
- **Decision-makers**: KP, Vas
23+
- **Consulted**: Andrei, Alisher
24+
- **Informed**:
25+
- Sviat
26+
27+
## Context
28+
For running a smart contract we have to have implemented pallet's extrinsic `execute()` and at least one method inside the contract to run it (i.e. `main()`).
29+
30+
## Problem
31+
We have introduced [pallet's execute method](https://github.com/QuantumFusion-network/qf-solochain/blob/main/pallets/qf-polkavm/src/lib.rs#L333), it has signature:
32+
```
33+
execute(origin, contract_address, to, value, user_data, gas_limit, gas_price)
34+
```
35+
, where:
36+
- `origin` is a caller address,
37+
- `contract_address` is an address of stored on-chain contract,
38+
- `user_data` is [SCALE] encoded structures passed to the contract's main() function,
39+
- `gas_limit` is a limit of the gas for executing of the contract behind contract_address,
40+
- `gas_price` is a price of the gas for auction; this argument is not implemented, it's for the future.
41+
42+
As we can see, the signature includes legacy arguments like `to` and `value`, inherited from PoC development.
43+
44+
## Decision
45+
### Change signature of pallet's extrinsic to:
46+
```
47+
execute(origin, contract_address, data, gas_limit, storage_deposit_limit, gas_price)
48+
```
49+
, where:
50+
- `origin` is a caller address,
51+
- `contract_address` is an address of stored on-chain contract,
52+
- `data` is encoded structures [_maybe_ SCALE encoded] passed to the contract's context and available via host function call,
53+
- `gas_limit` is a limit of the gas for executing of the contract behind contract_address,
54+
- `storage_deposit_limit` is a limit of how many storage space could be used for storing data during contract execution, if out of this limit, then transaction fail with Out of Storage limit error message and no data stored. Thing about this case: we have a huge `gas_limit` and trying to save inside a contract, by mistaken, a huge blob of data. This argument is not implemented, it's for the future. Unit: bytes per a storage slot.
55+
- `data` is [SCALE] encoded bytes passed to the contract's context and available via host function call,
56+
- `gas_limit` [Weight](https://docs.rs/sp-weights/31.1.0/sp_weights/struct.Weight.html) is a limit of the gas for execution of the contract behind `contract_address`-- [implementation reference](https://docs.rs/pallet-revive/latest/src/pallet_revive/lib.rs.html#727),
57+
- `storage_deposit_limit` is a maximum amount of balance that can be charged from the caller to pay for the storage consumed during contract execution. If this limit is exceeded, then transaction fails with `Out of Storage limit` error message and no data stored. Thing about this case: we have a huge `gas_limit` and trying to save inside a contract, by mistaken, a huge blob of data. This argument is not implemented, it's for the future. Unit: balance.
58+
- `gas_price` is a price of the gas for auction; this argument is not implemented, it's for the future.
59+
60+
61+
### Update function signatures
62+
`transfer()` and `balance_of()` should read address and value from the `data` instead of `to` and `value`.
63+
64+
## References
65+
66+
[Ref to pallet contracts](https://docs.rs/pallet-contracts/latest/pallet_contracts/pallet/struct.Pallet.html#method.call)
67+
68+
[Concern: value](https://docs.rs/pallet-contracts/latest/pallet_contracts/pallet/struct.Pallet.html#method.call)
69+
Research result: seems `value` introduced for optimization puposes for balance transfering and balance_of. I don't find any other reasons.
70+
71+
[Storage deposit limit explanation](https://github.com/paritytech/substrate-contracts-node/issues/23#issuecomment-1008751578)
72+
73+
[SCALE]: https://github.com/paritytech/parity-scale-codec
74+
75+
[Purpose of `value` param in `pallet-contracts::call` extrinsic?](https://substrate.stackexchange.com/questions/12363/purpose-of-value-param-in-pallet-contractscall-extrinsi)
76+

0 commit comments

Comments
 (0)