aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/src/2.0.0/protocol/Exchange/MixinTransactions.sol
diff options
context:
space:
mode:
authorAlex Browne <stephenalexbrowne@gmail.com>2018-10-02 07:44:13 +0800
committerAlex Browne <stephenalexbrowne@gmail.com>2018-10-16 04:36:09 +0800
commit81c48872415998e53ad653aabf183e18257ec327 (patch)
tree47e73fbdf817941414fa06035d5e568ee7d34ddb /packages/contracts/src/2.0.0/protocol/Exchange/MixinTransactions.sol
parent83a36aff3fa750560cf6dd6b08b84a5915ea4c5d (diff)
downloaddexon-sol-tools-81c48872415998e53ad653aabf183e18257ec327.tar
dexon-sol-tools-81c48872415998e53ad653aabf183e18257ec327.tar.gz
dexon-sol-tools-81c48872415998e53ad653aabf183e18257ec327.tar.bz2
dexon-sol-tools-81c48872415998e53ad653aabf183e18257ec327.tar.lz
dexon-sol-tools-81c48872415998e53ad653aabf183e18257ec327.tar.xz
dexon-sol-tools-81c48872415998e53ad653aabf183e18257ec327.tar.zst
dexon-sol-tools-81c48872415998e53ad653aabf183e18257ec327.zip
Move generated contract wrappers and artifacts into contracts package
Diffstat (limited to 'packages/contracts/src/2.0.0/protocol/Exchange/MixinTransactions.sol')
-rw-r--r--packages/contracts/src/2.0.0/protocol/Exchange/MixinTransactions.sol152
1 files changed, 0 insertions, 152 deletions
diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/MixinTransactions.sol b/packages/contracts/src/2.0.0/protocol/Exchange/MixinTransactions.sol
deleted file mode 100644
index 3a76ca202..000000000
--- a/packages/contracts/src/2.0.0/protocol/Exchange/MixinTransactions.sol
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
-
- Copyright 2018 ZeroEx Intl.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
-*/
-pragma solidity 0.4.24;
-
-import "./libs/LibExchangeErrors.sol";
-import "./mixins/MSignatureValidator.sol";
-import "./mixins/MTransactions.sol";
-import "./libs/LibEIP712.sol";
-
-
-contract MixinTransactions is
- LibEIP712,
- MSignatureValidator,
- MTransactions
-{
- // Mapping of transaction hash => executed
- // This prevents transactions from being executed more than once.
- mapping (bytes32 => bool) public transactions;
-
- // Address of current transaction signer
- address public currentContextAddress;
-
- /// @dev Executes an exchange method call in the context of signer.
- /// @param salt Arbitrary number to ensure uniqueness of transaction hash.
- /// @param signerAddress Address of transaction signer.
- /// @param data AbiV2 encoded calldata.
- /// @param signature Proof of signer transaction by signer.
- function executeTransaction(
- uint256 salt,
- address signerAddress,
- bytes data,
- bytes signature
- )
- external
- {
- // Prevent reentrancy
- require(
- currentContextAddress == address(0),
- "REENTRANCY_ILLEGAL"
- );
-
- bytes32 transactionHash = hashEIP712Message(hashZeroExTransaction(
- salt,
- signerAddress,
- data
- ));
-
- // Validate transaction has not been executed
- require(
- !transactions[transactionHash],
- "INVALID_TX_HASH"
- );
-
- // Transaction always valid if signer is sender of transaction
- if (signerAddress != msg.sender) {
- // Validate signature
- require(
- isValidSignature(
- transactionHash,
- signerAddress,
- signature
- ),
- "INVALID_TX_SIGNATURE"
- );
-
- // Set the current transaction signer
- currentContextAddress = signerAddress;
- }
-
- // Execute transaction
- transactions[transactionHash] = true;
- require(
- address(this).delegatecall(data),
- "FAILED_EXECUTION"
- );
-
- // Reset current transaction signer if it was previously updated
- if (signerAddress != msg.sender) {
- currentContextAddress = address(0);
- }
- }
-
- /// @dev Calculates EIP712 hash of the Transaction.
- /// @param salt Arbitrary number to ensure uniqueness of transaction hash.
- /// @param signerAddress Address of transaction signer.
- /// @param data AbiV2 encoded calldata.
- /// @return EIP712 hash of the Transaction.
- function hashZeroExTransaction(
- uint256 salt,
- address signerAddress,
- bytes memory data
- )
- internal
- pure
- returns (bytes32 result)
- {
- bytes32 schemaHash = EIP712_ZEROEX_TRANSACTION_SCHEMA_HASH;
- bytes32 dataHash = keccak256(data);
-
- // Assembly for more efficiently computing:
- // keccak256(abi.encodePacked(
- // EIP712_ZEROEX_TRANSACTION_SCHEMA_HASH,
- // salt,
- // bytes32(signerAddress),
- // keccak256(data)
- // ));
-
- assembly {
- // Load free memory pointer
- let memPtr := mload(64)
-
- mstore(memPtr, schemaHash) // hash of schema
- mstore(add(memPtr, 32), salt) // salt
- mstore(add(memPtr, 64), and(signerAddress, 0xffffffffffffffffffffffffffffffffffffffff)) // signerAddress
- mstore(add(memPtr, 96), dataHash) // hash of data
-
- // Compute hash
- result := keccak256(memPtr, 128)
- }
- return result;
- }
-
- /// @dev The current function will be called in the context of this address (either 0x transaction signer or `msg.sender`).
- /// If calling a fill function, this address will represent the taker.
- /// If calling a cancel function, this address will represent the maker.
- /// @return Signer of 0x transaction if entry point is `executeTransaction`.
- /// `msg.sender` if entry point is any other function.
- function getCurrentContextAddress()
- internal
- view
- returns (address)
- {
- address currentContextAddress_ = currentContextAddress;
- address contextAddress = currentContextAddress_ == address(0) ? msg.sender : currentContextAddress_;
- return contextAddress;
- }
-}