Skip to content
This repository has been archived by the owner on Mar 30, 2022. It is now read-only.

optimization suggestions for Will_v1.sol #1

Open
cylobi opened this issue Nov 10, 2021 · 1 comment
Open

optimization suggestions for Will_v1.sol #1

cylobi opened this issue Nov 10, 2021 · 1 comment

Comments

@cylobi
Copy link

cylobi commented Nov 10, 2021

Hey There
I found some ways of optimization for your code that I thought I could share with you.
No looping is ever needed for this contract:
- For deleting an heir part you could set their weight to zero and then swap the indexes of deleted heir with last heir in heirAddress[] and then decrementing length of array
- For calculating total weight count you could have defined an integer that kept the sum of weights and changed it's value with addHeir() changeHeirWeight() and removeHeir() functions

Also I'm not sure about this one but I think the division of heirs[getHeirsAddress(i)] / total will result in integer instead of floating point and I don't think that is what you want.

Apart from these there is possible re-entracy attack opportunity in your code. I advise you to replace claim with a new function that each person could withdraw they're share and then before you transfer the amount ,set their weight to 0.

@JGcarv
Copy link
Owner

JGcarv commented Nov 11, 2021

Hey! Thanks for taking the time to review my code. This was done purely as a learning project and quite a while ago, so I'm sure it's full of issues and vulnerabilities.

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

No branches or pull requests

2 participants