-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New Subkeys Proposal Spec by B-Harvest #4480
Comments
Great work on this @dlguddus. Following up from forum post. I'll try to structure feedback:
A single (unified) account representation incorporating the above changes could look like this:
Hope this is useful feedback. I haven't reviewed everything yet, but I guess this is a good starting point. :-) |
B-Harvest closes this Subkey feature issue due to a similar feature being developed by gaian team, a winner of Berlin hackatom. |
Forum post with some thoughts on subkey process: |
New Subkeys Proposal Spec by B-Harvest
Abstract
@sunnya97 created a great proposal spec(#4380) on
SubKeys
functionality. It allows users to create an account calledSubKeyAccount
which has multipleSubKey
to sign a transaction generated from the account. EachSubKey
can hold different list of permission among transaction type(PermissionedRoutes
), and also hold maximum 24 hour transaction fee allowance amount(DailyFeeAllowance
).B-Harvest proposes an advanced version of
SubKeys
functionality with additional utilities and with some structural changes from the original proposal by @sunnya97. Additional utilities are below.SubKeyAccount
without original public/private keysDailyFeeAllowance
toDailySpendableAllowance
(daily maximum allowed spendable amount)SubKeyAccount
to prevent spam attacksSubKey
for aSubKeyAccount
to prevent spam attacksSubKey
We expect above additional utilities will create good use-cases as below.
Construction of
SubKeyAccount
andSubKey
SubKeyAccount
(a newAccount
type) stores basic account information(BaseAccount
) with relatedSubKeys
andDeposit
amount when creation.SubKey
type storesSubKeyNumber
(index of aSubKey
),PubKey
,PermissionedRoutes
(list of allowed transaction type),DailySpendableAllowance
andDailySpent
.Now, we want to present pseudo codes to create a
SubKeyAccount
. There exists two kinds of it, 1) "upgrading" plainAccount
to aSubKeyAccount
and 2) "creating" newSubKeyAccount
without original master pubkey/privatekey.CreateSubKeyAccount
(upgrading)CreateSubKeyAccountWithoutPrivateKey
(creating without pubkey/privatekey)Parameters for
SubKeyAccount
andSubKey
We will add several parameters to use it for additional utilities as below.
SubKeyLimit
: Maximum number ofSubKey
for aSubKeyAccount
MinDeposit
: Minimum required deposit to create and maintain aSubKeyAccount
. Deposit will be vested until theSubKeyAccount
is destroyed.DefaultSubKeyLimit
: Default value ofSubKeyLimit
DefaultMinDepositAmount
: Default value ofMinDeposit
auth
inRouterKeyList
to properly handle the authority to manage aSubKeyAccount
SubKeyNumber
=NoSubKey
= 0 when user signs a transaction from aSubKeyAccount
with original master keyDailySpendableAllowance
=NoLimitAllowance
= -1 implies theSubKey
has infinite daily spendable allowance limitChecking and Tracking
DailySpendableAllowance
1) Checking
DailySpendableAllowance
Cosmos-SDK uses
SpendableCoins
andsubtractCoins
to check whether the balance of the account is enough. When a user signs a tx with aSubKey
, the SDK should additionally check whether given tx will spend more than allowed. The checking is possible by usingSpendableCoins
,substractCoins
and additionallyDailySpendableAllowance
,DailySpent
from the givenSubKey
information.Below is describing a new context called
WithSubKey
, which is holding context information ofSubKey
when a transaction is signed by aSubKey
. It will allow SDK to useDailySpendableAllowance
andDailySpent
from the new context.Also we need to add
SubKeyNumber
item inSpendableCoins
to inform which pair ofSubKeyAccount
andSubKey
is related to the givenstdTx
as below.Below explains how we add
SubKey
adjustment into theSpendableCoins
function.2) Tracking
DailySpent
The definition of
DailySpent
is the accumulated amount spent by aSubKey
of aSubKeyAccount
in recent 24 hours window. Therefore, we need to track the 24 hours window accumulation.But now we need a way to decrease the
DailySpent
field once transactions are past the 24 hour window. To do this we us a time based iterator similar to the ones used in the governance and staking queues.We start by defining a new struct called a
DailySpent
, which is what will be inserted into the Queue.When a transaction using a SubKey has spent, we insert a new entry into this queue's store.
sdk.FormatTimeBytes(ctx.BlockTime.Add(time.Day * 1)
DailySpent
Finally in the EndBlocker we iterate over the all the DailySpent in the queue which are expired (more than a day old). We prune them from state, and deduct their Spent amount from the corresponding SubKey.
Signature and Verification
When users sign a transaction with a
SubKey
, we need several changes in SDK so that it can properly verify the signature.First, we introduce a new function called
SubKey
which finds theSubKey
object usingPubKey
ofSubKey
/SubKeyAccount
.In
NewAnteHandle
, if account type isSubKeyAccount
, check the pubkey of the given signature is included as aSubKey
of theSubKeyAccount
.In
processSig
, whenSubKeyNumber
exists onctx
(when the signature is done by aSubKey
of aSubKeyAccount
), change thepubKey
toSubKey
'spubKey
to properly verify theSubKey
signature withVerifyBytes
function.We need to add
subKeyNumber
toTxBuilder
for offlinegaiacli
usage.Msgs
In order to create and destroy
SubKeyAccount
, we need three newMsg
types.Also we need three new
Msg
to add/delete aSubKey
and edit the permission setting of aSubKey
.The text was updated successfully, but these errors were encountered: