Omniscia Evergon Labs Audit

OmnichainIdentifiers Manual Review Findings

OmnichainIdentifiers Manual Review Findings

OIS-01M: Incorrect Bitwise Shift of Identifier

Description:

The OmnichainIdentifier is improperly decoded as a shift operation by 32 bits occurs which is incorrect as the right-most bits already contain the full 224 bits of the identifier.

Impact:

The decoding of an OmnichainIdentifier is presently incorrect as it will shift the data point by 32 bits to the left thus malforming data and losing the upper-most 32 bits.

Example:

contracts/utils/OmnichainIdentifiers.sol
33/**
34 * @dev Encode OmnichainIdentifier
35 * @param chainid Chain ID to encode
36 * @param identifier Numeric identifier
37 * @return Encoded OmnichainIdentifier
38 */
39function encode(uint32 chainid, uint224 identifier) internal pure returns (OmnichainIdentifier) {
40 return OmnichainIdentifier.wrap((uint256(chainid) << 224) | identifier);
41}
42
43/**
44 * @dev Decode OmnichainIdentifier
45 * @param oi OmnichainIdentifier to decode
46 * @return chainid Chain ID of the OmnichainIdentifier
47 * @return identifier Numeric identifier of the OmnichainIdentifier
48 */
49function decode(OmnichainIdentifier oi) internal pure returns (uint32 chainid, uint224 identifier) {
50 uint256 oiu = uint256(OmnichainIdentifier.unwrap(oi));
51 identifier = uint224(oiu << 32);
52 chainid = uint32(oiu >> 224);
53}

Recommendation:

We advise a truncation operation to occur either by directly casting the oiu to the uint224 data type or by shifting to the left and then to the right by 32 bits, either of which is an acceptable alleviation to this exhibit.

Alleviation (c6b23c23d8bcd8cce85049ad959cbd711a37126b):

The code was updated to omit the bitwise shift operation occurring for the identifier, alleviating this exhibit.