Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EIP-6110: Add deposit validation and apis #5295

Merged
merged 47 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
dcd958b
Initial commit
ensi321 Apr 3, 2023
ee3e2ae
Spotless Apply
ensi321 Apr 3, 2023
e62b6f5
Update test
ensi321 Apr 3, 2023
d25ad53
Added rpc tests. Update block creator rule for deposits
ensi321 Apr 3, 2023
ca121d3
Update test
ensi321 Apr 3, 2023
faf5a83
Update test
ensi321 Apr 4, 2023
53b2ac3
Spotless Apply
ensi321 Apr 4, 2023
941f602
Get deposit validator by block header
ensi321 Apr 4, 2023
0c26667
Fix up unit tests
ensi321 Apr 4, 2023
c15fa47
Recover deleted files
ensi321 Apr 5, 2023
2c80293
Fix test
ensi321 Apr 5, 2023
bb805c1
Rename according to feedback
ensi321 Apr 11, 2023
e6adf32
Introduce depositContractAddress to genesis file
ensi321 Apr 11, 2023
da4e180
Merge remote-tracking branch 'remote/main' into eip-6110
ensi321 Apr 11, 2023
d3d18a8
Update test to accommodate changes
ensi321 Apr 11, 2023
162f60c
Fix test
ensi321 Apr 11, 2023
6d567cc
Address comments
ensi321 Apr 30, 2023
1dbad08
Address pr comments
ensi321 May 2, 2023
00a9edd
Merge remote-tracking branch 'remote/main' into eip-6110
ensi321 May 2, 2023
695e6a0
Updated DepositsValidatorProvider
ensi321 May 2, 2023
fd8739b
Spotless Apply
ensi321 May 2, 2023
0bf4be1
Extract correct logs from receipts
ensi321 May 2, 2023
7f55dd9
Merge branch 'main' into eip-6110
ensi321 May 3, 2023
17d264b
Add changelog
ensi321 May 3, 2023
f79d203
Address PR comments
ensi321 May 8, 2023
807940f
Address PR comments
ensi321 May 8, 2023
d5ec15f
Address PR comments
ensi321 May 8, 2023
d712c0d
Merge branch 'main' into eip-6110
ensi321 May 8, 2023
f962e62
Spotless Apply
ensi321 May 8, 2023
1caf791
Detail log on failing deposit validation
ensi321 May 10, 2023
c3cbf98
Pass depositContractAddress to block creator and coordinator
ensi321 May 11, 2023
dd44ed4
Merge remote-tracking branch 'remote/main' into eip-6110
ensi321 May 12, 2023
201c44e
Update javadoc
ensi321 May 14, 2023
52e422b
Address comments
ensi321 May 16, 2023
713cc5d
Address comments
ensi321 May 16, 2023
eced987
Fix spotless
siladu May 26, 2023
74cda7f
Merge branch 'main' into eip-6110
siladu May 26, 2023
a9f80de
Merge remote-tracking branch 'remote/main' into eip-6110
ensi321 Jun 4, 2023
0b849ca
Merge branch 'hyperledger:main' into eip-6110
ensi321 Jun 11, 2023
e4efdff
Fix acceptance tests
ensi321 Jun 13, 2023
c99fe13
Merge branch 'main' into eip-6110
ensi321 Jun 13, 2023
fa69181
Fix unit tests by setting genesis file in the setup code
siladu Jun 16, 2023
346415c
Merge remote-tracking branch 'upstream/main' into eip-6110
siladu Jun 16, 2023
2380e32
Fix mock in another test, unintended consequence of last commit
siladu Jun 16, 2023
8804b98
Add units for AbstractBlockCreator
siladu Jun 16, 2023
b790ff1
Inline variables and tidy up
siladu Jun 16, 2023
8b270bb
Merge branch 'main' into eip-6110
siladu Jun 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"berlinBlock":0,
"londonBlock":0,
"shanghaiTime":10,
"experimentaleipstime":20,
ensi321 marked this conversation as resolved.
Show resolved Hide resolved
"clique": {
"period": 5,
"epoch": 30000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"amount": "0x2"
}
],
"deposits": null,
ensi321 marked this conversation as resolved.
Show resolved Hide resolved
"blockNumber": "0x2",
"blockHash": "0x5dec96e86ccd61362959cc73a0992b033fcde6f01d7467393363538c74c5260d",
"receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"request": {
"jsonrpc": "2.0",
"method": "engine_forkchoiceUpdatedV2",
ensi321 marked this conversation as resolved.
Show resolved Hide resolved
"params": [
{
"headBlockHash": "0x5dec96e86ccd61362959cc73a0992b033fcde6f01d7467393363538c74c5260d",
"safeBlockHash": "0x5dec96e86ccd61362959cc73a0992b033fcde6f01d7467393363538c74c5260d",
"finalizedBlockHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
},
{
"timestamp": "0x20",
"prevRandao": "0x0000000000000000000000000000000000000000000000000000000000000000",
"suggestedFeeRecipient": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"withdrawals": [
{
"index": "0x0",
"validatorIndex": "0x0",
"address": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"amount": "0x1"
},
{
"index": "0x1",
"validatorIndex": "0x0",
"address": "0xfe3b557e8fb62b89f4916b721be55ceb828dbd73",
"amount": "0x2"
}
]
}
],
"id": 67
},
"response": {
"jsonrpc": "2.0",
"id": 67,
"result": {
"payloadStatus": {
"status": "VALID",
"latestValidHash": "0x5dec96e86ccd61362959cc73a0992b033fcde6f01d7467393363538c74c5260d",
"validationError": null
},
"payloadId": "0x0065bd48ff13b2e0"
}
},
"statusCode" : 200
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"request": {
"jsonrpc": "2.0",
"method": "engine_getPayloadV2",
"params": [
"0x0065bd48ff13b2e0"
],
"id": 67
},
"response": {
"jsonrpc": "2.0",
"id": 67,
"result": {
"executionPayload": {
"parentHash": "0x5dec96e86ccd61362959cc73a0992b033fcde6f01d7467393363538c74c5260d",
"feeRecipient": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"stateRoot": "0x0212f870b77bf90e46d6d7f3cab2d0b7b8c8599d452736d572048789fffda8de",
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"prevRandao": "0x0000000000000000000000000000000000000000000000000000000000000000",
"gasLimit": "0x1c9c380",
"gasUsed": "0x0",
"timestamp": "0x20",
"extraData": "0x",
"baseFeePerGas": "0x7",
"transactions": [],
"withdrawals": [
{
"index": "0x0",
"validatorIndex": "0x0",
"address": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"amount": "0x1"
},
{
"index": "0x1",
"validatorIndex": "0x0",
"address": "0xfe3b557e8fb62b89f4916b721be55ceb828dbd73",
"amount": "0x2"
}
],
"deposits" : [],
"blockNumber": "0x3",
"blockHash": "0x299b9dbc0670aa8b029ea11195e1d365308c456e120e62c5dc39507944be394b",
"receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"
},
"blockValue": "0x0"
}
},
"statusCode": 200
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"request": {
"jsonrpc": "2.0",
"method": "engine_newPayloadV2",
"params": [
{
"parentHash": "0x5dec96e86ccd61362959cc73a0992b033fcde6f01d7467393363538c74c5260d",
"feeRecipient": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"stateRoot": "0x1a10dba514dc4faff7ec13edd9b5ef653c1cd14eb26608bfc2b37717730a55a4",
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"prevRandao": "0x0000000000000000000000000000000000000000000000000000000000000000",
"gasLimit": "0x1c9c380",
"gasUsed": "0x0",
"timestamp": "0x20",
"extraData": "0x",
"baseFeePerGas": "0x7",
"transactions": [],
"withdrawals": [
{
"index": "0x0",
"validatorIndex": "0x0",
"address": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"amount": "0x1"
},
{
"index": "0x1",
"validatorIndex": "0x0",
"address": "0xfe3b557e8fb62b89f4916b721be55ceb828dbd73",
"amount": "0x2"
}
],
"deposits": null,
"blockNumber": "0x3",
"blockHash": "0x1475ca311179652e44b10b7e2d7b72f3708f3201f8d729880a83f3eb397910e8",
"receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"
}
],
"id": 67
},
"response": {
"jsonrpc": "2.0",
"id": 67,
"error": {
"code": -32602,
"message": "Invalid params"
}
},
"statusCode": 200
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"request": {
"jsonrpc": "2.0",
"method": "engine_newPayloadV2",
"params": [
{
"parentHash": "0x5dec96e86ccd61362959cc73a0992b033fcde6f01d7467393363538c74c5260d",
"feeRecipient": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"stateRoot": "0x0212f870b77bf90e46d6d7f3cab2d0b7b8c8599d452736d572048789fffda8de",
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"prevRandao": "0x0000000000000000000000000000000000000000000000000000000000000000",
"gasLimit": "0x1c9c380",
"gasUsed": "0x0",
"timestamp": "0x20",
"extraData": "0x",
"baseFeePerGas": "0x7",
"transactions": [],
"withdrawals": [
{
"index": "0x0",
"validatorIndex": "0x0",
"address": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"amount": "0x1"
},
{
"index": "0x1",
"validatorIndex": "0x0",
"address": "0xfe3b557e8fb62b89f4916b721be55ceb828dbd73",
"amount": "0x2"
}
],
"deposits": [],
"blockNumber": "0x3",
"blockHash": "0x8e1cd0eb8e0df1c3713dfee3c7594d2bd85db4421d40fd89c34375091cb66d5a",
"receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"
}
],
"id": 67
},
"response": {
"jsonrpc": "2.0",
"id": 67,
"result": {
"status": "VALID",
"latestValidHash": "0x8e1cd0eb8e0df1c3713dfee3c7594d2bd85db4421d40fd89c34375091cb66d5a",
"validationError": null
}
},
"statusCode": 200
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ public class Address extends DelegatingBytes {
public static final Address KZG_POINT_EVAL = Address.precompiled(0x14);
/** The constant ZERO. */
public static final Address ZERO = Address.fromHexString("0x0");
/** The deposit address. */
public static final Address DEPOSIT_ADDRESS =
ensi321 marked this conversation as resolved.
Show resolved Hide resolved
Address.fromHexString("0x00000000219ab540356cbb839cbe05303d7705fa");
siladu marked this conversation as resolved.
Show resolved Hide resolved

/**
* Instantiates a new Address.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.ExecutionEngineJsonRpcMethod.EngineStatus.INVALID_BLOCK_HASH;
import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.ExecutionEngineJsonRpcMethod.EngineStatus.SYNCING;
import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.ExecutionEngineJsonRpcMethod.EngineStatus.VALID;
import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine.DepositsValidatorProvider.getDepositsValidator;
import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine.WithdrawalsValidatorProvider.getWithdrawalsValidator;
import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError.INVALID_PARAMS;

Expand All @@ -30,6 +31,7 @@
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.ExecutionEngineJsonRpcMethod;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.DepositParameter;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.EnginePayloadParameter;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.WithdrawalParameter;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError;
Expand All @@ -41,6 +43,7 @@
import org.hyperledger.besu.ethereum.core.BlockBody;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.BlockHeaderFunctions;
import org.hyperledger.besu.ethereum.core.Deposit;
import org.hyperledger.besu.ethereum.core.Difficulty;
import org.hyperledger.besu.ethereum.core.Transaction;
import org.hyperledger.besu.ethereum.core.Withdrawal;
Expand Down Expand Up @@ -111,6 +114,15 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext)
return new JsonRpcErrorResponse(reqId, INVALID_PARAMS);
}

final Optional<List<Deposit>> maybeDeposits =
Optional.ofNullable(blockParam.getDeposits())
.map(ds -> ds.stream().map(DepositParameter::toDeposit).collect(toList()));
if (!getDepositsValidator(
timestampSchedule, blockParam.getTimestamp(), blockParam.getBlockNumber())
.validateDepositParameters(maybeDeposits)) {
return new JsonRpcErrorResponse(reqId, INVALID_PARAMS);
}

if (mergeContext.get().isSyncing()) {
LOG.debug("We are syncing");
return respondWith(reqId, blockParam, null, SYNCING);
Expand Down Expand Up @@ -161,7 +173,7 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext)
0,
maybeWithdrawals.map(BodyValidation::withdrawalsRoot).orElse(null),
null,
null,
maybeDeposits.map(BodyValidation::depositsRoot).orElse(null),
headerFunctions);

// ensure the block hash matches the blockParam hash
Expand Down Expand Up @@ -205,8 +217,7 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext)
final var block =
new Block(
newBlockHeader,
new BlockBody(
transactions, Collections.emptyList(), maybeWithdrawals, Optional.empty()));
new BlockBody(transactions, Collections.emptyList(), maybeWithdrawals, maybeDeposits));

if (maybeParentHeader.isEmpty()) {
LOG.atDebug()
Expand Down Expand Up @@ -340,6 +351,10 @@ private void logImportedBlockInfo(final Block block, final double timeInS) {
message.append(" / %d ws");
messageArgs.add(block.getBody().getWithdrawals().get().size());
}
if (block.getBody().getDeposits().isPresent()) {
message.append(" / %d ds");
messageArgs.add(block.getBody().getDeposits().get().size());
}
message.append(" / base fee %s / %,d (%01.1f%%) gas / (%s) in %01.3fs. Peers: %d");
messageArgs.addAll(
List.of(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright Hyperledger Besu Contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/

package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine;

import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.BlockHeaderBuilder;
import org.hyperledger.besu.ethereum.mainnet.DepositsValidator;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec;
import org.hyperledger.besu.ethereum.mainnet.TimestampSchedule;

import java.util.Optional;

public class DepositsValidatorProvider {
static DepositsValidator getDepositsValidator(
final TimestampSchedule timestampSchedule,
ensi321 marked this conversation as resolved.
Show resolved Hide resolved
final long blockTimestamp,
final long blockNumber) {

final BlockHeader blockHeader =
BlockHeaderBuilder.createDefault()
.timestamp(blockTimestamp)
.number(blockNumber)
.buildBlockHeader();
return Optional.ofNullable(timestampSchedule.getByBlockHeader(blockHeader))
.map(ProtocolSpec::getDepositsValidator)
.orElseGet(DepositsValidator.ProhibitedDeposits::new);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class EnginePayloadParameter {
private final LogsBloomFilter logsBloom;
private final List<String> transactions;
private final List<WithdrawalParameter> withdrawals;
private final List<DepositParameter> deposits;

@JsonCreator
public EnginePayloadParameter(
Expand All @@ -64,7 +65,8 @@ public EnginePayloadParameter(
@JsonProperty("logsBloom") final LogsBloomFilter logsBloom,
@JsonProperty("prevRandao") final String prevRandao,
@JsonProperty("transactions") final List<String> transactions,
@JsonProperty("withdrawals") final List<WithdrawalParameter> withdrawals) {
@JsonProperty("withdrawals") final List<WithdrawalParameter> withdrawals,
@JsonProperty("deposits") final List<DepositParameter> deposits) {
ensi321 marked this conversation as resolved.
Show resolved Hide resolved
this.blockHash = blockHash;
this.parentHash = parentHash;
this.feeRecipient = feeRecipient;
Expand All @@ -80,6 +82,7 @@ public EnginePayloadParameter(
this.prevRandao = Bytes32.fromHexString(prevRandao);
this.transactions = transactions;
this.withdrawals = withdrawals;
this.deposits = deposits;
}

public Hash getBlockHash() {
Expand Down Expand Up @@ -141,4 +144,8 @@ public List<String> getTransactions() {
public List<WithdrawalParameter> getWithdrawals() {
return withdrawals;
}

public List<DepositParameter> getDeposits() {
return deposits;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public EngineGetPayloadResultV2 payloadTransactionCompleteV2(
blockWithReceipts.getHeader(),
txs,
blockWithReceipts.getBlock().getBody().getWithdrawals(),
blockWithReceipts.getBlock().getBody().getDeposits(),
Quantity.create(blockValue));
}

Expand Down
Loading