From 0eaf3674f3bb1a7de244d23e5fa2956138b6fac5 Mon Sep 17 00:00:00 2001 From: gop Date: Wed, 21 Feb 2024 17:10:02 -0600 Subject: [PATCH] Made the TX signing hash and Tx Hash a proto buf encoded hash --- core/types/proto_block.pb.go | 155 ++++++++++++++---------------- core/types/proto_block.proto | 61 ++++++------ core/types/transaction.go | 67 ++++++++++++- core/types/transaction_signing.go | 62 +++--------- internal/quaiapi/api.go | 6 +- 5 files changed, 183 insertions(+), 168 deletions(-) diff --git a/core/types/proto_block.pb.go b/core/types/proto_block.pb.go index c19ea58317..af84dd3d7e 100644 --- a/core/types/proto_block.pb.go +++ b/core/types/proto_block.pb.go @@ -364,27 +364,26 @@ type ProtoTransaction struct { To []byte `protobuf:"bytes,2,opt,name=to,proto3,oneof" json:"to,omitempty"` Nonce *uint64 `protobuf:"varint,3,opt,name=nonce,proto3,oneof" json:"nonce,omitempty"` Value []byte `protobuf:"bytes,4,opt,name=value,proto3,oneof" json:"value,omitempty"` - GasPrice []byte `protobuf:"bytes,5,opt,name=gas_price,json=gasPrice,proto3,oneof" json:"gas_price,omitempty"` - Gas *uint64 `protobuf:"varint,6,opt,name=gas,proto3,oneof" json:"gas,omitempty"` - Data []byte `protobuf:"bytes,7,opt,name=data,proto3,oneof" json:"data,omitempty"` - ChainId []byte `protobuf:"bytes,8,opt,name=chain_id,json=chainId,proto3,oneof" json:"chain_id,omitempty"` - GasFeeCap []byte `protobuf:"bytes,9,opt,name=gas_fee_cap,json=gasFeeCap,proto3,oneof" json:"gas_fee_cap,omitempty"` - GasTipCap []byte `protobuf:"bytes,10,opt,name=gas_tip_cap,json=gasTipCap,proto3,oneof" json:"gas_tip_cap,omitempty"` - AccessList *ProtoAccessList `protobuf:"bytes,11,opt,name=access_list,json=accessList,proto3,oneof" json:"access_list,omitempty"` - EtxGasLimit *uint64 `protobuf:"varint,12,opt,name=etx_gas_limit,json=etxGasLimit,proto3,oneof" json:"etx_gas_limit,omitempty"` - EtxGasPrice []byte `protobuf:"bytes,13,opt,name=etx_gas_price,json=etxGasPrice,proto3,oneof" json:"etx_gas_price,omitempty"` - EtxGasTip []byte `protobuf:"bytes,14,opt,name=etx_gas_tip,json=etxGasTip,proto3,oneof" json:"etx_gas_tip,omitempty"` - EtxData []byte `protobuf:"bytes,15,opt,name=etx_data,json=etxData,proto3,oneof" json:"etx_data,omitempty"` - EtxAccessList *ProtoAccessList `protobuf:"bytes,16,opt,name=etx_access_list,json=etxAccessList,proto3,oneof" json:"etx_access_list,omitempty"` - V []byte `protobuf:"bytes,17,opt,name=v,proto3,oneof" json:"v,omitempty"` - R []byte `protobuf:"bytes,18,opt,name=r,proto3,oneof" json:"r,omitempty"` - S []byte `protobuf:"bytes,19,opt,name=s,proto3,oneof" json:"s,omitempty"` - OriginatingTxHash *common.ProtoHash `protobuf:"bytes,20,opt,name=originating_tx_hash,json=originatingTxHash,proto3,oneof" json:"originating_tx_hash,omitempty"` - EtxIndex *uint32 `protobuf:"varint,21,opt,name=etx_index,json=etxIndex,proto3,oneof" json:"etx_index,omitempty"` - EtxSender []byte `protobuf:"bytes,22,opt,name=etx_sender,json=etxSender,proto3,oneof" json:"etx_sender,omitempty"` - TxIns *ProtoTxIns `protobuf:"bytes,23,opt,name=tx_ins,json=txIns,proto3,oneof" json:"tx_ins,omitempty"` - TxOuts *ProtoTxOuts `protobuf:"bytes,24,opt,name=tx_outs,json=txOuts,proto3,oneof" json:"tx_outs,omitempty"` - Signature []byte `protobuf:"bytes,25,opt,name=signature,proto3,oneof" json:"signature,omitempty"` + Gas *uint64 `protobuf:"varint,5,opt,name=gas,proto3,oneof" json:"gas,omitempty"` + Data []byte `protobuf:"bytes,6,opt,name=data,proto3,oneof" json:"data,omitempty"` + ChainId []byte `protobuf:"bytes,7,opt,name=chain_id,json=chainId,proto3,oneof" json:"chain_id,omitempty"` + GasFeeCap []byte `protobuf:"bytes,8,opt,name=gas_fee_cap,json=gasFeeCap,proto3,oneof" json:"gas_fee_cap,omitempty"` + GasTipCap []byte `protobuf:"bytes,9,opt,name=gas_tip_cap,json=gasTipCap,proto3,oneof" json:"gas_tip_cap,omitempty"` + AccessList *ProtoAccessList `protobuf:"bytes,10,opt,name=access_list,json=accessList,proto3,oneof" json:"access_list,omitempty"` + EtxGasLimit *uint64 `protobuf:"varint,11,opt,name=etx_gas_limit,json=etxGasLimit,proto3,oneof" json:"etx_gas_limit,omitempty"` + EtxGasPrice []byte `protobuf:"bytes,12,opt,name=etx_gas_price,json=etxGasPrice,proto3,oneof" json:"etx_gas_price,omitempty"` + EtxGasTip []byte `protobuf:"bytes,13,opt,name=etx_gas_tip,json=etxGasTip,proto3,oneof" json:"etx_gas_tip,omitempty"` + EtxData []byte `protobuf:"bytes,14,opt,name=etx_data,json=etxData,proto3,oneof" json:"etx_data,omitempty"` + EtxAccessList *ProtoAccessList `protobuf:"bytes,15,opt,name=etx_access_list,json=etxAccessList,proto3,oneof" json:"etx_access_list,omitempty"` + V []byte `protobuf:"bytes,16,opt,name=v,proto3,oneof" json:"v,omitempty"` + R []byte `protobuf:"bytes,17,opt,name=r,proto3,oneof" json:"r,omitempty"` + S []byte `protobuf:"bytes,18,opt,name=s,proto3,oneof" json:"s,omitempty"` + OriginatingTxHash *common.ProtoHash `protobuf:"bytes,19,opt,name=originating_tx_hash,json=originatingTxHash,proto3,oneof" json:"originating_tx_hash,omitempty"` + EtxIndex *uint32 `protobuf:"varint,20,opt,name=etx_index,json=etxIndex,proto3,oneof" json:"etx_index,omitempty"` + EtxSender []byte `protobuf:"bytes,21,opt,name=etx_sender,json=etxSender,proto3,oneof" json:"etx_sender,omitempty"` + TxIns *ProtoTxIns `protobuf:"bytes,22,opt,name=tx_ins,json=txIns,proto3,oneof" json:"tx_ins,omitempty"` + TxOuts *ProtoTxOuts `protobuf:"bytes,23,opt,name=tx_outs,json=txOuts,proto3,oneof" json:"tx_outs,omitempty"` + Signature []byte `protobuf:"bytes,24,opt,name=signature,proto3,oneof" json:"signature,omitempty"` } func (x *ProtoTransaction) Reset() { @@ -447,13 +446,6 @@ func (x *ProtoTransaction) GetValue() []byte { return nil } -func (x *ProtoTransaction) GetGasPrice() []byte { - if x != nil { - return x.GasPrice - } - return nil -} - func (x *ProtoTransaction) GetGas() uint64 { if x != nil && x.Gas != nil { return *x.Gas @@ -1778,7 +1770,7 @@ var file_core_types_proto_block_proto_rawDesc = []byte{ 0x65, 0x42, 0x0b, 0x0a, 0x09, 0x5f, 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x42, 0x07, 0x0a, 0x05, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x42, 0x08, 0x0a, 0x06, 0x5f, 0x65, 0x78, 0x74, 0x72, 0x61, 0x42, 0x0b, 0x0a, 0x09, 0x5f, 0x6d, 0x69, 0x78, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x42, 0x08, - 0x0a, 0x06, 0x5f, 0x6e, 0x6f, 0x6e, 0x63, 0x65, 0x22, 0xd8, 0x09, 0x0a, 0x10, 0x50, 0x72, 0x6f, + 0x0a, 0x06, 0x5f, 0x6e, 0x6f, 0x6e, 0x63, 0x65, 0x22, 0xa8, 0x09, 0x0a, 0x10, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x17, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x48, 0x00, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x88, 0x01, 0x01, 0x12, 0x13, 0x0a, 0x02, 0x74, 0x6f, 0x18, 0x02, 0x20, 0x01, @@ -1786,60 +1778,57 @@ var file_core_types_proto_block_proto_rawDesc = []byte{ 0x6f, 0x6e, 0x63, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x04, 0x48, 0x02, 0x52, 0x05, 0x6e, 0x6f, 0x6e, 0x63, 0x65, 0x88, 0x01, 0x01, 0x12, 0x19, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x48, 0x03, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x88, 0x01, - 0x01, 0x12, 0x20, 0x0a, 0x09, 0x67, 0x61, 0x73, 0x5f, 0x70, 0x72, 0x69, 0x63, 0x65, 0x18, 0x05, - 0x20, 0x01, 0x28, 0x0c, 0x48, 0x04, 0x52, 0x08, 0x67, 0x61, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, - 0x88, 0x01, 0x01, 0x12, 0x15, 0x0a, 0x03, 0x67, 0x61, 0x73, 0x18, 0x06, 0x20, 0x01, 0x28, 0x04, - 0x48, 0x05, 0x52, 0x03, 0x67, 0x61, 0x73, 0x88, 0x01, 0x01, 0x12, 0x17, 0x0a, 0x04, 0x64, 0x61, - 0x74, 0x61, 0x18, 0x07, 0x20, 0x01, 0x28, 0x0c, 0x48, 0x06, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, - 0x88, 0x01, 0x01, 0x12, 0x1e, 0x0a, 0x08, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x64, 0x18, - 0x08, 0x20, 0x01, 0x28, 0x0c, 0x48, 0x07, 0x52, 0x07, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x49, 0x64, - 0x88, 0x01, 0x01, 0x12, 0x23, 0x0a, 0x0b, 0x67, 0x61, 0x73, 0x5f, 0x66, 0x65, 0x65, 0x5f, 0x63, - 0x61, 0x70, 0x18, 0x09, 0x20, 0x01, 0x28, 0x0c, 0x48, 0x08, 0x52, 0x09, 0x67, 0x61, 0x73, 0x46, - 0x65, 0x65, 0x43, 0x61, 0x70, 0x88, 0x01, 0x01, 0x12, 0x23, 0x0a, 0x0b, 0x67, 0x61, 0x73, 0x5f, - 0x74, 0x69, 0x70, 0x5f, 0x63, 0x61, 0x70, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x0c, 0x48, 0x09, 0x52, - 0x09, 0x67, 0x61, 0x73, 0x54, 0x69, 0x70, 0x43, 0x61, 0x70, 0x88, 0x01, 0x01, 0x12, 0x3c, 0x0a, - 0x0b, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x5f, 0x6c, 0x69, 0x73, 0x74, 0x18, 0x0b, 0x20, 0x01, - 0x28, 0x0b, 0x32, 0x16, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x50, 0x72, 0x6f, 0x74, 0x6f, - 0x41, 0x63, 0x63, 0x65, 0x73, 0x73, 0x4c, 0x69, 0x73, 0x74, 0x48, 0x0a, 0x52, 0x0a, 0x61, 0x63, - 0x63, 0x65, 0x73, 0x73, 0x4c, 0x69, 0x73, 0x74, 0x88, 0x01, 0x01, 0x12, 0x27, 0x0a, 0x0d, 0x65, - 0x74, 0x78, 0x5f, 0x67, 0x61, 0x73, 0x5f, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x18, 0x0c, 0x20, 0x01, - 0x28, 0x04, 0x48, 0x0b, 0x52, 0x0b, 0x65, 0x74, 0x78, 0x47, 0x61, 0x73, 0x4c, 0x69, 0x6d, 0x69, - 0x74, 0x88, 0x01, 0x01, 0x12, 0x27, 0x0a, 0x0d, 0x65, 0x74, 0x78, 0x5f, 0x67, 0x61, 0x73, 0x5f, - 0x70, 0x72, 0x69, 0x63, 0x65, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x0c, 0x48, 0x0c, 0x52, 0x0b, 0x65, - 0x74, 0x78, 0x47, 0x61, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x88, 0x01, 0x01, 0x12, 0x23, 0x0a, - 0x0b, 0x65, 0x74, 0x78, 0x5f, 0x67, 0x61, 0x73, 0x5f, 0x74, 0x69, 0x70, 0x18, 0x0e, 0x20, 0x01, - 0x28, 0x0c, 0x48, 0x0d, 0x52, 0x09, 0x65, 0x74, 0x78, 0x47, 0x61, 0x73, 0x54, 0x69, 0x70, 0x88, - 0x01, 0x01, 0x12, 0x1e, 0x0a, 0x08, 0x65, 0x74, 0x78, 0x5f, 0x64, 0x61, 0x74, 0x61, 0x18, 0x0f, - 0x20, 0x01, 0x28, 0x0c, 0x48, 0x0e, 0x52, 0x07, 0x65, 0x74, 0x78, 0x44, 0x61, 0x74, 0x61, 0x88, - 0x01, 0x01, 0x12, 0x43, 0x0a, 0x0f, 0x65, 0x74, 0x78, 0x5f, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, - 0x5f, 0x6c, 0x69, 0x73, 0x74, 0x18, 0x10, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x16, 0x2e, 0x62, 0x6c, - 0x6f, 0x63, 0x6b, 0x2e, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x41, 0x63, 0x63, 0x65, 0x73, 0x73, 0x4c, - 0x69, 0x73, 0x74, 0x48, 0x0f, 0x52, 0x0d, 0x65, 0x74, 0x78, 0x41, 0x63, 0x63, 0x65, 0x73, 0x73, - 0x4c, 0x69, 0x73, 0x74, 0x88, 0x01, 0x01, 0x12, 0x11, 0x0a, 0x01, 0x76, 0x18, 0x11, 0x20, 0x01, - 0x28, 0x0c, 0x48, 0x10, 0x52, 0x01, 0x76, 0x88, 0x01, 0x01, 0x12, 0x11, 0x0a, 0x01, 0x72, 0x18, - 0x12, 0x20, 0x01, 0x28, 0x0c, 0x48, 0x11, 0x52, 0x01, 0x72, 0x88, 0x01, 0x01, 0x12, 0x11, 0x0a, - 0x01, 0x73, 0x18, 0x13, 0x20, 0x01, 0x28, 0x0c, 0x48, 0x12, 0x52, 0x01, 0x73, 0x88, 0x01, 0x01, - 0x12, 0x46, 0x0a, 0x13, 0x6f, 0x72, 0x69, 0x67, 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6e, 0x67, 0x5f, - 0x74, 0x78, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x14, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, - 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x48, 0x61, 0x73, 0x68, - 0x48, 0x13, 0x52, 0x11, 0x6f, 0x72, 0x69, 0x67, 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6e, 0x67, 0x54, - 0x78, 0x48, 0x61, 0x73, 0x68, 0x88, 0x01, 0x01, 0x12, 0x20, 0x0a, 0x09, 0x65, 0x74, 0x78, 0x5f, - 0x69, 0x6e, 0x64, 0x65, 0x78, 0x18, 0x15, 0x20, 0x01, 0x28, 0x0d, 0x48, 0x14, 0x52, 0x08, 0x65, - 0x74, 0x78, 0x49, 0x6e, 0x64, 0x65, 0x78, 0x88, 0x01, 0x01, 0x12, 0x22, 0x0a, 0x0a, 0x65, 0x74, - 0x78, 0x5f, 0x73, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x18, 0x16, 0x20, 0x01, 0x28, 0x0c, 0x48, 0x15, - 0x52, 0x09, 0x65, 0x74, 0x78, 0x53, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x88, 0x01, 0x01, 0x12, 0x2d, - 0x0a, 0x06, 0x74, 0x78, 0x5f, 0x69, 0x6e, 0x73, 0x18, 0x17, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, - 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x54, 0x78, 0x49, 0x6e, - 0x73, 0x48, 0x16, 0x52, 0x05, 0x74, 0x78, 0x49, 0x6e, 0x73, 0x88, 0x01, 0x01, 0x12, 0x30, 0x0a, - 0x07, 0x74, 0x78, 0x5f, 0x6f, 0x75, 0x74, 0x73, 0x18, 0x18, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, - 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x54, 0x78, 0x4f, 0x75, - 0x74, 0x73, 0x48, 0x17, 0x52, 0x06, 0x74, 0x78, 0x4f, 0x75, 0x74, 0x73, 0x88, 0x01, 0x01, 0x12, - 0x21, 0x0a, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x18, 0x19, 0x20, 0x01, - 0x28, 0x0c, 0x48, 0x18, 0x52, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x88, - 0x01, 0x01, 0x42, 0x07, 0x0a, 0x05, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x42, 0x05, 0x0a, 0x03, 0x5f, - 0x74, 0x6f, 0x42, 0x08, 0x0a, 0x06, 0x5f, 0x6e, 0x6f, 0x6e, 0x63, 0x65, 0x42, 0x08, 0x0a, 0x06, - 0x5f, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x42, 0x0c, 0x0a, 0x0a, 0x5f, 0x67, 0x61, 0x73, 0x5f, 0x70, - 0x72, 0x69, 0x63, 0x65, 0x42, 0x06, 0x0a, 0x04, 0x5f, 0x67, 0x61, 0x73, 0x42, 0x07, 0x0a, 0x05, + 0x01, 0x12, 0x15, 0x0a, 0x03, 0x67, 0x61, 0x73, 0x18, 0x05, 0x20, 0x01, 0x28, 0x04, 0x48, 0x04, + 0x52, 0x03, 0x67, 0x61, 0x73, 0x88, 0x01, 0x01, 0x12, 0x17, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, + 0x18, 0x06, 0x20, 0x01, 0x28, 0x0c, 0x48, 0x05, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x88, 0x01, + 0x01, 0x12, 0x1e, 0x0a, 0x08, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x07, 0x20, + 0x01, 0x28, 0x0c, 0x48, 0x06, 0x52, 0x07, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x49, 0x64, 0x88, 0x01, + 0x01, 0x12, 0x23, 0x0a, 0x0b, 0x67, 0x61, 0x73, 0x5f, 0x66, 0x65, 0x65, 0x5f, 0x63, 0x61, 0x70, + 0x18, 0x08, 0x20, 0x01, 0x28, 0x0c, 0x48, 0x07, 0x52, 0x09, 0x67, 0x61, 0x73, 0x46, 0x65, 0x65, + 0x43, 0x61, 0x70, 0x88, 0x01, 0x01, 0x12, 0x23, 0x0a, 0x0b, 0x67, 0x61, 0x73, 0x5f, 0x74, 0x69, + 0x70, 0x5f, 0x63, 0x61, 0x70, 0x18, 0x09, 0x20, 0x01, 0x28, 0x0c, 0x48, 0x08, 0x52, 0x09, 0x67, + 0x61, 0x73, 0x54, 0x69, 0x70, 0x43, 0x61, 0x70, 0x88, 0x01, 0x01, 0x12, 0x3c, 0x0a, 0x0b, 0x61, + 0x63, 0x63, 0x65, 0x73, 0x73, 0x5f, 0x6c, 0x69, 0x73, 0x74, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x0b, + 0x32, 0x16, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x41, 0x63, + 0x63, 0x65, 0x73, 0x73, 0x4c, 0x69, 0x73, 0x74, 0x48, 0x09, 0x52, 0x0a, 0x61, 0x63, 0x63, 0x65, + 0x73, 0x73, 0x4c, 0x69, 0x73, 0x74, 0x88, 0x01, 0x01, 0x12, 0x27, 0x0a, 0x0d, 0x65, 0x74, 0x78, + 0x5f, 0x67, 0x61, 0x73, 0x5f, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x04, + 0x48, 0x0a, 0x52, 0x0b, 0x65, 0x74, 0x78, 0x47, 0x61, 0x73, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x88, + 0x01, 0x01, 0x12, 0x27, 0x0a, 0x0d, 0x65, 0x74, 0x78, 0x5f, 0x67, 0x61, 0x73, 0x5f, 0x70, 0x72, + 0x69, 0x63, 0x65, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x0c, 0x48, 0x0b, 0x52, 0x0b, 0x65, 0x74, 0x78, + 0x47, 0x61, 0x73, 0x50, 0x72, 0x69, 0x63, 0x65, 0x88, 0x01, 0x01, 0x12, 0x23, 0x0a, 0x0b, 0x65, + 0x74, 0x78, 0x5f, 0x67, 0x61, 0x73, 0x5f, 0x74, 0x69, 0x70, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x0c, + 0x48, 0x0c, 0x52, 0x09, 0x65, 0x74, 0x78, 0x47, 0x61, 0x73, 0x54, 0x69, 0x70, 0x88, 0x01, 0x01, + 0x12, 0x1e, 0x0a, 0x08, 0x65, 0x74, 0x78, 0x5f, 0x64, 0x61, 0x74, 0x61, 0x18, 0x0e, 0x20, 0x01, + 0x28, 0x0c, 0x48, 0x0d, 0x52, 0x07, 0x65, 0x74, 0x78, 0x44, 0x61, 0x74, 0x61, 0x88, 0x01, 0x01, + 0x12, 0x43, 0x0a, 0x0f, 0x65, 0x74, 0x78, 0x5f, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x5f, 0x6c, + 0x69, 0x73, 0x74, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x16, 0x2e, 0x62, 0x6c, 0x6f, 0x63, + 0x6b, 0x2e, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x41, 0x63, 0x63, 0x65, 0x73, 0x73, 0x4c, 0x69, 0x73, + 0x74, 0x48, 0x0e, 0x52, 0x0d, 0x65, 0x74, 0x78, 0x41, 0x63, 0x63, 0x65, 0x73, 0x73, 0x4c, 0x69, + 0x73, 0x74, 0x88, 0x01, 0x01, 0x12, 0x11, 0x0a, 0x01, 0x76, 0x18, 0x10, 0x20, 0x01, 0x28, 0x0c, + 0x48, 0x0f, 0x52, 0x01, 0x76, 0x88, 0x01, 0x01, 0x12, 0x11, 0x0a, 0x01, 0x72, 0x18, 0x11, 0x20, + 0x01, 0x28, 0x0c, 0x48, 0x10, 0x52, 0x01, 0x72, 0x88, 0x01, 0x01, 0x12, 0x11, 0x0a, 0x01, 0x73, + 0x18, 0x12, 0x20, 0x01, 0x28, 0x0c, 0x48, 0x11, 0x52, 0x01, 0x73, 0x88, 0x01, 0x01, 0x12, 0x46, + 0x0a, 0x13, 0x6f, 0x72, 0x69, 0x67, 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6e, 0x67, 0x5f, 0x74, 0x78, + 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x13, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x63, 0x6f, + 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x48, 0x61, 0x73, 0x68, 0x48, 0x12, + 0x52, 0x11, 0x6f, 0x72, 0x69, 0x67, 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6e, 0x67, 0x54, 0x78, 0x48, + 0x61, 0x73, 0x68, 0x88, 0x01, 0x01, 0x12, 0x20, 0x0a, 0x09, 0x65, 0x74, 0x78, 0x5f, 0x69, 0x6e, + 0x64, 0x65, 0x78, 0x18, 0x14, 0x20, 0x01, 0x28, 0x0d, 0x48, 0x13, 0x52, 0x08, 0x65, 0x74, 0x78, + 0x49, 0x6e, 0x64, 0x65, 0x78, 0x88, 0x01, 0x01, 0x12, 0x22, 0x0a, 0x0a, 0x65, 0x74, 0x78, 0x5f, + 0x73, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x18, 0x15, 0x20, 0x01, 0x28, 0x0c, 0x48, 0x14, 0x52, 0x09, + 0x65, 0x74, 0x78, 0x53, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x88, 0x01, 0x01, 0x12, 0x2d, 0x0a, 0x06, + 0x74, 0x78, 0x5f, 0x69, 0x6e, 0x73, 0x18, 0x16, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x62, + 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x54, 0x78, 0x49, 0x6e, 0x73, 0x48, + 0x15, 0x52, 0x05, 0x74, 0x78, 0x49, 0x6e, 0x73, 0x88, 0x01, 0x01, 0x12, 0x30, 0x0a, 0x07, 0x74, + 0x78, 0x5f, 0x6f, 0x75, 0x74, 0x73, 0x18, 0x17, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x62, + 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x54, 0x78, 0x4f, 0x75, 0x74, 0x73, + 0x48, 0x16, 0x52, 0x06, 0x74, 0x78, 0x4f, 0x75, 0x74, 0x73, 0x88, 0x01, 0x01, 0x12, 0x21, 0x0a, + 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x18, 0x18, 0x20, 0x01, 0x28, 0x0c, + 0x48, 0x17, 0x52, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x88, 0x01, 0x01, + 0x42, 0x07, 0x0a, 0x05, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x42, 0x05, 0x0a, 0x03, 0x5f, 0x74, 0x6f, + 0x42, 0x08, 0x0a, 0x06, 0x5f, 0x6e, 0x6f, 0x6e, 0x63, 0x65, 0x42, 0x08, 0x0a, 0x06, 0x5f, 0x76, + 0x61, 0x6c, 0x75, 0x65, 0x42, 0x06, 0x0a, 0x04, 0x5f, 0x67, 0x61, 0x73, 0x42, 0x07, 0x0a, 0x05, 0x5f, 0x64, 0x61, 0x74, 0x61, 0x42, 0x0b, 0x0a, 0x09, 0x5f, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x64, 0x42, 0x0e, 0x0a, 0x0c, 0x5f, 0x67, 0x61, 0x73, 0x5f, 0x66, 0x65, 0x65, 0x5f, 0x63, 0x61, 0x70, 0x42, 0x0e, 0x0a, 0x0c, 0x5f, 0x67, 0x61, 0x73, 0x5f, 0x74, 0x69, 0x70, 0x5f, 0x63, diff --git a/core/types/proto_block.proto b/core/types/proto_block.proto index c3f58bcb40..d760302544 100644 --- a/core/types/proto_block.proto +++ b/core/types/proto_block.proto @@ -47,27 +47,26 @@ message ProtoTransaction { optional bytes to = 2; optional uint64 nonce = 3; optional bytes value = 4; - optional bytes gas_price = 5; - optional uint64 gas = 6; - optional bytes data = 7; - optional bytes chain_id = 8; - optional bytes gas_fee_cap = 9; - optional bytes gas_tip_cap = 10; - optional ProtoAccessList access_list = 11; - optional uint64 etx_gas_limit = 12; - optional bytes etx_gas_price = 13; - optional bytes etx_gas_tip = 14; - optional bytes etx_data = 15; - optional ProtoAccessList etx_access_list = 16; - optional bytes v = 17; - optional bytes r = 18; - optional bytes s = 19; - optional common.ProtoHash originating_tx_hash = 20; - optional uint32 etx_index = 21; - optional bytes etx_sender = 22; - optional ProtoTxIns tx_ins = 23; - optional ProtoTxOuts tx_outs = 24; - optional bytes signature = 25; + optional uint64 gas = 5; + optional bytes data = 6; + optional bytes chain_id = 7; + optional bytes gas_fee_cap = 8; + optional bytes gas_tip_cap = 9; + optional ProtoAccessList access_list = 10; + optional uint64 etx_gas_limit = 11; + optional bytes etx_gas_price = 12; + optional bytes etx_gas_tip = 13; + optional bytes etx_data = 14; + optional ProtoAccessList etx_access_list = 15; + optional bytes v = 16; + optional bytes r = 17; + optional bytes s = 18; + optional common.ProtoHash originating_tx_hash = 19; + optional uint32 etx_index = 20; + optional bytes etx_sender = 21; + optional ProtoTxIns tx_ins = 22; + optional ProtoTxOuts tx_outs = 23; + optional bytes signature = 24; } message ProtoTransactions { repeated ProtoTransaction transactions = 1; } @@ -133,22 +132,18 @@ message ProtoPendingEtxsRollup { optional ProtoTransactions etxs_rollup = 2; } -message ProtoTxIns { - repeated ProtoTxIn tx_ins = 1; -} +message ProtoTxIns { repeated ProtoTxIn tx_ins = 1; } -message ProtoTxOuts { - repeated ProtoTxOut tx_outs = 1; -} +message ProtoTxOuts { repeated ProtoTxOut tx_outs = 1; } -message ProtoTxIn { - optional ProtoOutPoint previous_out_point = 1; +message ProtoTxIn { + optional ProtoOutPoint previous_out_point = 1; optional bytes pub_key = 2; -} +} -message ProtoOutPoint { - optional common.ProtoHash hash = 1; - optional uint32 index = 2; +message ProtoOutPoint { + optional common.ProtoHash hash = 1; + optional uint32 index = 2; } message ProtoTxOut { diff --git a/core/types/transaction.go b/core/types/transaction.go index 540e2e38f4..9450d6f830 100644 --- a/core/types/transaction.go +++ b/core/types/transaction.go @@ -28,6 +28,7 @@ import ( "github.com/btcsuite/btcd/btcec/v2/schnorr" "github.com/dominant-strategies/go-quai/common" "github.com/dominant-strategies/go-quai/common/math" + "google.golang.org/protobuf/proto" "github.com/dominant-strategies/go-quai/crypto" "github.com/dominant-strategies/go-quai/rlp" @@ -416,6 +417,63 @@ func (tx *Transaction) ProtoDecode(protoTx *ProtoTransaction, location common.Lo return nil } +func (tx *Transaction) ProtoEncodeTxSigningData() *ProtoTransaction { + protoTxSigningData := &ProtoTransaction{} + if tx == nil { + return protoTxSigningData + } + switch tx.Type() { + case 0: + txType := uint64(tx.Type()) + protoTxSigningData.Type = &txType + protoTxSigningData.ChainId = tx.ChainId().Bytes() + nonce := tx.Nonce() + gas := tx.Gas() + protoTxSigningData.Nonce = &nonce + protoTxSigningData.Gas = &gas + protoTxSigningData.AccessList = tx.AccessList().ProtoEncode() + protoTxSigningData.Value = tx.Value().Bytes() + protoTxSigningData.Data = tx.Data() + if tx.To() != nil { + protoTxSigningData.To = tx.To().Bytes() + } else { + protoTxSigningData.To = []byte{} + } + protoTxSigningData.GasFeeCap = tx.GasFeeCap().Bytes() + protoTxSigningData.GasTipCap = tx.GasTipCap().Bytes() + case 1: + return protoTxSigningData + case 2: + txType := uint64(tx.Type()) + protoTxSigningData.Type = &txType + protoTxSigningData.ChainId = tx.ChainId().Bytes() + gas := tx.Gas() + nonce := tx.Nonce() + protoTxSigningData.Nonce = &nonce + protoTxSigningData.Gas = &gas + protoTxSigningData.AccessList = tx.AccessList().ProtoEncode() + protoTxSigningData.Value = tx.Value().Bytes() + protoTxSigningData.Data = tx.Data() + protoTxSigningData.To = tx.To().Bytes() + protoTxSigningData.GasFeeCap = tx.GasFeeCap().Bytes() + protoTxSigningData.GasTipCap = tx.GasTipCap().Bytes() + etxGasLimit := tx.ETXGasLimit() + protoTxSigningData.EtxGasLimit = &etxGasLimit + protoTxSigningData.EtxGasPrice = tx.ETXGasPrice().Bytes() + protoTxSigningData.EtxGasTip = tx.ETXGasTip().Bytes() + protoTxSigningData.EtxData = tx.ETXData() + protoTxSigningData.EtxAccessList = tx.ETXAccessList().ProtoEncode() + case 3: + txType := uint64(tx.Type()) + protoTxSigningData.Type = &txType + protoTxSigningData.ChainId = tx.ChainId().Bytes() + protoTxSigningData.TxIns, _ = tx.TxIn().ProtoEncode() + protoTxSigningData.TxOuts, _ = tx.TxOut().ProtoEncode() + protoTxSigningData.Signature = tx.GetSchnorrSignature().Serialize() + } + return protoTxSigningData +} + // EncodeRLP implements rlp.Encoder func (tx *Transaction) EncodeRLP(w io.Writer) error { buf := encodeBufferPool.Get().(*bytes.Buffer) @@ -695,11 +753,16 @@ func (tx *Transaction) EffectiveGasTipIntCmp(other *big.Int, baseFee *big.Int) i } // Hash returns the transaction hash. -func (tx *Transaction) Hash() common.Hash { +func (tx *Transaction) Hash() (h common.Hash) { if hash := tx.hash.Load(); hash != nil { return hash.(common.Hash) } - h := prefixedRlpHash(tx.Type(), tx.inner) + protoTx, _ := tx.ProtoEncode() + data, _ := proto.Marshal(protoTx) + sha := hasherPool.Get().(crypto.KeccakState) + defer hasherPool.Put(sha) + sha.Reset() + h.SetBytes(sha.Sum(data)) tx.hash.Store(h) return h } diff --git a/core/types/transaction_signing.go b/core/types/transaction_signing.go index e6e96322c7..57e8ae33cc 100644 --- a/core/types/transaction_signing.go +++ b/core/types/transaction_signing.go @@ -24,7 +24,9 @@ import ( "github.com/dominant-strategies/go-quai/common" "github.com/dominant-strategies/go-quai/crypto" + "github.com/dominant-strategies/go-quai/log" "github.com/dominant-strategies/go-quai/params" + "google.golang.org/protobuf/proto" ) var ( @@ -202,56 +204,18 @@ func (s SignerV1) SignatureValues(tx *Transaction, sig []byte) (R, S, V *big.Int // Hash returns the hash to be signed by the sender. // It does not uniquely identify the transaction. -func (s SignerV1) Hash(tx *Transaction) common.Hash { - if tx.Type() == QiTxType { - return prefixedRlpHash( - tx.Type(), - []interface{}{ - s.chainId, - tx.TxIn(), - tx.TxOut(), - }) - } - txTo := tx.To() - var txToBytes []byte - if txTo == nil { - txToBytes = []byte{} - } else { - txToBytes = txTo.Bytes() - } - if tx.Type() == InternalToExternalTxType { - return prefixedRlpHash( - tx.Type(), - []interface{}{ - s.chainId, - tx.Nonce(), - tx.GasTipCap(), - tx.GasFeeCap(), - tx.Gas(), - txToBytes, - tx.Value(), - tx.Data(), - tx.AccessList(), - tx.ETXGasLimit(), - tx.ETXGasPrice(), - tx.ETXGasTip(), - tx.ETXData(), - tx.ETXAccessList(), - }) +func (s SignerV1) Hash(tx *Transaction) (h common.Hash) { + protoTxSigningData := tx.ProtoEncodeTxSigningData() + data, err := proto.Marshal(protoTxSigningData) + if err != nil { + log.Global.Error("failed to marshal tx signing data", "err", err) } - return prefixedRlpHash( - tx.Type(), - []interface{}{ - s.chainId, - tx.Nonce(), - tx.GasTipCap(), - tx.GasFeeCap(), - tx.Gas(), - txToBytes, - tx.Value(), - tx.Data(), - tx.AccessList(), - }) + sha := hasherPool.Get().(crypto.KeccakState) + defer hasherPool.Put(sha) + sha.Reset() + sha.Sum(data) + sha.Read(h[:]) + return h } func (s SignerV1) ChainID() *big.Int { diff --git a/internal/quaiapi/api.go b/internal/quaiapi/api.go index a5cb9ead03..5b30e32383 100644 --- a/internal/quaiapi/api.go +++ b/internal/quaiapi/api.go @@ -25,6 +25,7 @@ import ( "time" "github.com/davecgh/go-spew/spew" + "google.golang.org/protobuf/proto" "github.com/dominant-strategies/go-quai/common" "github.com/dominant-strategies/go-quai/common/hexutil" @@ -1537,9 +1538,12 @@ func SubmitTransaction(ctx context.Context, b Backend, tx *types.Transaction) (c // The sender is responsible for signing the transaction and using the correct nonce. func (s *PublicTransactionPoolAPI) SendRawTransaction(ctx context.Context, input hexutil.Bytes) (common.Hash, error) { tx := new(types.Transaction) - if err := tx.UnmarshalBinary(input); err != nil { + protoTransaction := new(types.ProtoTransaction) + err := proto.Unmarshal(input, protoTransaction) + if err != nil { return common.Hash{}, err } + tx.ProtoDecode(protoTransaction, s.b.NodeLocation()) return SubmitTransaction(ctx, s.b, tx) }