Users

contract Users is MainStorage, LibConstants, MGovernance, MUsers

Users of the Stark Exchange are identified within the exchange by their Stark Key which is a public key defined over a Stark-friendly elliptic curve that is different from the standard Ethereum elliptic curve. These keys may be generated using the same private key used by the user on Ethereum.

The Stark-friendly elliptic curve used is defined as follows:

\[y^2 = (x^3 + \alpha \cdot x + \beta) \% p\]

where:

\[\alpha = 1\]
\[\beta = 3141592653589793238462643383279502884197169399375105820974944592307816406665\]
\[p = 3618502788666131213697322783095070105623107215331596699973092056135872020481\]

In order to associate exchange users with Ethereum account addresses, a user must register the Stark Key on the exchange contract before any other user operation can take place. User registration is performed by calling register with the selected Stark Key, representing an x coordinate on the Stark-friendly elliptic curve, and the y coordinate of the key on the curve (due to the nature of the curve, only two such possible y coordinates exist).

The registration is accepted if the following holds:

  1. The key registered is not zero and has not been registered in the past by the user or anyone else.

  2. The key provided represents a valid point on the Stark-friendly elliptic curve.

  3. The linkage between the Ethereum key of the caller and the selected Stark Key is signed by the User Admin (typically the exchange operator).

If the above holds, the Stark Key is registered by the contract mapping it to the Ethereum key of the registering entity and vice versa. This mapping is later used to ensure that withdrawals from accounts mapped to the Stark Key can only be performed by a user authenticated with the associated Ethereum public key (see Withdrawals).

event LogUserRegistered(address etherKey, uint256 starkKey)
event LogUserAdminAdded(address userAdmin)
event LogUserAdminRemoved(address userAdmin)
function registerUserAdmin(address newAdmin)
external
 onlyGovernance()
function unregisterUserAdmin(address oldAdmin)
external
 onlyGovernance()
function isUserAdmin(address testedAdmin)
public
view
returns (bool)
function register(uint256 starkKey, bytes calldata signature)
external
function getStarkKey(address etherKey)
public
view
returns (uint256 starkKey)
function getEtherKey(uint256 starkKey)
external
view
returns (address etherKey)
function fieldPow(uint256 base, uint256 exponent)
internal
view
returns (uint256)
function isQuadraticResidue(uint256 fieldElement)
private
view
returns (bool)