Skip to content

Commit

Permalink
Sepolia: Fix for deposit contract log decoding (#8383)
Browse files Browse the repository at this point in the history
* Sepolia: Fix for deposit contract log decoding

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* add tests

Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>

---------

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>
Co-authored-by: Daniel Lehrner <daniel.lehrner@consensys.net>
  • Loading branch information
fab-10 and daniellehrner committed Mar 5, 2025
1 parent a7877be commit 18bdca1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import org.hyperledger.besu.ethereum.core.Request;
import org.hyperledger.besu.ethereum.core.TransactionReceipt;
import org.hyperledger.besu.ethereum.core.encoding.DepositLogDecoder;
import org.hyperledger.besu.evm.log.Log;
import org.hyperledger.besu.evm.log.LogTopic;

import java.util.List;
import java.util.Optional;
Expand All @@ -27,6 +29,10 @@
import org.apache.tuweni.bytes.Bytes;

public class DepositRequestProcessor implements RequestProcessor {
private static final LogTopic DEPOSIT_EVENT_TOPIC =
LogTopic.wrap(
Bytes.fromHexString(
"0x649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c5"));

private final Optional<Address> depositContractAddress;

Expand All @@ -49,8 +55,14 @@ Optional<Bytes> getDepositRequestData(final List<TransactionReceipt> transaction
address ->
transactionReceipts.stream()
.flatMap(receipt -> receipt.getLogsList().stream())
.filter(log -> address.equals(log.getLogger()))
.filter(log -> isDepositEvent(address, log))
.map(DepositLogDecoder::decodeFromLog)
.reduce(Bytes::concatenate));
}

private boolean isDepositEvent(final Address depositContractAddress, final Log log) {
return depositContractAddress.equals(log.getLogger())
&& !log.getTopics().isEmpty()
&& log.getTopics().getFirst().equals(DEPOSIT_EVENT_TOPIC);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,25 @@ void shouldDecodeDepositFromLog() {

assertThat(requestData).isEqualTo(expectedDepositRequestData);
}

@Test
void shouldDecodeSepoliaDepositFromLog() {
final Address logger = Address.fromHexString("0x00000000219ab540356cbb839cbe05303d7705fa");
final List<LogTopic> topics =
List.of(
LogTopic.fromHexString(
"0x649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c5"));
final Bytes data =
Bytes.fromHexString(
"0x00000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000180000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000800000c3d5d53aa01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000");

final Log log = new Log(logger, data, topics);
final Bytes requestData = DepositLogDecoder.decodeFromLog(log);

final Bytes expectedDepositRequestData =
Bytes.fromHexString(
"0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000c3d5d53aa010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000030000000000000000");

assertThat(requestData).isEqualTo(expectedDepositRequestData);
}
}

0 comments on commit 18bdca1

Please sign in to comment.