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

Fix effectiveGasprice unsigned txs with forkId lower than 5 #2278

Merged
merged 1 commit into from
Jul 11, 2023
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
6 changes: 5 additions & 1 deletion state/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func EncodeTransaction(tx types.Transaction, effectivePercentage uint8, forkID u
}

// EncodeUnsignedTransaction RLP encodes the given unsigned transaction
func EncodeUnsignedTransaction(tx types.Transaction, chainID uint64, forcedNonce *uint64) ([]byte, error) {
func EncodeUnsignedTransaction(tx types.Transaction, chainID uint64, forcedNonce *uint64, forkID uint64) ([]byte, error) {
v, _ := new(big.Int).SetString("0x1c", 0)
r, _ := new(big.Int).SetString("0xa54492cfacf71aef702421b7fbc70636537a7b2fbe5718c5ed970a001bb7756b", 0)
s, _ := new(big.Int).SetString("0x2e9fb27acc75955b898f0b12ec52aa34bf08f01db654374484b80bf12f0d841e", 0)
Expand Down Expand Up @@ -151,6 +151,10 @@ func EncodeUnsignedTransaction(tx types.Transaction, chainID uint64, forcedNonce
newSPadded := fmt.Sprintf("%064s", s.Text(hex.Base))
newVPadded := fmt.Sprintf("%02s", newV.Text(hex.Base))
effectivePercentageAsHex := fmt.Sprintf("%x", MaxEffectivePercentage)
// Only add EffectiveGasprice if forkID is equal or higher than 5
if forkID < forkID5 {
effectivePercentageAsHex = ""
}
txData, err := hex.DecodeString(hex.EncodeToString(txCodedRlp) + newRPadded + newSPadded + newVPadded + effectivePercentageAsHex)
if err != nil {
return nil, err
Expand Down
10 changes: 6 additions & 4 deletions state/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -793,13 +793,14 @@ func (s *State) internalProcessUnsignedTransaction(ctx context.Context, tx *type
}
}

batchL2Data, err := EncodeUnsignedTransaction(*tx, s.cfg.ChainID, &nonce)
forkID := s.GetForkIDByBatchNumber(lastBatch.BatchNumber)

batchL2Data, err := EncodeUnsignedTransaction(*tx, s.cfg.ChainID, &nonce, forkID)
if err != nil {
log.Errorf("error encoding unsigned transaction ", err)
return nil, err
}

forkID := s.GetForkIDByBatchNumber(lastBatch.BatchNumber)
// Create Batch
processBatchRequest := &pb.ProcessBatchRequest{
OldBatchNum: lastBatch.BatchNumber,
Expand Down Expand Up @@ -1036,13 +1037,14 @@ func (s *State) EstimateGas(transaction *types.Transaction, senderAddress common
Data: transaction.Data(),
})

batchL2Data, err := EncodeUnsignedTransaction(*tx, s.cfg.ChainID, nil)
forkID := s.GetForkIDByBatchNumber(lastBatch.BatchNumber)

batchL2Data, err := EncodeUnsignedTransaction(*tx, s.cfg.ChainID, nil, forkID)
if err != nil {
log.Errorf("error encoding unsigned transaction ", err)
return false, false, gasUsed, nil, err
}

forkID := s.GetForkIDByBatchNumber(lastBatch.BatchNumber)
// Create a batch to be sent to the executor
processBatchRequest := &pb.ProcessBatchRequest{
OldBatchNum: lastBatch.BatchNumber,
Expand Down