How do permissions on deferred transactions work?
I'm playing around with deferred transactions and encountered an oddity.
Say, we have a contract deployed on contract, and an account account. contract has [email protected] as part of its active permission, account does not.
The EOS Portal developer documentation states:
Deferred transactions carry the authority of the contract that sends them.
In my deferred action handler I require_auth(account) and it passes. Shouldn't it fail as the transaction has authorization [email protected] and thus fail as account@active does not contain [email protected]?
If I add a deferred transaction to transfer eosio.token it however does not correctly pass the authorization check.
Exception Details: 3090003 unsatisfied_authorization: Provided keys, permissions, and delays do not satisfy declared authorizations
transaction declares authority '{"actor":"account","permission":"active"}', but does not have signatures for it under a provided delay of 3000 ms, provided permissions [{"actor":"contract","permission":"eosio.code"}], and provided keys []
{"auth":{"actor":"account","permission":"active"},"provided_delay":3000,"provided_permissions":[{"actor":"contract","permission":"eosio.code"}],"provided_keys":[],"delay_max_limit_ms":3888000000}
Why does one require_auth check pass, but the other doesn't? Here's the code I deploy on contract
#include <string>
#include <eosiolib/eosio.hpp>
#include <eosiolib/transaction.hpp>
#include <eosiolib/currency.hpp>
using namespace eosio;
using namespace std;
class deferred_example : public eosio::contract
{
public:
deferred_example(account_name self) : contract(self)
{
}
/// @abi action
void deferred(account_name from, const string &message)
{
// why does this pass? shouldn't the permission be [email protected]
// and thus fail as from@active does not contain [email protected]?
require_auth(from);
print("Printing deferred ", eosio::name{from}, " : ", message);
}
/// @abi action
void send(account_name from, const string &message)
{
require_auth(from);
eosio::transaction t{};
// sending this passes the require_auth(from) check in _self::deferred
t.actions.emplace_back(
permission_level(from, N(active)),
_self,
N(deferred),
std::make_tuple(from, message));
// sending this fails the require_auth(from) check in eosio.token::transfer
// because from@active does not contain [email protected] to
// t.actions.emplace_back(permission_level(from, N(active)),
// N(eosio.token),
// N(transfer),
// currency::transfer{
// .from = from,
// .to = _self,
// .quantity = asset(10000, S(4, EOS)),
// .memo = "transfer EOS"});
t.delay_sec = 3;
// use now() as sender id for ease of use
t.send(now(), from);
print("Deferred transaction scheduled");
}
};
EOSIO_ABI(deferred_example, (send)(deferred))
Exception Details: 3100006 subjective_block_production_exception: Subjective exception thrown during block production
Authorization failure with sent deferred transaction consisting only of actions to self
{}
thread-0 apply_context.cpp:347 schedule_deferred_transaction
transaction declares authority '{"actor":"useraaaaaaah","permission":"active"}', but does not have signatures for it under a provided delay of 30000 ms, provided permissions [{"actor":"useraaaaaaaa","permission":"eosio.code"}], provided keys [], and a delay max limit of 3888000000 ms
{"auth":{"actor":"useraaaaaaah","permission":"active"},"provided_delay":30000,"provided_permissions":[{"actor":"useraaaaaaaa","permission":"eosio.code"}],"provided_keys":[],"delay_max_limit_ms":3888000000}
thread-0 authorization_manager.cpp:520 check_authorization
The old implementation doesn't check authorization if the actions inside the scheduled deferred transaction are under the same contract. So in your first example, you schedule an action deferred under the same contract _self, while in your second example, you schedule an action transfer under a foreign contract eosio.token. However, this behavior is only limited to the old version that you're testing. In the latest version, authorization will always be checked, and the permisson_level in the scheduled action must satisfied by [email protected].
Hi @taokayan , Example I want to send inline transaction to external contract
action transfer = action(
permission_level{ get_self(), "active"_n },
"eos.token"_n,
"transfer"_n,
std::make_tuple(buyer, "fnx2exchange"_n, quantity, std::string("Test"))
);
transfer.send();
I still get fail because missing authority of buyer although I pass it in command push action ... -p buyer@active.
How do pass permission_level of buyer to external contract ? Pls help me.
Thank you very much !
I know if I change to
action transfer = action(
permission_level{ get_self(), "active"_n },
"eos.token"_n,
"transfer"_n,
std::make_tuple(get_self(), "fnx2exchange"_n, quantity, std::string("Test"))
);
transfer.send();
it will success. But I can only transfer from one account !
In order to focus our efforts on issues that are currently creating difficulty for the community we are closing tickets that were created prior to the EOSIO 2.0 release. If you believe this issue is still relevant please feel free to reopen it or create a new one. Thank you for your continued support of EOSIO!