Skip to content

Commit

Permalink
Fix for desync issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanIliev545 committed Feb 7, 2024
1 parent 22b397d commit 857ccf8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
3 changes: 3 additions & 0 deletions go/enclave/components/batch_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,14 @@ func (executor *batchExecutor) ComputeBatch(context *BatchExecutionContext, fail

syntheticTransactions := append(xchainTxs, freeTransactions...)

// fromTxIndex - Here we start from the 0 index. This will be the same for a validator.
successfulTxs, excludedTxs, txReceipts, err := executor.processTransactions(batch, 0, transactionsToProcess, stateDB, context.ChainConfig, false)
if err != nil {
return nil, fmt.Errorf("could not process transactions. Cause: %w", err)
}

// fromTxIndex - Here we start from the len of the successful transactions; As long as we have the exact same successful transactions in a batch,
// we will start from the same place.
ccSuccessfulTxs, _, ccReceipts, err := executor.processTransactions(batch, len(successfulTxs), syntheticTransactions, stateDB, context.ChainConfig, true)
if err != nil {
return nil, err
Expand Down
14 changes: 12 additions & 2 deletions go/enclave/evm/evm_facade.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ func ExecuteTransactions(
}

hash := header.Hash()

// tCountRollback - every time a transaction errors out, rather than producing a receipt
// we push back the index in the "block" (batch) it will have. This means that errored out transactions
// will be shunted by their follow up successful transaction.
// This also means the mix digest can be the same for two transactions, but
// as the error one reverts and cant mutate the state in order to push back the counter
// this should not open up any attack vectors on the randomness.
tCountRollback := 0
for i, t := range txs {
r, err := executeTransaction(
s,
Expand All @@ -68,11 +76,12 @@ func ExecuteTransactions(
t,
usedGas,
vmCfg,
fromTxIndex+i,
(fromTxIndex+i)-tCountRollback,
hash,
header.Number.Uint64(),
)
if err != nil {
tCountRollback++
result[t.Tx.Hash()] = err
logger.Info("Failed to execute tx:", log.TxKey, t.Tx.Hash(), log.CtrErrKey, err)
continue
Expand Down Expand Up @@ -156,7 +165,8 @@ func executeTransaction(
// Create a new context to be used in the EVM environment
blockContext := gethcore.NewEVMBlockContext(header, bc, author)
vmenv := vm.NewEVM(blockContext, vm.TxContext{BlobHashes: tx.Tx.BlobHashes()}, statedb, config, cfg)
receipt, err := applyTransaction(msg, config, gp, statedb, header.Number, header.Hash(), tx.Tx, usedGas, vmenv)
var receipt *types.Receipt
receipt, err = applyTransaction(msg, config, gp, statedb, header.Number, header.Hash(), tx.Tx, usedGas, vmenv)
if err != nil {
// If the transaction has l1 cost, then revert the funds exchange
// as it will not be published on error (no receipt condition)
Expand Down

0 comments on commit 857ccf8

Please sign in to comment.