diff --git a/src/Nethermind/Nethermind.Consensus/ExecutionRequests/ExecutionRequestProcessor.cs b/src/Nethermind/Nethermind.Consensus/ExecutionRequests/ExecutionRequestProcessor.cs index 9827bc6b4c0..091a93312f2 100644 --- a/src/Nethermind/Nethermind.Consensus/ExecutionRequests/ExecutionRequestProcessor.cs +++ b/src/Nethermind/Nethermind.Consensus/ExecutionRequests/ExecutionRequestProcessor.cs @@ -57,13 +57,15 @@ public IEnumerable ProcessDeposits(TxReceipt[] receipts, IRele private ExecutionRequest DecodeDepositRequest(LogEntry log) { object[] result = _abiEncoder.Decode(AbiEncodingStyle.None, _depositEventABI, log.Data); - List flattenedResult = new List(); + byte[] flattenedResult = new byte[depositRequestsBytesSize]; + int offset = 0; foreach (var item in result) { if (item is byte[] byteArray) { - flattenedResult.AddRange(byteArray); + Array.Copy(byteArray, 0, flattenedResult, offset, byteArray.Length); + offset += byteArray.Length; } else { @@ -72,15 +74,15 @@ private ExecutionRequest DecodeDepositRequest(LogEntry log) } // make sure the flattened result is of the correct size - if (flattenedResult.Count != depositRequestsBytesSize) + if (offset != depositRequestsBytesSize) { - throw new InvalidOperationException($"Decoded ABI result has incorrect size. Expected {depositRequestsBytesSize} bytes, got {flattenedResult.Count} bytes."); + throw new InvalidOperationException($"Decoded ABI result has incorrect size. Expected {depositRequestsBytesSize} bytes, got {offset} bytes."); } return new ExecutionRequest { RequestType = (byte)ExecutionRequestType.Deposit, - RequestData = flattenedResult.ToArray() + RequestData = flattenedResult }; } @@ -131,7 +133,7 @@ private IEnumerable ReadRequests(Block block, IWorldState stat public Hash256 CalculateRequestsHash(Block block, IWorldState state, TxReceipt[] receipts, IReleaseSpec spec, out ArrayPoolList requests) { - ArrayPoolList requestsList = new ArrayPoolList(0); + ArrayPoolList requestsList = new ArrayPoolList(receipts.Length * 2); using (SHA256 sha256 = SHA256.Create()) { using (SHA256 sha256Inner = SHA256.Create())