Multi-fragment activation: charge gas per fragment#4312
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #4312 +/- ##
===========================================
- Coverage 57.24% 33.00% -24.24%
===========================================
Files 483 484 +1
Lines 57539 57702 +163
===========================================
- Hits 32939 19047 -13892
- Misses 19694 35330 +15636
+ Partials 4906 3325 -1581 |
❌ 6 Tests Failed:
View the top 3 failed tests by shortest run time
📣 Thoughts on this report? Let Codecov know! | Powered by Codecov |
arbos/programs/wasmstorehelper.go
Outdated
| } | ||
|
|
||
| wasm, err := getWasmFromContractCode(statedb, code, progParams, false) | ||
| wasm, err := getWasmFromContractCode(statedb, code, progParams, false, nil) |
There was a problem hiding this comment.
I'm wondering - maybe we should pass p.programs.Burner() anyway here; otherwise, i'd add a comment why nil is ok
arbos/programs/programs.go
Outdated
| if !statedb.AddressInAccessList(addr) { | ||
| statedb.AddAddressToAccessList(addr) | ||
| // charge cold account access gas | ||
| if cost, overflow = cost.SafeIncrement(multigas.ResourceKindStorageAccess, gethParams.ColdAccountAccessCostEIP2929-gethParams.WarmStorageReadCostEIP2929); overflow { |
There was a problem hiding this comment.
why do we subtract warm storage here instead of just charge for cold read?
There was a problem hiding this comment.
Yeah a 100gas difference won't make a difference, so I will remove the warm cost Tsahi, just told me to model the code off EXTCODECOPY costs
There was a problem hiding this comment.
// gasExtCodeCopyEIP2929 implements extcodecopy according to EIP-2929
// EIP spec:
// > If the target is not in accessed_addresses,
// > charge COLD_ACCOUNT_ACCESS_COST gas, and add the address to accessed_addresses.
// > Otherwise, charge WARM_STORAGE_READ_COST gas.
func gasExtCodeCopyEIP2929(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (multigas.MultiGas, error) {
// memory expansion first (dynamic part of pre-2929 implementation)
multiGas, err := gasExtCodeCopy(evm, contract, stack, mem, memorySize)
if err != nil {
return multigas.ZeroGas(), err
}
addr := common.Address(stack.peek().Bytes20())
// Check slot presence in the access list
if !evm.StateDB.AddressInAccessList(addr) {
evm.StateDB.AddAddressToAccessList(addr)
var overflow bool
// We charge (cold-warm), since 'warm' is already charged as constantGas
// Charge cold → warm delta as storage-access gas.
// See rationale in: https://github.com/OffchainLabs/nitro/blob/master/docs/decisions/0002-multi-dimensional-gas-metering.md
if multiGas, overflow = multiGas.SafeIncrement(multigas.ResourceKindStorageAccess, params.ColdAccountAccessCostEIP2929-params.WarmStorageReadCostEIP2929); overflow {
return multigas.ZeroGas(), ErrGasUintOverflow
}
return multiGas, nil
}
return multiGas, nil
}
For reference EIP2929 specifies it this way, but honestly the way Tsahi wrote to me, it matters more that the feel is the same, rather then it being exactly the same.
arbos/programs/programs.go
Outdated
| if cost, overflow = cost.SafeIncrement(multigas.ResourceKindComputation, evmMemoryCost(codeSize)); overflow { | ||
| return vm.ErrGasUintOverflow | ||
| } | ||
| for kind := multigas.ResourceKindUnknown; kind < multigas.NumResourceKind; kind++ { |
There was a problem hiding this comment.
this is a bit vulnerable to changing the order of resource kinds, isn't it? I wonder if there's any safe way of iterating over every kind
There was a problem hiding this comment.
Yeah a loop seems overkill, I ended up just doing 2 if cases for the resources we use
| if codeSize > 0x1FFFFFFFE0 { | ||
| return 0 | ||
| } | ||
| words := (codeSize + 31) / 32 |
|
@pmikolajczyk41 @bragaigor @MishkaRogachev ok I believe I resolved your guys concerns ready for another look |
arbos/programs/programs.go
Outdated
| return vm.ErrGasUintOverflow | ||
| } | ||
| // charge memory gas | ||
| if cost, overflow = cost.SafeIncrement(multigas.ResourceKindComputation, evmMemoryCost(codeSize)); overflow { |
There was a problem hiding this comment.
I think we should remove this componenet.
Evm memory cost has a weird structure that should account only for added cost of new code, and we generally don't charge it in stylus. Stylus has a different way of charging for memory and I think here we could ignore both.
Not entirely sure.
|
@tsahee ready for another look. I believe I resolved your concerns. CI is a bit flakey, which is annoying, but I believe it is unrelated to this PR? I checked the logs and all the flakey tests don't seem to be related |
Add BurnMultiGas to Burner interface
fixes NIT-4405