|
20 | 20 | ceil32,
|
21 | 21 | )
|
22 | 22 | from eth.vm import mnemonics
|
23 |
| -from eth.vm.computation import ( |
24 |
| - BaseComputation |
25 |
| -) |
26 |
| -from eth.vm.opcode import ( |
27 |
| - Opcode, |
28 |
| -) |
| 23 | +from eth.vm.computation import BaseComputation |
| 24 | +from eth.vm.message import Message |
| 25 | +from eth.vm.opcode import Opcode |
29 | 26 |
|
30 | 27 | from .call import max_child_gas_eip150
|
31 | 28 |
|
@@ -193,13 +190,16 @@ def __call__(self, computation: BaseComputation) -> None:
|
193 | 190 | code=call_data,
|
194 | 191 | create_address=contract_address,
|
195 | 192 | )
|
| 193 | + self.apply_create_message(computation, child_msg) |
196 | 194 |
|
| 195 | + def apply_create_message(self, computation: BaseComputation, child_msg: Message) -> None: |
197 | 196 | child_computation = computation.apply_child_computation(child_msg)
|
198 | 197 |
|
199 | 198 | if child_computation.is_error:
|
200 | 199 | computation.stack_push(0)
|
201 | 200 | else:
|
202 |
| - computation.stack_push(contract_address) |
| 201 | + computation.stack_push(child_msg.storage_address) |
| 202 | + |
203 | 203 | computation.return_gas(child_computation.get_gas_remaining())
|
204 | 204 |
|
205 | 205 |
|
@@ -240,3 +240,22 @@ def generate_contract_address(self,
|
240 | 240 | stack_data.salt,
|
241 | 241 | call_data
|
242 | 242 | )
|
| 243 | + |
| 244 | + def apply_create_message(self, computation: BaseComputation, child_msg: Message) -> None: |
| 245 | + # We need to ensure that creation operates on empty storage **and** |
| 246 | + # that if the initialization code fails that we revert the account back |
| 247 | + # to its original state root. |
| 248 | + snapshot = computation.state.snapshot() |
| 249 | + |
| 250 | + computation.state.account_db.delete_storage(child_msg.storage_address) |
| 251 | + |
| 252 | + child_computation = computation.apply_child_computation(child_msg) |
| 253 | + |
| 254 | + if child_computation.is_error: |
| 255 | + computation.state.revert(snapshot) |
| 256 | + computation.stack_push(0) |
| 257 | + else: |
| 258 | + computation.state.commit(snapshot) |
| 259 | + computation.stack_push(child_msg.storage_address) |
| 260 | + |
| 261 | + computation.return_gas(child_computation.get_gas_remaining()) |
0 commit comments