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

l2geth: remove SignatureHashType #752

Merged
merged 5 commits into from
May 20, 2021
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
5 changes: 5 additions & 0 deletions .changeset/six-seals-eat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@eth-optimism/l2geth': patch
---

Removes the SignatureHashType from l2geth as it is deprecated and no longer required.
2 changes: 0 additions & 2 deletions integration-tests/test/queue-ingestion.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ describe('Queue Ingestion', () => {
// The `to` addresses are defined in the previous test and
// increment sequentially.
expect(tx.to).to.be.equal('0x' + `${i}`.repeat(40))
// The transaction type is EIP155
expect(tx.txType).to.be.equal('EIP155')
// The queue origin is Layer 1
expect(tx.queueOrigin).to.be.equal('l1')
// the L1TxOrigin is equal to the Layer one from
Expand Down
2 changes: 0 additions & 2 deletions integration-tests/test/rpc.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ describe('Basic RPC tests', () => {
await result.wait()

const transaction = (await provider.getTransaction(result.hash)) as any
expect(transaction.txType).to.equal('EIP155')
expect(transaction.queueOrigin).to.equal('sequencer')
expect(transaction.transactionIndex).to.be.eq(0)
expect(transaction.gasLimit).to.be.deep.eq(BigNumber.from(tx.gasLimit))
Expand All @@ -259,7 +258,6 @@ describe('Basic RPC tests', () => {
expect(block.number).to.not.equal(0)
expect(typeof block.stateRoot).to.equal('string')
expect(block.transactions.length).to.equal(1)
expect(block.transactions[0].txType).to.equal('EIP155')
expect(block.transactions[0].queueOrigin).to.equal('sequencer')
expect(block.transactions[0].l1TxOrigin).to.equal(null)
})
Expand Down
7 changes: 3 additions & 4 deletions l2geth/accounts/abi/bind/backends/simulated.go
Original file line number Diff line number Diff line change
Expand Up @@ -601,10 +601,9 @@ func (m callmsg) Gas() uint64 { return m.CallMsg.Gas }
func (m callmsg) Value() *big.Int { return m.CallMsg.Value }
func (m callmsg) Data() []byte { return m.CallMsg.Data }

func (m callmsg) L1MessageSender() *common.Address { return m.CallMsg.L1MessageSender }
func (m callmsg) L1BlockNumber() *big.Int { return m.CallMsg.L1BlockNumber }
func (m callmsg) QueueOrigin() *big.Int { return m.CallMsg.QueueOrigin }
func (m callmsg) SignatureHashType() types.SignatureHashType { return m.CallMsg.SignatureHashType }
func (m callmsg) L1MessageSender() *common.Address { return m.CallMsg.L1MessageSender }
func (m callmsg) L1BlockNumber() *big.Int { return m.CallMsg.L1BlockNumber }
func (m callmsg) QueueOrigin() *big.Int { return m.CallMsg.QueueOrigin }

// filterBackend implements filters.Backend to support filtering for logs without
// taking bloom-bits acceleration structures into account.
Expand Down
10 changes: 2 additions & 8 deletions l2geth/core/rawdb/accessors_chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ func TestBlockMetaStorage(t *testing.T) {

index1 := uint64(1)
tx1 := types.NewTransaction(1, common.HexToAddress("0x1"), big.NewInt(1), 1, big.NewInt(1), nil)
tx1Meta := types.NewTransactionMeta(nil, 0, nil, types.SighashEIP155, types.QueueOriginSequencer, &index1, nil, nil)
tx1Meta := types.NewTransactionMeta(nil, 0, nil, types.QueueOriginSequencer, &index1, nil, nil)
tx1.SetTransactionMeta(tx1Meta)

WriteTransactionMeta(db, index1, tx1.GetMeta())
Expand All @@ -442,9 +442,6 @@ func TestBlockMetaStorage(t *testing.T) {
if meta.L1BlockNumber != nil {
t.Fatalf("Could not recover L1BlockNumber")
}
if meta.SignatureHashType != types.SighashEIP155 {
t.Fatalf("Could not recover sighash type")
}
if meta.Index == nil {
t.Fatalf("Could not recover index")
}
Expand All @@ -464,7 +461,7 @@ func TestBlockMetaStorage(t *testing.T) {

index2 := uint64(2)
tx2 := types.NewTransaction(2, common.HexToAddress("0x02"), big.NewInt(2), 2, big.NewInt(2), nil)
tx2Meta := types.NewTransactionMeta(l1BlockNumber, 0, &addr, types.SighashEthSign, types.QueueOriginSequencer, nil, nil, nil)
tx2Meta := types.NewTransactionMeta(l1BlockNumber, 0, &addr, types.QueueOriginSequencer, nil, nil, nil)
tx2.SetTransactionMeta(tx2Meta)

WriteTransactionMeta(db, index2, tx2.GetMeta())
Expand All @@ -477,7 +474,4 @@ func TestBlockMetaStorage(t *testing.T) {
if meta2.L1BlockNumber.Cmp(l1BlockNumber) != 0 {
t.Fatalf("Could not recover L1BlockNumber")
}
if meta2.SignatureHashType != types.SighashEthSign {
t.Fatalf("Could not recover sighash type")
}
}
6 changes: 3 additions & 3 deletions l2geth/core/rawdb/accessors_indexes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ func TestLookupStorage(t *testing.T) {
l1BlockNumber2 := big.NewInt(2)

tx1 := types.NewTransaction(1, common.BytesToAddress([]byte{0x11}), big.NewInt(111), 1111, big.NewInt(11111), []byte{0x11, 0x11, 0x11})
tx1Meta := types.NewTransactionMeta(l1BlockNumber1, 0, &sender1, types.SighashEIP155, types.QueueOriginSequencer, nil, nil, nil)
tx1Meta := types.NewTransactionMeta(l1BlockNumber1, 0, &sender1, types.QueueOriginSequencer, nil, nil, nil)
tx1.SetTransactionMeta(tx1Meta)

tx2 := types.NewTransaction(2, common.BytesToAddress([]byte{0x22}), big.NewInt(222), 2222, big.NewInt(22222), []byte{0x22, 0x22, 0x22})
tx2Meta := types.NewTransactionMeta(l1BlockNumber2, 0, &sender2, types.SighashEIP155, types.QueueOriginSequencer, nil, nil, nil)
tx2Meta := types.NewTransactionMeta(l1BlockNumber2, 0, &sender2, types.QueueOriginSequencer, nil, nil, nil)
tx2.SetTransactionMeta(tx2Meta)

tx3 := types.NewTransaction(3, common.BytesToAddress([]byte{0x33}), big.NewInt(333), 3333, big.NewInt(33333), []byte{0x33, 0x33, 0x33})
tx3Meta := types.NewTransactionMeta(l1BlockNumber1, 0, nil, types.SighashEIP155, types.QueueOriginSequencer, nil, nil, nil)
tx3Meta := types.NewTransactionMeta(l1BlockNumber1, 0, nil, types.QueueOriginSequencer, nil, nil, nil)
tx3.SetTransactionMeta(tx3Meta)

txs := []*types.Transaction{tx1, tx2, tx3}
Expand Down
1 change: 0 additions & 1 deletion l2geth/core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ type Message interface {
L1MessageSender() *common.Address
L1BlockNumber() *big.Int
QueueOrigin() *big.Int
SignatureHashType() types.SignatureHashType
}

// IntrinsicGas computes the 'intrinsic gas' for a message with the given data.
Expand Down
1 change: 0 additions & 1 deletion l2geth/core/state_transition_ovm.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ func modMessage(
msg.L1MessageSender(),
msg.L1BlockNumber(),
queueOrigin,
msg.SignatureHashType(),
)

return outmsg, nil
Expand Down
23 changes: 8 additions & 15 deletions l2geth/core/types/gen_tx_meta_json.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 15 additions & 36 deletions l2geth/core/types/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,6 @@ var (
ErrInvalidSig = errors.New("invalid transaction v, r, s values")
)

// TODO(mark): migrate from sighash type to type
type SignatureHashType uint8

const (
SighashEIP155 SignatureHashType = 0
SighashEthSign SignatureHashType = 1
CreateEOA SignatureHashType = 2
)

type Transaction struct {
data txdata
meta TransactionMeta
Expand Down Expand Up @@ -85,7 +76,6 @@ func NewTransaction(nonce uint64, to common.Address, amount *big.Int, gasLimit u
return newTransaction(nonce, &to, amount, gasLimit, gasPrice, data)
}

// TODO: cannot deploy contracts with SighashEthSign right until SighashEIP155 is no longer hardcoded
func NewContractCreation(nonce uint64, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte) *Transaction {
return newTransaction(nonce, nil, amount, gasLimit, gasPrice, data)
}
Expand All @@ -95,7 +85,7 @@ func newTransaction(nonce uint64, to *common.Address, amount *big.Int, gasLimit
data = common.CopyBytes(data)
}

meta := NewTransactionMeta(nil, 0, nil, SighashEIP155, QueueOriginSequencer, nil, nil, nil)
meta := NewTransactionMeta(nil, 0, nil, QueueOriginSequencer, nil, nil, nil)

d := txdata{
AccountNonce: nonce,
Expand Down Expand Up @@ -230,14 +220,7 @@ func (tx *Transaction) Value() *big.Int { return new(big.Int).Set(tx.data.Amo
func (tx *Transaction) Nonce() uint64 { return tx.data.AccountNonce }
func (tx *Transaction) CheckNonce() bool { return true }

func (tx *Transaction) SetNonce(nonce uint64) { tx.data.AccountNonce = nonce }
func (tx *Transaction) SignatureHashType() SignatureHashType { return tx.meta.SignatureHashType }
func (tx *Transaction) SetSignatureHashType(sighashType SignatureHashType) {
tx.meta.SignatureHashType = sighashType
}
func (tx *Transaction) IsEthSignSighash() bool {
return tx.SignatureHashType() == SighashEthSign
}
func (tx *Transaction) SetNonce(nonce uint64) { tx.data.AccountNonce = nonce }

// To returns the recipient address of the transaction.
// It returns nil if the transaction is a contract creation.
Expand Down Expand Up @@ -317,10 +300,9 @@ func (tx *Transaction) AsMessage(s Signer) (Message, error) {
data: tx.data.Payload,
checkNonce: true,

l1MessageSender: tx.meta.L1MessageSender,
l1BlockNumber: tx.meta.L1BlockNumber,
signatureHashType: tx.meta.SignatureHashType,
queueOrigin: tx.meta.QueueOrigin,
l1MessageSender: tx.meta.L1MessageSender,
l1BlockNumber: tx.meta.L1BlockNumber,
queueOrigin: tx.meta.QueueOrigin,
}

var err error
Expand Down Expand Up @@ -533,13 +515,12 @@ type Message struct {
data []byte
checkNonce bool

l1MessageSender *common.Address
l1BlockNumber *big.Int
signatureHashType SignatureHashType
queueOrigin *big.Int
l1MessageSender *common.Address
l1BlockNumber *big.Int
queueOrigin *big.Int
}

func NewMessage(from common.Address, to *common.Address, nonce uint64, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte, checkNonce bool, l1MessageSender *common.Address, l1BlockNumber *big.Int, queueOrigin QueueOrigin, signatureHashType SignatureHashType) Message {
func NewMessage(from common.Address, to *common.Address, nonce uint64, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte, checkNonce bool, l1MessageSender *common.Address, l1BlockNumber *big.Int, queueOrigin QueueOrigin) Message {
return Message{
from: from,
to: to,
Expand All @@ -550,10 +531,9 @@ func NewMessage(from common.Address, to *common.Address, nonce uint64, amount *b
data: data,
checkNonce: checkNonce,

l1BlockNumber: l1BlockNumber,
l1MessageSender: l1MessageSender,
signatureHashType: signatureHashType,
queueOrigin: big.NewInt(int64(queueOrigin)),
l1BlockNumber: l1BlockNumber,
l1MessageSender: l1MessageSender,
queueOrigin: big.NewInt(int64(queueOrigin)),
}
}

Expand All @@ -566,7 +546,6 @@ func (m Message) Nonce() uint64 { return m.nonce }
func (m Message) Data() []byte { return m.data }
func (m Message) CheckNonce() bool { return m.checkNonce }

func (m Message) L1MessageSender() *common.Address { return m.l1MessageSender }
func (m Message) L1BlockNumber() *big.Int { return m.l1BlockNumber }
func (m Message) SignatureHashType() SignatureHashType { return m.signatureHashType }
func (m Message) QueueOrigin() *big.Int { return m.queueOrigin }
func (m Message) L1MessageSender() *common.Address { return m.l1MessageSender }
func (m Message) L1BlockNumber() *big.Int { return m.l1BlockNumber }
func (m Message) QueueOrigin() *big.Int { return m.queueOrigin }
39 changes: 12 additions & 27 deletions l2geth/core/types/transaction_meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@ const (
//go:generate gencodec -type TransactionMeta -out gen_tx_meta_json.go

type TransactionMeta struct {
L1BlockNumber *big.Int `json:"l1BlockNumber"`
L1Timestamp uint64 `json:"l1Timestamp"`
L1MessageSender *common.Address `json:"l1MessageSender" gencodec:"required"`
SignatureHashType SignatureHashType `json:"signatureHashType" gencodec:"required"`
QueueOrigin *big.Int `json:"queueOrigin" gencodec:"required"`
L1BlockNumber *big.Int `json:"l1BlockNumber"`
L1Timestamp uint64 `json:"l1Timestamp"`
L1MessageSender *common.Address `json:"l1MessageSender" gencodec:"required"`
QueueOrigin *big.Int `json:"queueOrigin" gencodec:"required"`
// The canonical transaction chain index
Index *uint64 `json:"index" gencodec:"required"`
// The queue index, nil for queue origin sequencer transactions
Expand All @@ -36,22 +35,20 @@ type TransactionMeta struct {
}

// NewTransactionMeta creates a TransactionMeta
func NewTransactionMeta(l1BlockNumber *big.Int, l1timestamp uint64, l1MessageSender *common.Address, sighashType SignatureHashType, queueOrigin QueueOrigin, index *uint64, queueIndex *uint64, rawTransaction []byte) *TransactionMeta {
func NewTransactionMeta(l1BlockNumber *big.Int, l1timestamp uint64, l1MessageSender *common.Address, queueOrigin QueueOrigin, index *uint64, queueIndex *uint64, rawTransaction []byte) *TransactionMeta {
return &TransactionMeta{
L1BlockNumber: l1BlockNumber,
L1Timestamp: l1timestamp,
L1MessageSender: l1MessageSender,
SignatureHashType: sighashType,
QueueOrigin: big.NewInt(int64(queueOrigin)),
Index: index,
QueueIndex: queueIndex,
RawTransaction: rawTransaction,
L1BlockNumber: l1BlockNumber,
L1Timestamp: l1timestamp,
L1MessageSender: l1MessageSender,
QueueOrigin: big.NewInt(int64(queueOrigin)),
Index: index,
QueueIndex: queueIndex,
RawTransaction: rawTransaction,
}
}

// TxMetaDecode deserializes bytes as a TransactionMeta struct.
// The schema is:
// varbytes(SignatureHashType) ||
// varbytes(L1BlockNumber) ||
// varbytes(L1MessageSender) ||
// varbytes(QueueOrigin) ||
Expand All @@ -61,14 +58,6 @@ func TxMetaDecode(input []byte) (*TransactionMeta, error) {
meta := TransactionMeta{}
b := bytes.NewReader(input)

sb, err := common.ReadVarBytes(b, 0, 1024, "SignatureHashType")
if err != nil {
return nil, err
}
var sighashType SignatureHashType
binary.Read(bytes.NewReader(sb), binary.LittleEndian, &sighashType)
meta.SignatureHashType = sighashType

lb, err := common.ReadVarBytes(b, 0, 1024, "l1BlockNumber")
if err != nil {
return nil, err
Expand Down Expand Up @@ -138,10 +127,6 @@ func TxMetaDecode(input []byte) (*TransactionMeta, error) {
func TxMetaEncode(meta *TransactionMeta) []byte {
b := new(bytes.Buffer)

s := new(bytes.Buffer)
binary.Write(s, binary.LittleEndian, &meta.SignatureHashType)
common.WriteVarBytes(b, 0, s.Bytes())

L1BlockNumber := meta.L1BlockNumber
if L1BlockNumber == nil {
common.WriteVarBytes(b, 0, getNullValue())
Expand Down
Loading