Skip to content

Commit

Permalink
StarkEx v4.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
gkaempfer committed Nov 9, 2021
1 parent 0efa9ce commit 6db87ef
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 24 deletions.
2 changes: 1 addition & 1 deletion scalable-dex/contracts/src/components/ECDSA.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ library ECDSA {
uint256 pubX,
uint256 pubY
) internal pure {
require(msgHash % FIELD_PRIME == msgHash, "msgHash out of range");
require(msgHash % EC_ORDER == msgHash, "msgHash out of range");
require((1 <= s) && (s < EC_ORDER), "s out of range");
uint256 w = s.invMod(EC_ORDER);
require((1 <= r) && (r < (1 << N_ELEMENT_BITS_ECDSA)), "r out of range");
Expand Down
6 changes: 3 additions & 3 deletions scalable-dex/contracts/src/components/Users.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import "../libraries/LibConstants.sol";
The only flows that require user registration are the anti-concorship flows:
forced actions and deposit cancellation.
User registration is performed by calling :sol:func:`registerEthAddress` with the selected
User registration is performed by calling :sol:func:`registerEthAddress` 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).
Expand Down Expand Up @@ -65,14 +65,14 @@ abstract contract Users is MainStorage, LibConstants {
require(ethKey != ZERO_ADDRESS, "INVALID_ETH_ADDRESS");
require(ethKeys[starkKey] == ZERO_ADDRESS, "STARK_KEY_UNAVAILABLE");
require(isOnCurve(starkKey), "INVALID_STARK_KEY");
require(starkSignature.length == 32 * 3, "INVALID_STARK_SIGNATURE");
require(starkSignature.length == 32 * 3, "INVALID_STARK_SIGNATURE_LENGTH");

bytes memory sig = starkSignature;
(uint256 r, uint256 s, uint256 StarkKeyY) = abi.decode(sig, (uint256, uint256, uint256));

uint256 msgHash = uint256(
keccak256(abi.encodePacked("UserRegistration:", ethKey, starkKey))
) % K_MODULUS;
) % ECDSA.EC_ORDER;

ECDSA.verify(msgHash, r, s, starkKey, StarkKeyY);

Expand Down
28 changes: 28 additions & 0 deletions scalable-dex/contracts/src/interactions/CompositeActions.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// SPDX-License-Identifier: Apache-2.0.
pragma solidity ^0.6.11;

import "../interfaces/MDeposits.sol";

abstract contract CompositeActions is MDeposits {
function registerAndDepositERC20(
address ethKey,
uint256 starkKey,
bytes calldata signature,
uint256 assetType,
uint256 vaultId,
uint256 quantizedAmount
) external {
depositERC20(starkKey, assetType, vaultId, quantizedAmount);
}

// NOLINTNEXTLINE: locked-ether.
function registerAndDepositEth(
address ethKey,
uint256 starkKey,
bytes calldata signature,
uint256 assetType,
uint256 vaultId
) external payable {
depositEth(starkKey, assetType, vaultId);
}
}
12 changes: 0 additions & 12 deletions scalable-dex/contracts/src/libraries/Common.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,6 @@ library Addresses {
"UNEXPECTED_CONTRACT_IDENTIFIER"
);
}

/*
Similar to safeTokenContractCall, but always ignores the return value.
Assumes some other method is used to detect the failures
(e.g. balance is checked before and after the call).
*/
function uncheckedTokenContractCall(address tokenAddress, bytes memory callData) internal {
// NOLINTNEXTLINE: low-level-calls.
(bool success, bytes memory returndata) = tokenAddress.call(callData);
require(success, string(returndata));
}
}

/*
Expand Down
4 changes: 2 additions & 2 deletions scalable-dex/contracts/src/perpetual/StarkPerpetual.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ contract StarkPerpetual is MainDispatcher, PerpetualStorage {
// ---------- The following code was auto-generated. PLEASE DO NOT EDIT. ----------
uint256 constant MAGIC_SALT = 24748;
uint256 constant IDX_MAP_0 = 0x3000130000203000002010004002010003003000010000001222000021002010;
uint256 constant IDX_MAP_1 = 0x4300000140200010000300201000030000300100000022303302;
uint256 constant IDX_MAP_1 = 0x4300000140200010000300201000030000300100000222303302;
uint256 constant IDX_MAP_2 = 0x10001300000020200020000200201000020000300000000031100030020012;
uint256 constant IDX_MAP_3 = 0x120300002000000000000100000000002001002000040101130302000000;
uint256 constant IDX_MAP_3 = 0x120300002000000000000100000000202001002000040101130302000000;

// ---------- End of auto-generated code. ----------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import "../../components/KeyGetters.sol";
import "../../components/Users.sol";
import "../../components/MainGovernance.sol";
import "../../interactions/AcceptModifications.sol";
import "../../interactions/CompositeActions.sol";
import "../../interactions/Deposits.sol";
import "../../interactions/TokenAssetData.sol";
import "../../interactions/TokenQuantization.sol";
Expand All @@ -28,6 +29,7 @@ contract PerpetualTokensAndRamping is
KeyGetters,
Users,
Deposits,
CompositeActions,
Withdrawals
{
function initialize(
Expand Down
12 changes: 6 additions & 6 deletions scalable-dex/contracts/src/starkex/StarkExchange.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ pragma solidity ^0.6.11;
import "../interfaces/MainDispatcher.sol";

contract StarkExchange is MainDispatcher {
string public constant VERSION = "4.0.0";
string public constant VERSION = "4.0.1";

// Salt for a 8 bit unique spread of all relevant selectors. Pre-caclulated.
// ---------- The following code was auto-generated. PLEASE DO NOT EDIT. ----------
uint256 constant MAGIC_SALT = 25249;
uint256 constant IDX_MAP_0 = 0x302000300020020000502000000100000230000550000020220001050200000;
uint256 constant IDX_MAP_1 = 0x2001000000001000000000000220120204000002023062500000300002400132;
uint256 constant IDX_MAP_2 = 0x100000011000000100030550001200120001003000000000005100000002032;
uint256 constant IDX_MAP_3 = 0x1010000105100000000300000321012000002150002002002000001100020300;
uint256 constant MAGIC_SALT = 46110;
uint256 constant IDX_MAP_0 = 0x30006100050005012000102002000001200000010001100500200000000020;
uint256 constant IDX_MAP_1 = 0x120000105000000501200000120502000000200452005000202002030500003;
uint256 constant IDX_MAP_2 = 0x1020000000003020000502203000300000200000000001000100330010220001;
uint256 constant IDX_MAP_3 = 0x200230200020300001401200000000100020011200000002020000010000301;

// ---------- End of auto-generated code. ----------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import "../../components/TokenTransfers.sol";
import "../../components/Users.sol";
import "../../components/MainGovernance.sol";
import "../../interactions/AcceptModifications.sol";
import "../../interactions/CompositeActions.sol";
import "../../interactions/Deposits.sol";
import "../../interactions/TokenAssetData.sol";
import "../../interactions/TokenQuantization.sol";
Expand All @@ -30,6 +31,7 @@ contract TokensAndRamping is
KeyGetters,
Users,
Deposits,
CompositeActions,
Withdrawals
{
function initialize(
Expand Down

0 comments on commit 6db87ef

Please sign in to comment.