diff options
author | Amir Bandeali <abandeali1@gmail.com> | 2018-08-08 04:54:34 +0800 |
---|---|---|
committer | Amir Bandeali <abandeali1@gmail.com> | 2018-08-09 06:44:43 +0800 |
commit | 1fb3da6b5325497ea18f17dc61cf50aed7bcfc95 (patch) | |
tree | c9e533abce373fac3fcd4226f516e2b8e0426222 /packages/contracts/src/2.0.0 | |
parent | 970bef717e422ac79901300b56ac8f11d3593685 (diff) | |
download | dexon-sol-tools-1fb3da6b5325497ea18f17dc61cf50aed7bcfc95.tar.gz dexon-sol-tools-1fb3da6b5325497ea18f17dc61cf50aed7bcfc95.tar.zst dexon-sol-tools-1fb3da6b5325497ea18f17dc61cf50aed7bcfc95.zip |
Increment free memory pointer for internal Exchange functions that use asm
Diffstat (limited to 'packages/contracts/src/2.0.0')
3 files changed, 34 insertions, 12 deletions
diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/MixinAssetProxyDispatcher.sol b/packages/contracts/src/2.0.0/protocol/Exchange/MixinAssetProxyDispatcher.sol index e9f882194..b34903668 100644 --- a/packages/contracts/src/2.0.0/protocol/Exchange/MixinAssetProxyDispatcher.sol +++ b/packages/contracts/src/2.0.0/protocol/Exchange/MixinAssetProxyDispatcher.sol @@ -159,18 +159,22 @@ contract MixinAssetProxyDispatcher is } /////// Call `assetProxy.transferFrom` using the constructed calldata /////// + let inputLen := sub(cdEnd, cdStart) let success := call( gas, // forward all gas assetProxy, // call address of asset proxy 0, // don't send any ETH cdStart, // pointer to start of input - sub(cdEnd, cdStart), // length of input + inputLen, // length of input cdStart, // write output over input 512 // reserve 512 bytes for output ) if iszero(success) { revert(cdStart, returndatasize()) } + + // Increment free memory pointer + mstore(64, add(cdStart, inputLen)) } } } diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/libs/LibAbiEncoder.sol b/packages/contracts/src/2.0.0/protocol/Exchange/libs/LibAbiEncoder.sol index 704c7061c..f047342b3 100644 --- a/packages/contracts/src/2.0.0/protocol/Exchange/libs/LibAbiEncoder.sol +++ b/packages/contracts/src/2.0.0/protocol/Exchange/libs/LibAbiEncoder.sol @@ -24,20 +24,17 @@ import "./LibOrder.sol"; contract LibAbiEncoder { - /// @dev ABI encodes calldata for `fillOrder` in memory and returns the address range. - /// This range can be passed into `call` or `delegatecall` to invoke an external - /// call to `fillOrder`. + /// @dev ABI encodes calldata for `fillOrder`. /// @param order Order struct containing order specifications. /// @param takerAssetFillAmount Desired amount of takerAsset to sell. /// @param signature Proof that order has been created by maker. - /// @return calldataBegin Memory address of ABI encoded calldata. - /// @return calldataLength Lenfgth of ABI encoded calldata. + /// @return ABI encoded calldata for `fillOrder`. function abiEncodeFillOrder( LibOrder.Order memory order, uint256 takerAssetFillAmount, bytes memory signature ) - public + internal pure returns (bytes memory fillOrderCalldata) { @@ -207,10 +204,11 @@ contract LibAbiEncoder { } // Set length of calldata - mstore( - fillOrderCalldata, - sub(dataAreaEnd, add(fillOrderCalldata, 0x20)) - ) + let calldataLen := sub(dataAreaEnd, add(fillOrderCalldata, 0x20)) + mstore(fillOrderCalldata, calldataLen) + + // Increment free memory pointer + mstore(0x40, add(fillOrderCalldata, add(calldataLen, 0x20))) } return fillOrderCalldata; diff --git a/packages/contracts/src/2.0.0/test/TestLibs/TestLibs.sol b/packages/contracts/src/2.0.0/test/TestLibs/TestLibs.sol index 5a349527b..4a99dd9c1 100644 --- a/packages/contracts/src/2.0.0/test/TestLibs/TestLibs.sol +++ b/packages/contracts/src/2.0.0/test/TestLibs/TestLibs.sol @@ -22,13 +22,33 @@ pragma experimental ABIEncoderV2; import "../../protocol/Exchange/libs/LibMath.sol"; import "../../protocol/Exchange/libs/LibOrder.sol"; import "../../protocol/Exchange/libs/LibFillResults.sol"; +import "../../protocol/Exchange/libs/LibAbiEncoder.sol"; contract TestLibs is LibMath, LibOrder, - LibFillResults + LibFillResults, + LibAbiEncoder { + + function publicAbiEncodeFillOrder( + Order memory order, + uint256 takerAssetFillAmount, + bytes memory signature + ) + public + pure + returns (bytes memory fillOrderCalldata) + { + fillOrderCalldata = abiEncodeFillOrder( + order, + takerAssetFillAmount, + signature + ); + return fillOrderCalldata; + } + function publicGetPartialAmount( uint256 numerator, uint256 denominator, |