Add offset to signature

This commit is contained in:
Remco Bloemen
2018-02-26 15:09:14 -08:00
committed by Amir Bandeali
parent 58c5e800d0
commit a4f294c090

View File

@@ -63,7 +63,7 @@ contract MixinWrapperFunctions is
{
// We need to call MExchangeCore.fillOrder using a delegatecall in
// assembly so that we can intercept a call that throws. For this, we
// need the input encoded in memory in the Ethereum ABI format [1].
// need the input encoded in memory in the Ethereum ABIv2 format [1].
//
// | Offset | Length | Contents |
// |--------|--------|------------------------------|
@@ -71,22 +71,23 @@ contract MixinWrapperFunctions is
// | 4 | 160 | address[5] orderAddresses |
// | 164 | 192 | uint256[6] orderValues |
// | 356 | 32 | uint256 takerTokenFillAmount |
// | 388 | 32 | len(signature) |
// | 420 | (1) | signature |
// | 388 | 32 | offset to signature (416) |
// | 420 | 32 | len(signature) |
// | 452 | (1) | signature |
// | (2) | (3) | padding (zero) |
// | (4) | | end of input |
//
// (1): len(signature)
// (2): 420 + len(signature)
// (2): 452 + len(signature)
// (3): (32 - len(signature)) mod 32
// (4): 420 + len(signature) + (32 - len(signature)) mod 32
// (4): 452 + len(signature) + (32 - len(signature)) mod 32
//
// [1]: https://solidity.readthedocs.io/en/develop/abi-spec.html
// Allocate memory for input
uint256 signatureLength = signature.length;
uint256 paddingLength = (32 - signatureLength) % 32
uint256 inputSize = 420 + signatureLength + paddingLength;
uint256 inputSize = 452 + signatureLength + paddingLength;
bytes memory input = new bytes(inputSize);
// The in memory layout of `bytes memory input` starts with
@@ -108,8 +109,8 @@ contract MixinWrapperFunctions is
mstore(start, FILL_ORDER_FUNCTION_SIGNATURE);
}
// Write orderAddresses, orderValues, takerTokenFillAmount
// and len(signature)
// Write orderAddresses, orderValues, takerTokenFillAmount,
// offset to signature and len(signature)
// It is done in assembly so we can write 32 bytes at a time. In
// solidity we would have to copy one byte at a time.
// Fixed size arrays do not have the `uint256 length` prefix that
@@ -126,15 +127,16 @@ contract MixinWrapperFunctions is
mstore(add(start, 260), add(orderValues, 96)) // takerFee
mstore(add(start, 292), add(orderValues, 128)) // expiration
mstore(add(start, 356), takerTokenFillAmount)
mstore(add(start, 388), signatureLength)
mstore(add(start, 388), 416)
mstore(add(start, 420), signatureLength)
}
// Write signature contents and padding one byte at a time
for (uint256 i = 0; i < signatureLength; i++) {
input[420 + i] = signature[i];
input[452 + i] = signature[i];
}
for (uint256 i = 0; i < paddingLength; i++) {
input[420 + signatureLength + i] = 0x00;
input[452 + signatureLength + i] = 0x00;
}
// Call the function