Updated length to match comment + added explicit test

This commit is contained in:
Greg Hysen
2019-06-04 17:00:32 -07:00
parent e7c4120d24
commit d66ba70f5e
2 changed files with 29 additions and 1 deletions

View File

@@ -166,7 +166,7 @@ contract ERC1155Proxy is
// Assert that the length of asset data:
// 1. Must be at least 132 bytes (Table #2)
// 2. Must be a multiple of 32 (excluding the 4-byte selector)
if or(lt(assetDataLength, 100), mod(sub(assetDataLength, 4), 32)) {
if or(lt(assetDataLength, 132), mod(sub(assetDataLength, 4), 32)) {
// Revert with `Error("INVALID_ASSET_DATA_LENGTH")`
mstore(0, 0x08c379a000000000000000000000000000000000000000000000000000000000)
mstore(32, 0x0000002000000000000000000000000000000000000000000000000000000000)

View File

@@ -1382,6 +1382,34 @@ describe('ERC1155Proxy', () => {
RevertReason.InvalidAssetDataLength
);
});
it('should revert if length of assetData is less than 132 bytes', async () => {
// setup test parameters
const tokensToTransfer = fungibleTokens.slice(0, 1);
const valuesToTransfer = [fungibleValueToTransferLarge];
const valueMultiplier = valueMultiplierSmall;
// we'll construct asset data that has a 4 byte selector plus
// 96 byte payload. This results in asset data that is 100 bytes
// long and will trigger the `invalid length` error.
// we must be sure to use a # of bytes that is still %32
// so that we know the error is not triggered by another check in the code.
const zeros96Bytes = "0".repeat(188);
const assetData131Bytes = `${AssetProxyId.ERC1155}${zeros96Bytes}`;
// execute transfer
await expectTransactionFailedAsync(
erc1155ProxyWrapper.transferFromWithLogsAsync(
spender,
receiverContract,
erc1155Contract.address,
tokensToTransfer,
valuesToTransfer,
valueMultiplier,
receiverCallbackData,
authorized,
assetData131Bytes,
),
RevertReason.InvalidAssetDataLength
);
});
it('should transfer nothing if value is zero', async () => {
// setup test parameters
const tokenHolders = [spender, receiver];