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

Implement/Revise EIP 6610 #3390

Merged
merged 7 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions packages/common/src/eips.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,13 @@ export const EIPs: EIPsDict = {
},
},
},
6110: {
comment: 'Supply validator deposits on chain',
url: 'https://eips.ethereum.org/EIPS/eip-6110',
status: Status.Draft,
minimumHardfork: Hardfork.Cancun,
requiredEIPs: [7685],
},
6780: {
comment: 'SELFDESTRUCT only in same transaction',
url: 'https://eips.ethereum.org/EIPS/eip-6780',
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/hardforks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ export const hardforks: HardforksDict = {
'Next feature hardfork after cancun, internally used for pectra testing/implementation (incomplete/experimental)',
url: 'https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/prague.md',
status: Status.Draft,
eips: [2537, 2935, 3074],
eips: [2537, 2935, 3074, 6110, 7002, 7685],
},
osaka: {
name: 'osaka',
Expand Down
2 changes: 1 addition & 1 deletion packages/evm/src/evm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export class EVM implements EVMInterface {
// Supported EIPs
const supportedEIPs = [
1153, 1559, 2537, 2565, 2718, 2929, 2930, 2935, 3074, 3198, 3529, 3540, 3541, 3607, 3651,
3670, 3855, 3860, 4399, 4895, 4788, 4844, 5133, 5656, 6780, 6800, 7002, 7516, 7685,
3670, 3855, 3860, 4399, 4895, 4788, 4844, 5133, 5656, 6110, 6780, 6800, 7002, 7516, 7685,
]

for (const eip of this.common.eips()) {
Expand Down
2 changes: 1 addition & 1 deletion packages/vm/src/buildBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ export class BlockBuilder {
let requests
let requestsRoot
if (this.vm.common.isActivatedEIP(7685)) {
requests = await accumulateRequests(this.vm)
requests = await accumulateRequests(this.vm, this.transactionResults)
requestsRoot = await Block.genRequestsTrieRoot(requests)
// Do other validations per request type
}
Expand Down
43 changes: 40 additions & 3 deletions packages/vm/src/runBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
bigIntToBytes,
bigIntToHex,
bytesToHex,
bytesToInt,
concatBytes,
equalsBytes,
hexToBytes,
Expand Down Expand Up @@ -196,7 +197,7 @@ export async function runBlock(this: VM, opts: RunBlockOpts): Promise<RunBlockRe
let requestsRoot
let requests: CLRequest[] | undefined
if (block.common.isActivatedEIP(7685)) {
requests = await accumulateRequests(this)
requests = await accumulateRequests(this, result.results)
requestsRoot = await Block.genRequestsTrieRoot(requests)
}

Expand Down Expand Up @@ -968,11 +969,16 @@ export class ValidatorWithdrawalRequest extends CLRequest implements CLRequestTy
* @param _vm VM instance from which to derive CL requests
* @returns an list of CL requests in ascending order by type
*/
export const accumulateRequests = async (vm: VM): Promise<CLRequest[]> => {
export const accumulateRequests = async (
vm: VM,
txResults: RunTxResult[]
): Promise<CLRequest[]> => {
const requests: CLRequest[] = []
const common = vm.common

// TODO: Add in code to accumulate deposits (EIP-6110)
if (common.isActivatedEIP(6110)) {
await accumulateDeposits(txResults, requests)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

accumulate7002 is with _ while this is not, may be we take a consistent approach

}

if (common.isActivatedEIP(7002)) {
await _accumulateEIP7002Requests(vm, requests)
Expand Down Expand Up @@ -1030,3 +1036,34 @@ const _accumulateEIP7002Requests = async (vm: VM, requests: CLRequest[]): Promis
}
}
}

export const DEPOSIT_CONTRACT_ADDRESS = '0x00000000219ab540356cBB839Cbe05303d7705Fa'
const accumulateDeposits = async (txResults: RunTxResult[], requests: CLRequest[]) => {
for (const [_, tx] of txResults.entries()) {
for (let i = 0; i < tx.receipt.logs.length; i++) {
const log = tx.receipt.logs[i]
if (bytesToHex(log[0]).toLowerCase() === DEPOSIT_CONTRACT_ADDRESS.toLowerCase()) {
const pubKeyIdx = bytesToInt(log[2].slice(0, 32))
const pubKeySize = bytesToInt(log[2].slice(pubKeyIdx, pubKeyIdx + 32))
const withcredsIdx = bytesToInt(log[2].slice(32, 64))
const withcredsSize = bytesToInt(log[2].slice(withcredsIdx, withcredsIdx + 32))
const amountIdx = bytesToInt(log[2].slice(64, 96))
const amountSize = bytesToInt(log[2].slice(amountIdx, amountIdx + 32))
const sigIdx = bytesToInt(log[2].slice(96, 128))
const sigSize = bytesToInt(log[2].slice(sigIdx, sigIdx + 32))
const indexIdx = bytesToInt(log[2].slice(128, 160))
const indexSize = bytesToInt(log[2].slice(indexIdx, indexIdx + 32))
const pubkey = bytesToHex(log[2].slice(pubKeyIdx + 32, pubKeyIdx + 32 + pubKeySize))
const withdrawalCreds = bytesToHex(
log[2].slice(withcredsIdx + 32, withcredsIdx + 32 + withcredsSize)
)
const amount = bytesToHex(log[2].slice(amountIdx + 32, amountIdx + 32 + amountSize))
const signature = bytesToHex(log[2].slice(sigIdx + 32, sigIdx + 32 + sigSize))
const index = bytesToHex(log[2].slice(indexIdx + 32, indexIdx + 32 + indexSize))
requests.push(
new CLRequest(0x0, RLP.encode([pubkey, withdrawalCreds, amount, signature, index]))
)
}
}
}
}
Loading
Loading