This repository was archived by the owner on Aug 2, 2022. It is now read-only.
Consensus protocol upgrade to forward setcode actions to the contract on the eosio account #6988
Labels
CONSENSUS
Introduces a change that may modify consensus protocol rules on an existing blockchain.
Background
Normal execution of actions involve first calling any native handler that may be registered for the action and then calling the WebAssembly code if a contract is in place on the receiver account (see
apply_context::exec_one
). The conditiona.code.size() > 0
(wherea
is theaccount_object
of thereceiver
) is used in that code to check that a contract exists on the receiver and if not it will not attempt to execute WebAssembly code.However, the existing code has additional restrictions that prevents the execution of WebAssembly code for a
eosio::setcode
action even when a contract exists. The fullif
statement to enter the part of the code that executes the contract is:Note that
act
is the currently executing action andconfig::system_account_name == N(eosio)
.The original intention behind this condition, which is one we no longer find necessary and may even find undesirable to maintain, was to prevent the contract from executing if the
eosio::setcode
was setting a new contract on theeosio
account. But due to a bug in the condition, it ended up preventing WebAssembly code from executing on anyeosio::setcode
actions, regardless of which account theeosio::setcode
action was for.Use cases are enabled by fixing the bug. For example, it enables operators of the network to deploy a system contract that is selective about the contracts it allows other accounts to deploy.
There is not as strong of a use case identified for allowing an
eosio::setcode
action that tries to set a contract on theeosio
account to also be forwarded to execute on the contract deployed oneosio
; but we haven't identified any harm in allowing that to occur as well. If it was to be allowed, there is a choice available between two ways of doing it. One option is for the old WebAssembly code to run in the context of theeosio::setcode
action, essentially acting as a pre-check to the code that is to replace it. The other option is for the new WebAssembly code to run in the context of theeosio::setcode
action. We have identified three arguments in favor of taking the latter approach:eosio
(whether before or after contract replacement) via therequire_recipient
orsend_inline
intrinsics would necessarily run in an environment in which the new contract was already deployed. So going with the latter approach provides more consistency to contract developers.eosio
. A separate management account could be in charge of deploying changes to theeosio
contract by providing a proxy action tosetcode
; any necessary pre-checks would be added to this contract. Then theeosio::setcode
action could be linked for theeosio
account to a custom permission that is unilaterally satisfiable by theeosio.code
permission of the management account.Consensus protocol upgrade feature
This protocol feature (codename:
FORWARD_SETCODE
) allows the contract WebAssembly code deployed on theeosio
account to execute foreosio::setcode
actions.So when the
eosio::setcode
action is dispatched to theeosio
receiver, first the native handler (seeapply_eosio_newaccount
) would run as it does currently. But then the WebAssembly code deployed on theeosio
account would execute under the context of that action (assuming a contract was deployed on theeosio
account).This means that an
eosio::setcode
action that changes the contract oneosio
would first change the contract to the new one, and then execute the new contract under the context of theeosio::setcode
action. Given the recent changes of eosio.cdt v1.6.x, it means any contract compiled with recent versions of eosio.cdt that is to be deployed ontoeosio
should include a handler for theeosio::setcode
action even if it is to do nothing; otherwise, the auto-generated dispatcher would reject theeosio::setcode
action making it impossible to deploy that contract toeosio
in the first place. (Note: the current eosio.system contract is properly designed to handle this, but the eosio.bios contract would need to be updated.)The changes described above can be achieved, after the protocol feature foundations have been completed (see issues #6429 and #6431), by simply changing the
if
condition mentioned in the background section to instead be:(The above change omits the other code changes needed to setup
FORWARD_SETCODE
as a new protocol feature in the first place.)The text was updated successfully, but these errors were encountered: