Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
gameofpointers committed Aug 15, 2024
1 parent b6da2f8 commit 3c944f9
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions params/protocol_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ const (
Sha3Gas uint64 = 30 // Once per SHA3 operation.
Sha3WordGas uint64 = 6 // Once per word of the SHA3 operation's data.

SstoreSetGas uint64 = 20000 // Once per SSTORE operation from clean zero to non-zero
SstoreResetGas uint64 = 5000 // Once per SSTORE operation from clean non-zero to something else
SstoreResetGas uint64 = 5000 // Once per SSTORE operation from clean non-zero to something else

ColdAccountAccessCost = uint64(2600) // COLD_ACCOUNT_ACCESS_COST
ColdSloadCost = uint64(2100) // COLD_SLOAD_COST
Expand Down Expand Up @@ -207,14 +206,26 @@ func RegionEntropyTarget(expansionNum uint8) *big.Int {
return new(big.Int).Mul(big.NewInt(timeFactor), new(big.Int).SetUint64(numZones))
}

// Gas calculation functions

func SstoreSetGas(stateSize, contractSize *big.Int) uint64 {
return 20000 * CalculateGasScalingFactor(stateSize, contractSize) // Once per SSTORE operation from clean zero to non-zero
}

func SstoreSentryGas(stateSize, contractSize *big.Int) uint64 {
return 2300 * CalculateGasScalingFactor(stateSize, contractSize) // Minimum gas required to be present for an SSTORE call, not consumed
}

func CalculateGasScalingFactor(stateSize, contractSize *big.Int) uint64 {
stateSizeFloat, _ := stateSize.Float64()
contractSizeFloat, _ := contractSize.Float64()
scalingFactor := math.Log(stateSizeFloat) + math.Log(contractSizeFloat)
var stateSizeFloat, contractSizeFloat, scalingFactor float64
if stateSize.Sign() != 0 {
stateSizeFloat, _ = stateSize.Float64()
scalingFactor += math.Log(stateSizeFloat)
}
if contractSize.Sign() != 0 {
contractSizeFloat, _ = contractSize.Float64()
scalingFactor += math.Log(contractSizeFloat)
}
// If we can assume that the gas price constants is correct for level 7 trie
return uint64(scalingFactor) / 7
}

0 comments on commit 3c944f9

Please sign in to comment.