Skip to content
This repository has been archived by the owner on Mar 12, 2024. It is now read-only.

Commit

Permalink
refactor(contracts)!: encode inputs with strict mode
Browse files Browse the repository at this point in the history
BREAKING CHANGE: changed the encoding of inputs added by input relays
  • Loading branch information
guidanoli committed Aug 16, 2023
1 parent f94eeb0 commit 799c86f
Showing 1 changed file with 18 additions and 43 deletions.
61 changes: 18 additions & 43 deletions onchain/rollups/contracts/common/InputEncoding.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@ library InputEncoding {
uint256 value,
bytes calldata execLayerData
) internal pure returns (bytes memory) {
return
abi.encodePacked(
sender, // 20B
value, // 32B
execLayerData // arbitrary size
);
return abi.encode(sender, value, execLayerData);
}

/// @notice Encode an ERC-20 token deposit.
Expand All @@ -44,14 +39,7 @@ library InputEncoding {
uint256 amount,
bytes calldata execLayerData
) internal pure returns (bytes memory) {
return
abi.encodePacked(
ret, // 1B
token, // 20B
sender, // 20B
amount, // 32B
execLayerData // arbitrary size
);
return abi.encode(ret, token, sender, amount, execLayerData);
}

/// @notice Encode an ERC-721 token deposit.
Expand All @@ -69,14 +57,7 @@ library InputEncoding {
bytes calldata baseLayerData,
bytes calldata execLayerData
) internal pure returns (bytes memory) {
bytes memory data = abi.encode(baseLayerData, execLayerData);
return
abi.encodePacked(
token, // 20B
sender, // 20B
tokenId, // 32B
data // arbitrary size
);
return abi.encode(token, sender, tokenId, baseLayerData, execLayerData);
}

/// @notice Encode an ERC-1155 single token deposit.
Expand All @@ -96,14 +77,14 @@ library InputEncoding {
bytes calldata baseLayerData,
bytes calldata execLayerData
) internal pure returns (bytes memory) {
bytes memory data = abi.encode(baseLayerData, execLayerData);
return
abi.encodePacked(
token, // 20B
sender, // 20B
tokenId, // 32B
value, // 32B
data // arbitrary size
abi.encode(
token,
sender,
tokenId,
value,
baseLayerData,
execLayerData
);
}

Expand All @@ -124,17 +105,14 @@ library InputEncoding {
bytes calldata baseLayerData,
bytes calldata execLayerData
) internal pure returns (bytes memory) {
bytes memory data = abi.encode(
tokenIds,
values,
baseLayerData,
execLayerData
);
return
abi.encodePacked(
token, // 20B
sender, // 20B
data // arbitrary size
abi.encode(
token,
sender,
tokenIds,
values,
baseLayerData,
execLayerData
);
}

Expand All @@ -144,9 +122,6 @@ library InputEncoding {
function encodeDAppAddressRelay(
address dapp
) internal pure returns (bytes memory) {
return
abi.encodePacked(
dapp // 20B
);
return abi.encode(dapp);
}
}

0 comments on commit 799c86f

Please sign in to comment.