diff options
author | Greg Hysen <greg.hysen@gmail.com> | 2018-11-30 10:24:19 +0800 |
---|---|---|
committer | Greg Hysen <greg.hysen@gmail.com> | 2018-12-19 05:36:05 +0800 |
commit | 4e341582ae74d7ab1c52c4e888d72c0c1c78e890 (patch) | |
tree | 058c63bc5dda350994f6ad936c7d47fb1bd5c2ba /packages | |
parent | 37a1271af256af2c0a64b947b3c212a749b540b0 (diff) | |
download | dexon-0x-contracts-4e341582ae74d7ab1c52c4e888d72c0c1c78e890.tar.gz dexon-0x-contracts-4e341582ae74d7ab1c52c4e888d72c0c1c78e890.tar.zst dexon-0x-contracts-4e341582ae74d7ab1c52c4e888d72c0c1c78e890.zip |
Extract makerAddress in assembly
Diffstat (limited to 'packages')
-rw-r--r-- | packages/contracts/contracts/extensions/CompliantForwarder/CompliantForwarder.sol | 42 | ||||
-rw-r--r-- | packages/contracts/test/extensions/compliant_forwarder.ts | 16 |
2 files changed, 50 insertions, 8 deletions
diff --git a/packages/contracts/contracts/extensions/CompliantForwarder/CompliantForwarder.sol b/packages/contracts/contracts/extensions/CompliantForwarder/CompliantForwarder.sol index 7a4c8d2f6..b8ba43b15 100644 --- a/packages/contracts/contracts/extensions/CompliantForwarder/CompliantForwarder.sol +++ b/packages/contracts/contracts/extensions/CompliantForwarder/CompliantForwarder.sol @@ -31,6 +31,8 @@ contract CompliantForwarder { IExchange internal EXCHANGE; IERC721Token internal COMPLIANCE_TOKEN; + bytes4 constant internal EXCHANGE_FILL_ORDER_SELECTOR_2 = 0xb4be83d5; + constructor(address exchange, address complianceToken) public { @@ -41,17 +43,43 @@ contract CompliantForwarder { function executeTransaction( uint256 salt, address signerAddress, - bytes signedFillOrderTransaction, + bytes signedExchangeTransaction, bytes signature ) - public + external { // Validate `signedFillOrderTransaction` - bytes4 selector = signedFillOrderTransaction.readBytes4(0); - if (selector != EXCHANGE_FILL_ORDER_SELECTOR) { - revert("EXCHANGE_TRANSACTION_NOT_FILL_ORDER"); + bytes4 selector = signedExchangeTransaction.readBytes4(0); + address makerAddress = 0x00; + assembly { + function getMakerAddress(orderPtr) -> makerAddress { + let orderOffset := calldataload(orderPtr) + makerAddress := calldataload(orderOffset) + } + + switch selector + case 0xb4be83d500000000000000000000000000000000000000000000000000000000 { + let exchangeTxPtr := calldataload(0x44) + + // Add 0x20 for length offset and 0x04 for selector offset + let orderPtrRelativeToExchangeTx := calldataload(add(0x4, add(exchangeTxPtr, 0x24))) // 0x60 + let orderPtr := add(0x4,add(exchangeTxPtr, add(0x24, orderPtrRelativeToExchangeTx))) + + makerAddress := calldataload(orderPtr) + + + //makerAddress := getMakerAddress(orderPtr) + } + default { + // revert(0, 100) + } } + /* + if (selector != 0xb4be83d5) { + revert("EXCHANGE_TRANSACTION_NOT_FILL_ORDER"); + }*/ + // Taker must be compliant require( COMPLIANCE_TOKEN.balanceOf(signerAddress) > 0, @@ -87,7 +115,7 @@ contract CompliantForwarder { // Add 0x4 to a given offset to account for the fillOrder selector prepended to `signedFillOrderTransaction`. // Add 0xc to the makerAddress since abi-encoded addresses are left padded with 12 bytes. // Putting this together: makerAddress = 0x60 + 0x4 + 0xc = 0x70 - address makerAddress = signedFillOrderTransaction.readAddress(0x70); + //address makerAddress = signedExchangeTransaction.readAddress(0x70); require( COMPLIANCE_TOKEN.balanceOf(makerAddress) > 0, "MAKER_UNVERIFIED" @@ -97,7 +125,7 @@ contract CompliantForwarder { EXCHANGE.executeTransaction( salt, signerAddress, - signedFillOrderTransaction, + signedExchangeTransaction, signature ); } diff --git a/packages/contracts/test/extensions/compliant_forwarder.ts b/packages/contracts/test/extensions/compliant_forwarder.ts index c962d82ac..b916f54c9 100644 --- a/packages/contracts/test/extensions/compliant_forwarder.ts +++ b/packages/contracts/test/extensions/compliant_forwarder.ts @@ -26,6 +26,9 @@ import { TransactionFactory } from '../utils/transaction_factory'; import { ContractName, ERC20BalancesByOwner, SignedTransaction } from '../utils/types'; import { provider, txDefaults, web3Wrapper } from '../utils/web3_wrapper'; +import { MethodAbi } from 'ethereum-types'; +import { AbiEncoder } from '@0x/utils'; + chaiSetup.configure(); const expect = chai.expect; const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); @@ -192,7 +195,18 @@ describe.only(ContractName.CompliantForwarder, () => { beforeEach(async () => { erc20Balances = await erc20Wrapper.getBalancesAsync(); }); - it('should transfer the correct amounts when maker and taker are compliant', async () => { + it.only('should transfer the correct amounts when maker and taker are compliant', async () => { + + + const method = new AbiEncoder.Method(compliantForwarderInstance.abi[0] as MethodAbi); + const args = [ + compliantSignedFillOrderTx.salt, + compliantSignedFillOrderTx.signerAddress, + compliantSignedFillOrderTx.data, + compliantSignedFillOrderTx.signature + ]; + console.log(method.encode(args, {annotate: true})); + await compliantForwarderInstance.executeTransaction.sendTransactionAsync( compliantSignedFillOrderTx.salt, compliantSignedFillOrderTx.signerAddress, |