Skip to main content

Preventing Voter Fraud

The vote/yesVotes and vote/noVotes predicates hold all of the auth records that voted for or against a proposed change.

We need to make sure that only the owner of a given auth record adds their auth record to yes or no votes.

To do this, we can add a spec to both of these predicates, which ensures that users only cast votes with their own auth records.

The transaction will look as follows:

[
{
"_id": "_fn$ownAuth",
"_fn/name": "ownAuth?",
"_fn/code": "SMART FUNCTION CODE HERE"
},
{
"_id": ["_predicate/name", "vote/yesVotes"],
"spec": ["_fn$ownAuth"]
},
{
"_id": ["_predicate/name", "vote/noVotes"],
"spec": ["_fn$ownAuth"]
}
]

It is your job to write the code of the smart function. Remember, we want to check whether the _auth we add to vote/yesVotes or vote/noVotes is your own _auth.

You will need one (or several) of these smart function to write, ownAuth?.

FunctionArgumentsExample
incn optional(inc)
decn optional(dec)
==arg1 arg2 ...(== 1 1 1 1)
+arg1 arg2 ...(+ 1 2 3)
-arg1 arg2 ...(- 10 9 3)
*arg1 arg2 ...(* 90 10 2)
/arg1 arg2 ...(/ 36 3 4)
>arg1 arg2 ...(> 90 10 2)
<arg1 arg2 ...(< 90 10 2)
>=arg1 arg2 ...(>= 90 90 10 2)
<arg1 arg2 ...(< 2 10 90)
<=arg1 arg2 ...(<= 2 10 90 90)
maxarg1 arg2 ...(max 1 2 3)
minarg1 arg2 ...(min 1 2 3)


You will also need several context-specific functions. Note, you may not need all of these functions:

  • (?sid): The _id for the subject being updated.
  • (?auth_id) : The _id of the auth making the update.
  • (?user_id) : The _id of the user making the update.
  • (?o): Tthe object (value) of the predicate that is being edited.

Write the Smart Function!

Using the above instructions, write the smart function code for ownAuth