-
Notifications
You must be signed in to change notification settings - Fork 147
/
evm.go
40 lines (33 loc) · 1.16 KB
/
evm.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package gas
import "github.com/iotaledger/wasp/packages/util"
// <ISC gas> = <EVM Gas> * <A> / <B>
var DefaultEVMGasRatio = util.Ratio32{A: 1, B: 1}
func ISCGasBudgetToEVM(iscGasBudget uint64, gasRatio *util.Ratio32) uint64 {
// EVM gas budget = floor(ISC gas budget * B / A)
if gasRatio.IsEmpty() {
return 0
}
return gasRatio.YFloor64(iscGasBudget)
}
func ISCGasBurnedToEVM(iscGasBurned uint64, gasRatio *util.Ratio32) uint64 {
// estimated EVM gas = ceil(ISC gas burned * B / A)
if gasRatio.IsEmpty() {
return 0
}
return gasRatio.YCeil64(iscGasBurned)
}
func EVMGasToISC(evmGas uint64, gasRatio *util.Ratio32) uint64 {
// ISC gas burned = ceil(EVM gas * A / B)
if gasRatio.IsEmpty() {
return 0
}
return gasRatio.XCeil64(evmGas)
}
// EVMBlockGasLimit returns the ISC block gas limit converted to EVM gas units
func EVMBlockGasLimit(gasLimits *Limits, gasRatio *util.Ratio32) uint64 {
return ISCGasBudgetToEVM(gasLimits.MaxGasPerBlock, gasRatio)
}
// EVMCallGasLimit returns the maximum gas limit accepted for an EVM tx
func EVMCallGasLimit(gasLimits *Limits, gasRatio *util.Ratio32) uint64 {
return ISCGasBudgetToEVM(gasLimits.MaxGasPerRequest, gasRatio)
}