Question about Registry.sol code


#1

I am wondering about some code in the Registry.sol smart contract:

// Maps number of applications per address
mapping(address => uint) public numApplications;

// Maps total amount staked per address
mapping(address => uint) public totalStaked;

I am wondering why totalStaked is added to, but never subtracted from, when listing are deleted. What is the intent of this? Is it just to measure how much has been staked, cumulatively, without accounting for stake decreasing?

Also, I am curious if numApplications works the same way (only counting increases).

Thanks,

Dave


#2

Hi @dkaj thanks for your question. The reason for this logic in Registry.sol is a limitation of the Token Controller contract which enforces Proof of Use, a requirement of the FOAM token sale. The Token Controller queries the registry to see if an account has added the minimum number of points. This works cumulativley because if a user had one of their points challenged and removed they would fall back behind the Proof of Use requirements and need to pass the Token Controller again. You can see the Token Controller here:
https://etherscan.io/address/0x5b9691fc4b0ee89546b15a13a6e7eea38700ba1d#readContract

Audit: https://github.com/f-o-a-m/public-research/blob/master/foam-controller-audit-report-2018-08-24-master.pdf

numApplications works the same way, but for a different reason. Even if your point is rejected as invalid it is still a valid candidate that has applied, so numApplications should only increase in count.


#3

Awesome, that makes a lot of sense.

I am also wondering about the doubly linked list and votes. From what I understand, the DLL sorts all the polls that a user has participated in.

But I don’t understand what the function rescueTokens() is doing. Overall I think this is because I am confused by how the voting works.

Lets say I deposit 100,000 tokens for voting:

  • Can my voting balance ever go down when I vote for a losing proposal? Or do I only lose stake, which I have staked in the registry?
  • I have 100,000 tokens for voting, but it isn’t clear to me if that is 100,000 spread across all polls I am voting in, or if I can allocate 100,000 votes to any poll. I don’t see incrementing and decrementing of the vote balance when entering a poll, or when rescuing a token, so that is what I am confused. (I would guess that tokens do get locked up, but I just don’t understand how the store and the DLL ensure that this is the case).

Any help would be much appreciated in understand this! Thanks :slight_smile:


#4

To start there is a difference between tokens approved for the Voting Registry and Voting credits.

You can approve as many tokens as you would like to the Registry, for example 1,000,000 even if you have much less tokens than that. This is just telling the registry you approve up to that amount of tokens to be deposited to the Voting contract.
https://mapguide.foam.space/voting/what-is-voting-credit

Voting Credit are your FOAM tokens currently located in the voting smart contract.

  • When you submit a vote, your tokens are transferred to the voting contract and become Voting Credit.
  • Voting Credit is not displayed in your balance of FOAM tokens in MetaMask. You must withdraw unlocked Voting Credit to have access to it there.
  • In the Voting tab of My Assets, you can approve voting tokens in advance to streamline the process.
  • You can use the same Voting Credit to vote in multiple challenges at the same time.

Voting Credit has 2 states: locked and unlocked. In My Assets under the Voting tab, Total Voting Credit shows your combined balance of unlocked and locked Voting Credit.

  • Unlocked Voting Credit is Voting Credit available to be withdrawn from the voting smart contract back into your Ethereum wallet connected to MetaMask. Go to the Voting tab of My Assets to withdraw unlocked Voting Credit.
  • Locked Voting Credit is Voting Credit currently being used in a challenge. You can always use locked Voting Credit in as many challenges as you like. But you won’t be able to return locked Voting Credit to your MetaMask wallet until all active challenges have completed and it has been unlocked.

There are 2 ways to unlock Voting Credit:

  1. Reveal your vote during the vote reveal period to unlock it automatically after the challenge completes.
  2. Visit the Voting tab of My Assets. At the bottom, you can see your votes never revealed during the vote reveal period. Click the button at the bottom to unlock all eligible Voting Credit.

NOTE: You can only submit a vote as long as the amount is within your combined balance of Total Voting Credit and Approved Registry Tokens.

All of this utilizes the Partial Lock Commit Reveal Voting (PLCR) process.

It is definitely not straightforward, and certainly confusing re: using the same tokens across multiple polls. Let me know if this answers your questions.


#5

These two references are perfect! They describe exactly what I was trying to understand. Thank you!