• Diederik Loerakker's avatar
    Bedrock: share more test utils, cleanup derive package structure, move... · 98e83d63
    Diederik Loerakker authored
    Bedrock: share more test utils, cleanup derive package structure, move payload/attributes types to eth package (#2761)
    
    * feat(bedrock): move ExecutionPayload, PayloadAttributes and other engine types from l2 to eth package
    
    * chore(bedrock): clean up derive package, move test util out or polish for public use, split payload_attributes and improve file names
    
    * chore(bedrock): move more test utils out of derive and driver packages into shared package
    
    * bedrock: fix go import newlines/order
    
    * testutils: describe TestID usage
    Co-authored-by: default avatarmergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
    98e83d63
deposit_source.go 1.19 KB
package derive

import (
	"encoding/binary"

	"github.com/ethereum/go-ethereum/common"
	"github.com/ethereum/go-ethereum/crypto"
)

type UserDepositSource struct {
	L1BlockHash common.Hash
	LogIndex    uint64
}

const (
	UserDepositSourceDomain   = 0
	L1InfoDepositSourceDomain = 1
)

func (dep *UserDepositSource) SourceHash() common.Hash {
	var input [32 * 2]byte
	copy(input[:32], dep.L1BlockHash[:])
	binary.BigEndian.PutUint64(input[32*2-8:], dep.LogIndex)
	depositIDHash := crypto.Keccak256Hash(input[:])
	var domainInput [32 * 2]byte
	binary.BigEndian.PutUint64(domainInput[32-8:32], UserDepositSourceDomain)
	copy(domainInput[32:], depositIDHash[:])
	return crypto.Keccak256Hash(domainInput[:])
}

type L1InfoDepositSource struct {
	L1BlockHash common.Hash
	SeqNumber   uint64
}

func (dep *L1InfoDepositSource) SourceHash() common.Hash {
	var input [32 * 2]byte
	copy(input[:32], dep.L1BlockHash[:])
	binary.BigEndian.PutUint64(input[32*2-8:], dep.SeqNumber)
	depositIDHash := crypto.Keccak256Hash(input[:])

	var domainInput [32 * 2]byte
	binary.BigEndian.PutUint64(domainInput[32-8:32], L1InfoDepositSourceDomain)
	copy(domainInput[32:], depositIDHash[:])
	return crypto.Keccak256Hash(domainInput[:])
}