Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

Add gasPrice to 0x transactions #2084

Merged
merged 34 commits into from
Aug 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
74b9ad5
`@0x:contracts-exchange` Added unit tests for getCurrentContextAddress
jalextowle Aug 13, 2019
1724ecd
`@0x:contracts-exchange` Added unit tests for executeTransaction
jalextowle Aug 13, 2019
907771f
`@0x:contracts-exchange` Added unit tests for batchExecuteTransactions
jalextowle Aug 15, 2019
4b97090
`@0x:contracts-exchange` Removed code written to transactions
jalextowle Aug 15, 2019
d845b31
`@0x:contracts-exchange` Changed the signature validation stub functi…
jalextowle Aug 19, 2019
0253bba
`@0x:contracts-exchange` Addressed review comments by completely over…
jalextowle Aug 20, 2019
cd147db
`@0x:contracts-exchange` Fixed issues caused by rebase
jalextowle Aug 20, 2019
c1ed836
CI: Changed the `test-contracts-ganache-3.0` to run in stages to avoi…
jalextowle Aug 21, 2019
5733805
CI: Split contracts tests up into two seperate jobs to attempt to inc…
jalextowle Aug 21, 2019
67f9126
Add gasPrice to ZeroExTransaction struct
abandeali1 Aug 20, 2019
2134537
Add TransactionGasPriceError to LibExchangeRichErrors
abandeali1 Aug 20, 2019
47da971
Add _assertExecutableTransaction function and add gasPrice check
abandeali1 Aug 20, 2019
27e2a76
Update remaining contracts to use new transaction schema
abandeali1 Aug 20, 2019
1dd216b
Update ZeroExTransaction interface
abandeali1 Aug 20, 2019
e6b81a8
Update ZeroExTransaction schema
abandeali1 Aug 20, 2019
59369ce
Update transaction hashing and tests
abandeali1 Aug 20, 2019
23dd711
Update ZeroExTransaction tests
abandeali1 Aug 20, 2019
2b1e0be
Add default gasPrice to web3Wrapper instance and TransactionFactory
abandeali1 Aug 20, 2019
f41a29c
Fix weth tests
abandeali1 Aug 21, 2019
f32732d
Add TransactionGasPriceError rich revert class
abandeali1 Aug 21, 2019
9d38bf7
Add transaction gasPrice tests
abandeali1 Aug 21, 2019
a114bbb
Reduce code duplication in unit tests
abandeali1 Aug 21, 2019
eb6637a
Add public version of _assertExecutableTransaction
abandeali1 Aug 21, 2019
ca35eed
Add _assertExecutableTransaction unit tests
abandeali1 Aug 21, 2019
7b96fa8
Add more unit tests
abandeali1 Aug 21, 2019
44753bb
Add TransactionInvalidContextError and remove NO_REENTRANCY errorCode
abandeali1 Aug 22, 2019
edb923b
Use TransactionInvalidContextError in _assertExecutableTransaction
abandeali1 Aug 22, 2019
37cc948
Add TransactionInvalidContextError class
abandeali1 Aug 22, 2019
890bfd1
Update tests to use new TransactionInvalidContextError
abandeali1 Aug 22, 2019
5e51233
Address PR feedback
abandeali1 Aug 23, 2019
76c0708
Fix config.yml
abandeali1 Aug 23, 2019
8f8c16b
Add more recursion tests
abandeali1 Aug 23, 2019
830d6f7
Use default gasPrice in Forwarder tests
abandeali1 Aug 23, 2019
798fb18
Address remaining PR feedback
abandeali1 Aug 23, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ jobs:
keys:
- repo-{{ .Environment.CIRCLE_SHA1 }}
- run: yarn wsrun test:circleci @0x/contracts-multisig @0x/contracts-utils @0x/contracts-exchange-libs @0x/contracts-erc20 @0x/contracts-erc721 @0x/contracts-erc1155 @0x/contracts-extensions @0x/contracts-asset-proxy @0x/contracts-exchange @0x/contracts-exchange-forwarder @0x/contracts-coordinator @0x/contracts-dev-utils @0x/contracts-staking
test-contracts-ganache-3.0:
test-exchange-ganache-3.0:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clever girl
As requested.

resource_class: medium+
docker:
- image: nikolaik/python-nodejs:python3.7-nodejs8
Expand All @@ -100,7 +100,17 @@ jobs:
- restore_cache:
keys:
- repo-{{ .Environment.CIRCLE_SHA1 }}
- run: yarn wsrun test:circleci @0x/contracts-multisig @0x/contracts-utils @0x/contracts-exchange-libs @0x/contracts-erc20 @0x/contracts-erc721 @0x/contracts-erc1155 @0x/contracts-asset-proxy @0x/contracts-exchange @0x/contracts-exchange-forwarder @0x/contracts-dev-utils @0x/contracts-staking
- run: yarn wsrun test:circleci @0x/contracts-exchange
test-contracts-rest-ganache-3.0:
resource_class: medium+
docker:
- image: nikolaik/python-nodejs:python3.7-nodejs8
working_directory: ~/repo
steps:
- restore_cache:
keys:
- repo-{{ .Environment.CIRCLE_SHA1 }}
- run: yarn wsrun test:circleci @0x/contracts-multisig @0x/contracts-utils @0x/contracts-exchange-libs @0x/contracts-erc20 @0x/contracts-erc721 @0x/contracts-erc1155 @0x/contracts-asset-proxy @0x/contracts-exchange-forwarder @0x/contracts-dev-utils @0x/contracts-staking
# TODO(dorothy-zbornak): Re-enable after updating this package for 3.0.
# - run: yarn wsrun test:circleci @0x/contracts-extensions
# TODO(abandeali): Re-enable after this package is complete.
Expand Down Expand Up @@ -563,7 +573,10 @@ workflows:
# - build-website:
# requires:
# - build
- test-contracts-ganache-3.0:
- test-exchange-ganache-3.0:
requires:
- build-3.0
- test-contracts-rest-ganache-3.0:
requires:
- build-3.0
# Disabled until geth docker image is fixed.
Expand All @@ -590,7 +603,8 @@ workflows:
# - build-3.0
- submit-coverage-3.0:
requires:
- test-contracts-ganache-3.0
- test-contracts-rest-ganache-3.0
- test-exchange-ganache-3.0
- test-rest-3.0
- static-tests-3.0
# Disabled for 3.0
Expand Down
2 changes: 1 addition & 1 deletion contracts/erc20/test/weth9.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);

describe('EtherToken', () => {
let account: string;
const gasPrice = Web3Wrapper.toBaseUnitAmount(new BigNumber(20), 9);
const gasPrice = new BigNumber(constants.DEFAULT_GAS_PRICE);
let etherToken: WETH9Contract;

before(async () => {
Expand Down
8 changes: 2 additions & 6 deletions contracts/exchange-forwarder/test/forwarder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { artifacts, ForwarderContract, ForwarderTestFactory, ForwarderWrapper }

const DECIMALS_DEFAULT = 18;

blockchainTests.only(ContractName.Forwarder, env => {
blockchainTests(ContractName.Forwarder, env => {
let chainId: number;
let makerAddress: string;
let owner: string;
Expand All @@ -45,7 +45,7 @@ blockchainTests.only(ContractName.Forwarder, env => {
let tx: TransactionReceiptWithDecodedLogs;

let erc721MakerAssetIds: BigNumber[];
let gasPrice: BigNumber;
const gasPrice = new BigNumber(constants.DEFAULT_GAS_PRICE);

before(async () => {
await env.blockchainLifecycle.startAsync();
Expand All @@ -61,10 +61,6 @@ blockchainTests.only(ContractName.Forwarder, env => {
forwarderFeeRecipientAddress,
] = accounts);

const txHash = await env.web3Wrapper.sendTransactionAsync({ from: accounts[0], to: accounts[0], value: 0 });
const transaction = await env.web3Wrapper.getTransactionByHashAsync(txHash);
gasPrice = new BigNumber(transaction.gasPrice);

const erc721Wrapper = new ERC721Wrapper(env.provider, usedAddresses, owner);
erc20Wrapper = new ERC20Wrapper(env.provider, usedAddresses, owner);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ library LibExchangeRichErrors {
}

enum TransactionErrorCodes {
NO_REENTRANCY,
ALREADY_EXECUTED,
EXPIRED
}
Expand Down Expand Up @@ -131,6 +130,14 @@ library LibExchangeRichErrors {
// bytes4(keccak256("TransactionExecutionError(bytes32,bytes)"))
bytes4 internal constant TRANSACTION_EXECUTION_ERROR_SELECTOR =
0x20d11f61;

// bytes4(keccak256("TransactionGasPriceError(bytes32,uint256,uint256)"))
bytes4 internal constant TRANSACTION_GAS_PRICE_ERROR_SELECTOR =
0xa26dac09;

// bytes4(keccak256("TransactionInvalidContextError(bytes32,address)"))
bytes4 internal constant TRANSACTION_INVALID_CONTEXT_ERROR_SELECTOR =
0xdec4aedf;

// bytes4(keccak256("IncompleteFillError(uint8,uint256,uint256)"))
bytes4 internal constant INCOMPLETE_FILL_ERROR_SELECTOR =
Expand Down Expand Up @@ -293,6 +300,14 @@ library LibExchangeRichErrors {
return BATCH_MATCH_ORDERS_ERROR_SELECTOR;
}

function TransactionGasPriceErrorSelector()
internal
pure
returns (bytes4)
{
return TRANSACTION_GAS_PRICE_ERROR_SELECTOR;
}

function BatchMatchOrdersError(
BatchMatchOrdersErrorCodes errorCode
)
Expand Down Expand Up @@ -581,6 +596,38 @@ library LibExchangeRichErrors {
);
}

function TransactionGasPriceError(
bytes32 transactionHash,
uint256 actualGasPrice,
uint256 requiredGasPrice
)
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
TRANSACTION_GAS_PRICE_ERROR_SELECTOR,
transactionHash,
actualGasPrice,
requiredGasPrice
);
}

function TransactionInvalidContextError(
bytes32 transactionHash,
address currentContextAddress
)
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
TRANSACTION_INVALID_CONTEXT_ERROR_SELECTOR,
transactionHash,
currentContextAddress
);
}

function IncompleteFillError(
IncompleteFillErrorCode errorCode,
uint256 expectedAssetFillAmount,
Expand Down
33 changes: 19 additions & 14 deletions contracts/exchange-libs/contracts/src/LibZeroExTransaction.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,18 @@ library LibZeroExTransaction {
// keccak256(abi.encodePacked(
// "ZeroExTransaction(",
// "uint256 salt,",
// "uint256 expirationTimeSeconds,"
// "uint256 expirationTimeSeconds,",
// "uint256 gasPrice,",
// "address signerAddress,",
// "bytes data",
// ")"
// ));
bytes32 constant internal _EIP712_ZEROEX_TRANSACTION_SCHEMA_HASH = 0x6b4c70d217b44d0ff0d3bf7aeb18eb8604c5cd06f615a4b497aeefa4f01d2775;
bytes32 constant internal _EIP712_ZEROEX_TRANSACTION_SCHEMA_HASH = 0xec69816980a3a3ca4554410e60253953e9ff375ba4536a98adfa15cc71541508;

struct ZeroExTransaction {
uint256 salt; // Arbitrary number to ensure uniqueness of transaction hash.
uint256 expirationTimeSeconds; // Timestamp in seconds at which transaction expires.
uint256 gasPrice; // gasPrice at which transaction is required to be executed with.
address signerAddress; // Address of transaction signer.
bytes data; // AbiV2 encoded calldata.
}
Expand Down Expand Up @@ -72,15 +74,17 @@ library LibZeroExTransaction {
bytes memory data = transaction.data;
uint256 salt = transaction.salt;
uint256 expirationTimeSeconds = transaction.expirationTimeSeconds;
uint256 gasPrice = transaction.gasPrice;
address signerAddress = transaction.signerAddress;

// Assembly for more efficiently computing:
// keccak256(abi.encodePacked(
// EIP712_ZEROEX_TRANSACTION_SCHEMA_HASH,
// transaction.salt,
// transaction.expirationTimeSeconds,
// uint256(transaction.signerAddress),
// keccak256(transaction.data)
// result = keccak256(abi.encodePacked(
// schemaHash,
// salt,
// expirationTimeSeconds,
// gasPrice,
// uint256(signerAddress),
// keccak256(data)
// ));

assembly {
Expand All @@ -90,14 +94,15 @@ library LibZeroExTransaction {
// Load free memory pointer
let memPtr := mload(64)

mstore(memPtr, schemaHash) // hash of schema
mstore(add(memPtr, 32), salt) // salt
mstore(add(memPtr, 64), expirationTimeSeconds) // expirationTimeSeconds
mstore(add(memPtr, 96), and(signerAddress, 0xffffffffffffffffffffffffffffffffffffffff)) // signerAddress
mstore(add(memPtr, 128), dataHash) // hash of data
mstore(memPtr, schemaHash) // hash of schema
mstore(add(memPtr, 32), salt) // salt
mstore(add(memPtr, 64), expirationTimeSeconds) // expirationTimeSeconds
mstore(add(memPtr, 96), gasPrice) // gasPrice
mstore(add(memPtr, 128), and(signerAddress, 0xffffffffffffffffffffffffffffffffffffffff)) // signerAddress
mstore(add(memPtr, 160), dataHash) // hash of data

// Compute hash
result := keccak256(memPtr, 160)
result := keccak256(memPtr, 192)
}
return result;
}
Expand Down
3 changes: 3 additions & 0 deletions contracts/exchange-libs/test/lib_zero_ex_transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ blockchainTests('LibZeroExTransaction', env => {
const EMPTY_TRANSACTION: ZeroExTransaction = {
salt: constants.ZERO_AMOUNT,
expirationTimeSeconds: constants.ZERO_AMOUNT,
gasPrice: constants.ZERO_AMOUNT,
signerAddress: constants.NULL_ADDRESS,
data: constants.NULL_BYTES,
domain: {
Expand Down Expand Up @@ -66,6 +67,7 @@ blockchainTests('LibZeroExTransaction', env => {
await testGetTypedDataHashAsync({
salt: randomUint256(),
expirationTimeSeconds: randomUint256(),
gasPrice: randomUint256(),
signerAddress: randomAddress(),
data: randomAssetData(),
domain: {
Expand Down Expand Up @@ -121,6 +123,7 @@ blockchainTests('LibZeroExTransaction', env => {
await testGetStructHashAsync({
salt: randomUint256(),
expirationTimeSeconds: randomUint256(),
gasPrice: randomUint256(),
signerAddress: randomAddress(),
data: randomAssetData(),
// The domain is not used in this test, so it's okay if it is left empty.
Expand Down
2 changes: 2 additions & 0 deletions contracts/exchange/contracts/examples/ExchangeWrapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ contract ExchangeWrapper {
LibZeroExTransaction.ZeroExTransaction memory transaction = LibZeroExTransaction.ZeroExTransaction({
salt: salt,
expirationTimeSeconds: transactionExpirationTimeSeconds,
gasPrice: tx.gasprice,
data: data,
signerAddress: makerAddress
});
Expand Down Expand Up @@ -99,6 +100,7 @@ contract ExchangeWrapper {
LibZeroExTransaction.ZeroExTransaction memory transaction = LibZeroExTransaction.ZeroExTransaction({
salt: salt,
expirationTimeSeconds: transactionExpirationTimeSeconds,
gasPrice: tx.gasprice,
data: data,
signerAddress: takerAddress
});
Expand Down
1 change: 1 addition & 0 deletions contracts/exchange/contracts/examples/Whitelist.sol
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ contract Whitelist is
LibZeroExTransaction.ZeroExTransaction memory transaction = LibZeroExTransaction.ZeroExTransaction({
salt: salt,
data: data,
gasPrice: tx.gasprice,
expirationTimeSeconds: uint256(-1),
signerAddress: takerAddress
});
Expand Down
7 changes: 5 additions & 2 deletions contracts/exchange/contracts/src/MixinExchangeCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -361,11 +361,14 @@ contract MixinExchangeCore is
orderInfo.orderHash,
makerAddress,
signature
)) {
)
) {
if (!_isValidOrderWithHashSignature(
order,
orderInfo.orderHash,
signature)) {
signature
)
) {
LibRichErrors.rrevert(LibExchangeRichErrors.SignatureError(
LibExchangeRichErrors.SignatureErrorCodes.BAD_SIGNATURE,
orderInfo.orderHash,
Expand Down
Loading