@@ -89,6 +89,8 @@ func (aw *AccessWitness) Copy() *AccessWitness {
89
89
return naw
90
90
}
91
91
92
+ // TouchFullAccount returns the gas to be charged for each of the currently cold
93
+ // member fields of an account.
92
94
func (aw * AccessWitness ) TouchFullAccount (addr []byte , isWrite bool ) uint64 {
93
95
var gas uint64
94
96
for i := utils .VersionLeafKey ; i <= utils .CodeSizeLeafKey ; i ++ {
@@ -97,22 +99,27 @@ func (aw *AccessWitness) TouchFullAccount(addr []byte, isWrite bool) uint64 {
97
99
return gas
98
100
}
99
101
102
+ // TouchAndChargeMessageCall returns the gas to be charged for each of the currently
103
+ // cold member fields of an account, that need to be touched when making a message
104
+ // call to that account.
100
105
func (aw * AccessWitness ) TouchAndChargeMessageCall (destination []byte ) uint64 {
101
106
var gas uint64
102
107
gas += aw .touchAddressAndChargeGas (addr , zeroTreeIndex , utils .VersionLeafKey , false )
103
108
gas += aw .touchAddressAndChargeGas (addr , zeroTreeIndex , utils .CodeSizeLeafKey , false )
104
109
return gas
105
110
}
106
111
112
+ // TouchAndChargeValueTransfer returns the gas to be charged for each of the currently
113
+ // cold balance member fields of the caller and the callee accounts.
107
114
func (aw * AccessWitness ) TouchAndChargeValueTransfer (callerAddr , targetAddr []byte ) uint64 {
108
115
var gas uint64
109
116
gas += aw .touchAddressAndChargeGas (callerAddr , zeroTreeIndex , utils .BalanceLeafKey , true )
110
117
gas += aw .touchAddressAndChargeGas (targetAddr , zeroTreeIndex , utils .BalanceLeafKey , true )
111
118
return gas
112
119
}
113
120
114
- // TouchAndChargeContractCreateInit charges access costs to initiate
115
- // a contract creation
121
+ // TouchAndChargeContractCreateInit returns the access gas costs for the initialization of
122
+ // a contract creation.
116
123
func (aw * AccessWitness ) TouchAndChargeContractCreateInit (addr []byte , createSendsValue bool ) uint64 {
117
124
var gas uint64
118
125
gas += aw .touchAddressAndChargeGas (addr , zeroTreeIndex , utils .VersionLeafKey , true )
@@ -123,41 +130,30 @@ func (aw *AccessWitness) TouchAndChargeContractCreateInit(addr []byte, createSen
123
130
return gas
124
131
}
125
132
126
- func (aw * AccessWitness ) TouchTxOriginAndComputeGas (originAddr []byte ) uint64 {
133
+ // TouchTxOrigin adds the member fields of the sender account to the witness,
134
+ // so that cold accesses are not charged, since they are covered by the 21000 gas.
135
+ func (aw * AccessWitness ) TouchTxOrigin (originAddr []byte ) {
127
136
for i := utils .VersionLeafKey ; i <= utils .CodeSizeLeafKey ; i ++ {
128
137
aw .touchAddressAndChargeGas (originAddr , zeroTreeIndex , byte (i ), i == utils .BalanceLeafKey || i == utils .NonceLeafKey )
129
138
}
130
-
131
- // Kaustinen note: we're currently experimenting with stop chargin gas for the origin address
132
- // so simple transfer still take 21000 gas. This is to potentially avoid breaking existing tooling.
133
- // This is the reason why we return 0 instead of `gas`.
134
- // Note that we still have to touch the addresses to make sure the witness is correct.
135
- return 0
136
139
}
137
140
138
- func (aw * AccessWitness ) TouchTxExistingAndComputeGas (targetAddr []byte , sendsValue bool ) uint64 {
139
- aw .touchAddressAndChargeGas (targetAddr , zeroTreeIndex , utils .VersionLeafKey , false )
140
- aw .touchAddressAndChargeGas (targetAddr , zeroTreeIndex , utils .CodeSizeLeafKey , false )
141
- aw .touchAddressAndChargeGas (targetAddr , zeroTreeIndex , utils .CodeKeccakLeafKey , false )
142
- aw .touchAddressAndChargeGas (targetAddr , zeroTreeIndex , utils .NonceLeafKey , false )
143
- if sendsValue {
144
- aw .touchAddressAndChargeGas (targetAddr , zeroTreeIndex , utils .BalanceLeafKey , true )
145
- } else {
146
- aw .touchAddressAndChargeGas (targetAddr , zeroTreeIndex , utils .BalanceLeafKey , false )
141
+ // TouchTxDestination adds the member fields of the sender account to the witness,
142
+ // so that cold accesses are not charged, since they are covered by the 21000 gas.
143
+ func (aw * AccessWitness ) TouchTxDestination (targetAddr []byte , sendsValue bool ) {
144
+ for i := utils .VersionLeafKey ; i <= utils .CodeSizeLeafKey ; i ++ {
145
+ aw .touchAddressAndChargeGas (targetAddr , zeroTreeIndex , byte (i ), i == utils .VersionLeafKey && sendsValue )
147
146
}
148
-
149
- // Kaustinen note: we're currently experimenting with stop chargin gas for the origin address
150
- // so simple transfer still take 21000 gas. This is to potentially avoid breaking existing tooling.
151
- // This is the reason why we return 0 instead of `gas`.
152
- // Note that we still have to touch the addresses to make sure the witness is correct.
153
- return 0
154
147
}
155
148
149
+ // TouchSlotAndChargeGas returns the amount of gas to be charged for a cold storage access.
156
150
func (aw * AccessWitness ) TouchSlotAndChargeGas (addr []byte , slot common.Hash , isWrite bool ) uint64 {
157
151
treeIndex , subIndex := utils .StorageIndex (slot .Bytes ())
158
152
return aw .touchAddressAndChargeGas (addr , * treeIndex , subIndex , isWrite )
159
153
}
160
154
155
+ // touchAddressAndChargeGas adds any missing access event to the witness, and returns the cold
156
+ // access cost to be charged, if need be.
161
157
func (aw * AccessWitness ) touchAddressAndChargeGas (addr []byte , treeIndex uint256.Int , subIndex byte , isWrite bool ) uint64 {
162
158
stemRead , selectorRead , stemWrite , selectorWrite , selectorFill := aw .touchAddress (addr , treeIndex , subIndex , isWrite )
163
159
0 commit comments