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

[Batch Execution] Fix for desync issue. #1778

Merged
merged 1 commit into from
Feb 7, 2024
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
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
Loading