/// <summary> /// Returns xor of metadata source hashes. If there are no source hashes, returns the /// hash of the json abi string. /// </summary> /// <param name="contract"></param> /// <returns></returns> byte[] GetSourceHashesXor(SolcNet.DataDescription.Output.Contract contract) { if (string.IsNullOrEmpty(contract.Metadata)) { return(KeccakHashString(_assemblyVersion + "\n" + contract.AbiJsonString)); } var hashes = JObject.Parse(contract.Metadata) .SelectTokens("sources.*.keccak256") .Values <string>() .ToArray(); Span <byte> hashBuff = new byte[32]; Span <ulong> hashBuffLong = MemoryMarshal.Cast <byte, ulong>(hashBuff); byte[] resultBuffer = new byte[32]; KeccakHashString(_assemblyVersion, resultBuffer); Span <ulong> resultBufferLong = MemoryMarshal.Cast <byte, ulong>(resultBuffer); for (var i = 0; i < hashes.Length; i++) { var hash = hashes[i].AsSpan(2, 64); HexUtil.HexToSpan(hash, hashBuff); for (var j = 0; j < resultBufferLong.Length; j++) { resultBufferLong[j] ^= hashBuffLong[j]; } } return(resultBuffer); }