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

Clean Up Deposit Contract #460

Closed
wants to merge 13 commits into from
Closed

Conversation

nisdas
Copy link
Contributor

@nisdas nisdas commented Jan 17, 2019

This PR cleans up the deposit contract, with changes in declarations, which was suggested by @jacqueswww.

Also another issue was that the vyper contract was not able to be compiled, however @jacqueswww has been kind enough to put up a quick fix here: vyperlang/vyper#1202. After that is merged in the deposit contract should have no issues being compiled.

Changes in Contract

  • Update version number to reflect latest vyper release.
  • Perform all calculations in terms of gwei
  • Change global constant from Gwei_Per_Eth to Wei_Per_Gwei

@hwwhww
Copy link
Contributor

hwwhww commented Jan 17, 2019

There's a MAX_DEPOSIT_AMOUNT thing on L691.

@hwwhww
Copy link
Contributor

hwwhww commented Jan 17, 2019

@nisdas
I labeled DO NOT MERGE since it's pending on the Vyper release.

@jacqueswww
Copy link

Just tagged beta-7, please give it a shot :)

hwwhww added a commit to hwwhww/deposit_contract that referenced this pull request Jan 18, 2019
hwwhww
hwwhww previously approved these changes Jan 18, 2019
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.

@hwwhww
Copy link
Contributor

hwwhww commented Jan 19, 2019

Second thought, the bytecodes are exactly the same. So I don't feel strongly of having this refactoring or not because it brings the "ether" unit back to the spec again. /cc @terenc3t @ralexstokes @JustinDrake

@jacqueswww
Copy link

jacqueswww commented Jan 19, 2019

Hmmm I see , valid point.

@nisdas
Copy link
Contributor Author

nisdas commented Jan 19, 2019

@hwwhww Is there any reason we shouldn't be using the ether unit ?

@hwwhww
Copy link
Contributor

hwwhww commented Jan 19, 2019

@nisdas due to the point of view from #418. :)

@nisdas
Copy link
Contributor Author

nisdas commented Jan 19, 2019

@hwwhww ah , k , fair enough then. Yeah then it would make sense to keep it in gwei

@terencechain
Copy link
Contributor

terencechain commented Jan 19, 2019

Ahh yes. I thought the direction we were heading is to normalize everything to Gwei : )

@nisdas
Copy link
Contributor Author

nisdas commented Jan 19, 2019

@hwwhww alright changed it to gwei :)

assert msg.value >= as_wei_value(MIN_DEPOSIT_AMOUNT, "gwei")
assert msg.value <= as_wei_value(MAX_DEPOSIT_AMOUNT, "gwei")
assert msg.value >= MIN_DEPOSIT
assert msg.value <= MAX_DEPOSIT

index: uint256 = self.deposit_count + TWO_TO_POWER_OF_TREE_DEPTH
deposit_amount: bytes[8] = slice(concat("", convert(msg.value / GWEI_PER_ETH, bytes32)), start=24, len=8)
Copy link
Collaborator

Choose a reason for hiding this comment

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

msg.value / GWEI_PER_ETH is only "correct" by chance. It should be msg.value / WEI_PER_GWEI.

@@ -670,8 +670,8 @@ full_deposit_count: uint256
@payable
@public
def deposit(deposit_input: bytes[2048]):
assert msg.value >= as_wei_value(MIN_DEPOSIT_AMOUNT, "gwei")
assert msg.value <= as_wei_value(MAX_DEPOSIT_AMOUNT, "gwei")
assert msg.value >= MIN_DEPOSIT
Copy link
Collaborator

Choose a reason for hiding this comment

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

In line with using Gwei everywhere, my suggestion is to define deposit_amount (e.g. deposit_amount = msg.value / WEI_PER_GWEI) and then only deal with Gwei amounts (never msg.value directly).

@nisdas
Copy link
Contributor Author

nisdas commented Jan 20, 2019

@JustinDrake Alright I changed all references to gwei. Also changed min/max deposits to be represented in terms of gwei

@nisdas nisdas changed the title Make Min/Max Deposits Cleaner in Deposit Contract Clean Up Deposit Contract Jan 20, 2019
* Use `self.get_deposit_root` instead of `self.deposit_tree[1]`
* Use `self.to_bytes` instead of `slice(concat("", convert( , bytes32)), start=24, len=8)`
* By consistent with naming (`deposit_amount` and `MAX_DEPOSIT_AMOUNT`)
* Remove unnecessary intermediate variables
* By consistent with comments (two spaces for inline comments, capitalise first letter)
* Symbolic constant now supported for `get_branch`
* Simplify code
@nisdas
Copy link
Contributor Author

nisdas commented Jan 21, 2019

@JustinDrake Hey, so I was testing this contract out and a bug came out, which is referenced here:
vyperlang/vyper#1206

We shouldn't call functions when emitting logs, as it leads to undecodable logs

@JustinDrake
Copy link
Collaborator

@nisdas Can you try making to_bytes @public as suggested in vyperlang/vyper#1206? (BTW, how can I reproduce your tests?)

@JustinDrake
Copy link
Collaborator

I suggest we wait until Vyper gets fixed vyperlang/vyper#1213

@hwwhww hwwhww dismissed their stale review January 25, 2019 02:42

The approval was for denomination clean up. Need farther tests for of the latest branch and also pending on #490 discussion.

@nisdas
Copy link
Contributor Author

nisdas commented Jan 28, 2019

@JustinDrake Hey vyperlang/vyper#1213 is merged in now are we waiting on #490, or is this good to be merged in ?

@JustinDrake
Copy link
Collaborator

@nisdas Shall we wait for the 0.1.0-beta.8 release? Also need to merge with #490

@nisdas
Copy link
Contributor Author

nisdas commented Jan 28, 2019

@JustinDrake Sounds good to me 👍

@@ -667,45 +666,48 @@ deposit_tree: map(uint256, bytes32)
deposit_count: uint256
full_deposit_count: uint256

@private
@constant
def to_bytes(value: uint256) -> bytes[8]:
Copy link
Contributor

Choose a reason for hiding this comment

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

to_bytes -> to_bytes8

@jacqueswww
Copy link

With regards to when beta8 will be released, I hope sometime next week, this will also include the bytes32 slice() fix, which one can then inline the to_bytes function at a much lower gas cost (I expect, still have to make the change).

@djrtwo
Copy link
Contributor

djrtwo commented Jan 31, 2019

@nisdas Can you sync this with the latest changes in master?

@nisdas
Copy link
Contributor Author

nisdas commented Jan 31, 2019

@djrtwo Alright, done

@djrtwo djrtwo changed the base branch from master to dev January 31, 2019 15:49
@nisdas
Copy link
Contributor Author

nisdas commented Feb 5, 2019

With #562 being merged in, this PR doesnt make sense now. So I am closing it

@nisdas nisdas closed this Feb 5, 2019
@nisdas nisdas deleted the depositContractFix branch February 5, 2019 08:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants