You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When there is a MsgTransferRequest the Accept method decrements funds and returns an updated MarkerTrasnferAuthorization with the new limit amount when there exists an msg.administrator. Then the funds are again decremented in the authzHandler function in the Marker module. This may lead to double decrementing when the transfer type is something other than MsgTransferRequest.
returnfmt.Errorf("authorization was not accepted for %s", admin)
}
We're deleting here when limitLeft.IsZero() and ignoring accept.Delete which is set by shouldDelete (see below). If we check for if accept.Delete { ... } it helps avoid type casting and allows for other authorization types to work as well.
The logic in authzHandler() and MarkerTransferAuthorization.Accept() are confusing.
After some research, it looks like this is working as intended, except accidentally, and in such a way that would be easy to have things go wrong.
In the Accept method, the limit is decremented if the from == admin. In the TransferCoin endpoint, we only call Accept when from != admin. But then, in the TransferCoin endpoint, if from != admin, we then manually decrement the limit.
That decrementing should ONLY be handled in the Accept method. In the TransferCoin endpoint, where we call Accept, we then need to properly handle its result, i.e. deleting if appropriate, or updating with the returned authorization if appropriate.
Basically, the MarkerTransferAuthorization.Accept method should always return the updated authorization and delete flag (without the from/admin comparison). Then the authzHandler should not care what type of authorization is being used as long as Accept says it's okay. It should also use the result of Accept to decide when to update or delete the authorization entry.
Because authzHandler assumes that the authorization is a MarkerTransferAuthorization authorization, any other type of authorization will get messed up. E.g. if it's a generic authorization, limitLeft, _ := authorization.(*types.MarkerTransferAuthorization).DecreaseTransferLimit(amount) will always result in a negative limit (if it doesn't panic), which will then cause the authorization to be deleted.
egaxhaj
changed the title
Marker module authzHandler function is double decrementing
Fix the MarkerTransferAuthorization Accept function and TransferCoin authz handling to prevent problems when other authorization types are used
Jun 29, 2022
Summary of Bug
When there is a
MsgTransferRequest
theAccept
method decrements funds and returns an updatedMarkerTrasnferAuthorization
with the new limit amount when there exists anmsg.administrator
. Then the funds are again decremented in theauthzHandler
function in the Marker module. This may lead to double decrementing when the transfer type is something other thanMsgTransferRequest
.Line 710:
provenance/x/marker/keeper/marker.go
Lines 699 to 717 in 1283582
We're deleting here when
limitLeft.IsZero()
and ignoringaccept.Delete
which is set byshouldDelete
(see below). If we check forif accept.Delete { ... }
it helps avoidtype casting
and allows for other authorization types to work as well.The logic in
authzHandler()
andMarkerTransferAuthorization.Accept()
are confusing.provenance/x/marker/types/authz.go
Lines 26 to 44 in 1283582
Line 40: Why is the update occurring in the
marker
module?Version
Steps to Reproduce
For Admin Use
The text was updated successfully, but these errors were encountered: