Function: function withdraw()
This function withdraws an amount of the defaultToken if the ECDSA signature verifies the given id, trader, and amount.
The withdrawToken and withdrawNative functions work similarly except that the token address is included in the signature. The same threat model applies to them.
Inputs
idControl: Controlled by the caller.
Constraints: The mapping
processedWithdrawalsof the givenidmust not be true. Theidin the given signature must match.Impact: Prevent replay attacks.
traderControl: Controlled by the caller.
Constraints: The
traderin the given signature must match.Impact: Ensure the address of the recipient was authorized.
amountControl: Completely controlled by the caller.
Constraints: The
amountin the given signature must match, and the value must be bigger than zero.Impact: The amount to transfer.
vControl: Completely controlled by the caller.
Constraints: The
vargument of the ECDSA signature can be either 27 or 28, arbitrary to be compatible with the AWS KMS.Impact: A part of the signature to verify.
rControl: Completely controlled by the caller.
Constraints: This must be a part of the valid ECDSA signature for the given
id,trader, andamount.Impact: The first part of the signature to verify.
sControl: Completely controlled by the caller.
Constraints: This must be a part of the valid ECDSA signature with the given
id,trader, andamount.Impact: The second part of the signature to verify.
Branches and code coverage (including function calls)
Intended branches
Verify the signature.
Verify the signature with another
vvalue.Send the
defaultTokento the giventrader, and verify the balance is correct.
Negative behavior
Revert when it fails to verify an incorrect signature.
Revert when the amount is zero.
Revert when the
idis already withdrawn.Revert when the transfer fails.
Function call analysis
withdraw -> getDigest(id, trader, amount, defaultToken, false)External/Internal? Internal.
Argument control?
id,trader, andamountare controlled.Impact: Compute the hash of the parameters before the signature.
withdraw -> verify(digest, v, r, s)External/Internal?: Internal.
Argument control?:
v,r, andsare controlled.Impact: Verify the ECDSA signature.
withdraw -> makeTransfer(trader, amount, defaultToken)External/Internal? Internal.
Argument control?:
traderandamountare controlled but must be signed correctly.Impact: Transfer the token to the trader.