@@ -96,12 +96,10 @@ library InteroperableAddress {
9696 bytes memory self
9797 ) internal pure returns (bool success , bytes2 chainType , bytes memory chainReference , bytes memory addr ) {
9898 unchecked {
99- success = true ;
10099 if (self.length < 0x06 ) return (false , 0x0000 , _emptyBytesMemory (), _emptyBytesMemory ());
101100
102101 bytes2 version = _readBytes2 (self, 0x00 );
103102 if (version != bytes2 (0x0001 )) return (false , 0x0000 , _emptyBytesMemory (), _emptyBytesMemory ());
104- chainType = _readBytes2 (self, 0x02 );
105103
106104 uint8 chainReferenceLength = uint8 (self[0x04 ]);
107105 if (self.length < 0x06 + chainReferenceLength)
@@ -112,6 +110,10 @@ library InteroperableAddress {
112110 if (self.length < 0x06 + chainReferenceLength + addrLength)
113111 return (false , 0x0000 , _emptyBytesMemory (), _emptyBytesMemory ());
114112 addr = self.slice (0x06 + chainReferenceLength, 0x06 + chainReferenceLength + addrLength);
113+
114+ // At least one of chainReference or addr must be non-empty
115+ success = (chainReferenceLength > 0 ) || (addrLength > 0 );
116+ chainType = success ? _readBytes2 (self, 0x02 ) : bytes2 (0 );
115117 }
116118 }
117119
@@ -122,12 +124,10 @@ library InteroperableAddress {
122124 bytes calldata self
123125 ) internal pure returns (bool success , bytes2 chainType , bytes calldata chainReference , bytes calldata addr ) {
124126 unchecked {
125- success = true ;
126127 if (self.length < 0x06 ) return (false , 0x0000 , Calldata.emptyBytes (), Calldata.emptyBytes ());
127128
128129 bytes2 version = _readBytes2Calldata (self, 0x00 );
129130 if (version != bytes2 (0x0001 )) return (false , 0x0000 , Calldata.emptyBytes (), Calldata.emptyBytes ());
130- chainType = _readBytes2Calldata (self, 0x02 );
131131
132132 uint8 chainReferenceLength = uint8 (self[0x04 ]);
133133 if (self.length < 0x06 + chainReferenceLength)
@@ -138,6 +138,10 @@ library InteroperableAddress {
138138 if (self.length < 0x06 + chainReferenceLength + addrLength)
139139 return (false , 0x0000 , Calldata.emptyBytes (), Calldata.emptyBytes ());
140140 addr = self[0x06 + chainReferenceLength:0x06 + chainReferenceLength + addrLength];
141+
142+ // At least one of chainReference or addr must be non-empty
143+ success = (chainReferenceLength > 0 ) || (addrLength > 0 );
144+ chainType = success ? _readBytes2Calldata (self, 0x02 ) : bytes2 (0 );
141145 }
142146 }
143147
0 commit comments