Skip to content

Commit

Permalink
Remove todo and refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
simonlechner committed Dec 19, 2024
1 parent 680ee56 commit fa627d9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
24 changes: 9 additions & 15 deletions go/processor/floria/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ func (p *processor) Run(
return tosca.Receipt{}, nil
}

intrinsicGas := setupGasBilling(transaction)
if gas < intrinsicGas {
setupGas := calculateSetupGas(transaction)
if gas < setupGas {
return errorReceipt, nil
}
gas -= intrinsicGas
gas -= setupGas

if blockParameters.Revision >= tosca.R12_Shanghai && transaction.Recipient == nil &&
len(transaction.Input) > maxInitCodeSize {
Expand Down Expand Up @@ -109,14 +109,6 @@ func (p *processor) Run(
if err != nil {
return errorReceipt, err
}
// Depending on wether the call was unsuccessful due to a revert with gas
// left or due to other failures, the transaction needs to handle it differently.
// TODO: add extensive testing for output handling in reverted/failed cases
// Work in progress, still prone to changes
if !result.Success && result.GasLeft == 0 {
return errorReceipt, nil
}
// End of work in progress

var createdAddress *tosca.Address
if kind == tosca.Create {
Expand Down Expand Up @@ -201,6 +193,7 @@ func callParameters(transaction tosca.Transaction, gas tosca.Gas) tosca.CallPara

func calculateGasLeft(transaction tosca.Transaction, result tosca.CallResult, revision tosca.Revision) tosca.Gas {
gasLeft := result.GasLeft

// 10% of remaining gas is charged for non-internal transactions
if transaction.Sender != (tosca.Address{}) {
gasLeft -= gasLeft / 10
Expand Down Expand Up @@ -235,7 +228,7 @@ func refundGas(transaction tosca.Transaction, context tosca.TransactionContext,
context.SetBalance(transaction.Sender, senderBalance)
}

func setupGasBilling(transaction tosca.Transaction) tosca.Gas {
func calculateSetupGas(transaction tosca.Transaction) tosca.Gas {
var gas tosca.Gas
if transaction.Recipient == nil {
gas = TxGasContractCreation
Expand All @@ -251,13 +244,14 @@ func setupGasBilling(transaction tosca.Transaction) tosca.Gas {
}
}
zeroBytes := tosca.Gas(len(transaction.Input)) - nonZeroBytes

// No overflow check for the gas computation is required although it is performed in the
// opera version. The overflow check would be triggered in a worst case with an input
// greater than 2^64 / 16 - 53000 = ~10^18, which is not possible with real world hardware
gas += zeroBytes * TxDataZeroGasEIP2028
gas += nonZeroBytes * TxDataNonZeroGasEIP2028
}

// No overflow check for the gas computation is required although it is performed in the
// opera version. The overflow check would be triggered in a worst case with an input
// greater than 2^64 / 16 - 53000 = ~10^18, which is not possible with real world hardware
if transaction.AccessList != nil {
gas += tosca.Gas(len(transaction.AccessList)) * TxAccessListAddressGas

Expand Down
2 changes: 1 addition & 1 deletion go/processor/floria/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ func TestProcessor_SetupGasBilling(t *testing.T) {
AccessList: test.accessList,
}

actualGasUsed := setupGasBilling(transaction)
actualGasUsed := calculateSetupGas(transaction)
if actualGasUsed != test.expectedGasUsed {
t.Errorf("setupGasBilling returned incorrect gas used, got: %d, want: %d", actualGasUsed, test.expectedGasUsed)
}
Expand Down

0 comments on commit fa627d9

Please sign in to comment.