Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add create2 #269

Merged
merged 15 commits into from
Jan 18, 2018
Merged

Add create2 #269

merged 15 commits into from
Jan 18, 2018

Conversation

NIC619
Copy link
Contributor

@NIC619 NIC619 commented Jan 14, 2018

How was it fixed?

Add CREATE2 opcode

  • update intrinsic gas calculation of sharing transaction
  • add CREATE2 address check in execute_transaction to make sure transaction.to is the same as computed contract address
  • add CREATE2 opcode and remove CREATE from sharding opcodes
  • test

Cute Animal Picture

@hwwhww
Copy link
Contributor

hwwhww commented Jan 14, 2018

link #224

@@ -43,5 +44,6 @@ def _get_sharding_intrinsic_gas(transaction_data, transaction_code):
return (
GAS_TX +
num_zero_bytes * GAS_TXDATAZERO +
num_non_zero_bytes * GAS_TXDATANONZERO
num_non_zero_bytes * GAS_TXDATANONZERO +
GAS_TXCREATE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may miss something, could you tell me why GAS_TXCREATE is included in every sharding tx?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. It should not be included in every tx.

@@ -190,3 +191,69 @@ def __call__(self, computation):
if computation.msg.is_static:
raise WriteProtection("Cannot modify state while inside of a STATICCALL context")
return super(CreateEIP150, self).__call__(computation)


class Create2(CreateEIP150):
Copy link
Contributor

@hwwhww hwwhww Jan 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason for inheriting CreateEIP150 instead of CreateByzantium?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CreateByzantium and Create2 both override __call__ function so I make Create2 inherit from CreateEIP150 and copy the is_static check from CreateByzantium.

Copy link
Contributor

@hwwhww hwwhww left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the shard chain doesn’t have as many JSON test cases as the non-shard chain now, add some boundary test cases might help.
Some test cases like:

  1. When contract_address != transaction.to?
  2. When is_collision is True?
  3. Assert vm.block.header.gas_used after apply_transaction

simple_transfer_contract_address,
simple_contract_factory_bytecode,
CREATE2_contract_bytecode,
CREATE2_contract_address,
)


def test_sharding_transaction(shard_chain_without_block_validation): # noqa: F811
Copy link
Contributor

@hwwhww hwwhww Jan 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it's a test in test_vm_state.py test_sharding_vm.py, mind updating the test name to test_sharding_apply_transaction?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. I will update the name. Do you mean also moving it to test_vm_state.py?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ohhhhh sorry, I meant test_sharding_vm.py!

@NIC619
Copy link
Contributor Author

NIC619 commented Jan 16, 2018

Tests updated. Thanks.

Copy link
Member

@pipermerriam pipermerriam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some cleanup suggestions.

}


SHARDING_OPCODES = merge(
copy.deepcopy(BYZANTIUM_OPCODES),
NEW_OPCODES
)


SHARDING_OPCODES.pop(opcode_values.CREATE)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of popping this value out, can we do the following a few lines up.

from cytoolz import dissoc

SHARDING_OPCODES = merge(
     dissoc(copy.deepcopy(BYZANTIUM_OPCODES), opcode_values.CREATE),
     NEW_OPCODES
 )

# Second test: contract that deploy new contract with CREATE2
second_deploy_tx = new_sharding_transaction(
CREATE2_contract_address,
b'',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change this to use keyword arguments so that it's clear what all of these similar parameters are.

chain = shard_chain_without_block_validation
first_failed_deploy_tx = new_sharding_transaction(
simple_transfer_contract_address,
b'',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same request here regarding keyword arguments.

# Next, complete deploying the contract
successful_deploy_tx = new_sharding_transaction(
simple_transfer_contract_address,
b'',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here

# Second case: deploy to existing account
second_failed_deploy_tx = successful_deploy_tx
computation = vm.apply_transaction(second_failed_deploy_tx)
assert computation.is_error
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a check that isinstance(computation._error, ContractCreationCollision)


vm = chain.get_vm()
computation = vm.apply_transaction(first_failed_deploy_tx)
assert computation.is_error
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a check for isinstance(computation._error, IncorrectContractCreationAddress)

Copy link
Member

@pipermerriam pipermerriam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants