Skip to content

Commit

Permalink
implementing aliases #20
Browse files Browse the repository at this point in the history
  • Loading branch information
Janis Erdmanis committed Apr 19, 2024
1 parent 75988d5 commit 7aec558
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
14 changes: 10 additions & 4 deletions src/Core/Model/audit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ function audit(ledger::BallotBoxLedger)
return true
end


function isbinding(chain::BraidChainLedger, bbox::BallotBoxLedger)

# records must be part of the chain
Expand All @@ -250,10 +249,17 @@ function isbinding(chain::BraidChainLedger, bbox::BallotBoxLedger)
braid_index = bbox.proposal.anchor.index
braid_receipt = chain[braid_index]::BraidReceipt

voters = Set(output_members(braid_receipt))

# voters = Set(output_members(braid_receipt))
# for record in bbox
# issuer(record) in voters || return false
# end

# Checking aliases. This also checks membership
members = output_members(braid_receipt)

for record in bbox
issuer(record) in voters || return false
1 <= record.alias <= length(members) || return false
members[record.alias] == issuer(record.vote) || return false
end

return true
Expand Down
14 changes: 13 additions & 1 deletion src/Core/Model/ballotbox.jl
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ that they had cast their vote without revealing the link to the vote.
"""
struct CastRecord
vote::Vote
alias::Int
timestamp::DateTime
end

Expand Down Expand Up @@ -386,6 +387,7 @@ and that could be a good thing!
"""
struct CastReceipt
vote::Digest
alias::Digest # H(alias|vote)
timestamp::DateTime
end

Expand All @@ -402,7 +404,17 @@ end
Construct a CastReceipt from a CastRecord with a provided hasher function.
"""
receipt(record::CastRecord, hasher::HashSpec) = CastReceipt(digest(record.vote, hasher), record.timestamp)
function receipt(record::CastRecord, hasher::HashSpec)

vote_hash = digest(record.vote, hasher)

vote_bytes = canonicalize(record.vote)
alias_bytes = reinterpret(UInt8, [UInt32(record.alias)])
alias_commit = digest(UInt8[alias_bytes..., vote_bytes...], hasher)

return CastReceipt(vote_hash, alias_commit, record.timestamp)
end

receipt(record::CastRecord, spec) = receipt(record, hasher(spec))


Expand Down
1 change: 1 addition & 0 deletions src/Core/ProtocolSchema.jl
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ revoting would be as hard as monitoring the submitted votes.
"""
struct CastAck
receipt::CastReceipt
alias::Int
ack::AckInclusion{BallotBoxState}
end

Expand Down
8 changes: 5 additions & 3 deletions src/Server/Controllers/ballotbox.jl
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,10 @@ Compute an acknowledgment for record inclusion at `index`.
function ack_cast(ballotbox::BallotBoxController, N::Int)

ack = ack_leaf(ballotbox, N)
_receipt = receipt(ballotbox, N)
record = ballotbox[N]
_receipt = receipt(record, ballotbox.ledger.spec)

return CastAck(_receipt, ack)
return CastAck(_receipt, record.alias, ack)
end

"""
Expand Down Expand Up @@ -375,8 +376,9 @@ function commit!(ballotbox::BallotBoxController, timestamp::DateTime, signer::Si

for vote in ballotbox.queue

alias = findindex(issuer(vote), ballotbox.voters)
# an ideal place to form a blind signature on the user's request.
record = CastRecord(vote, timestamp)
record = CastRecord(vote, alias, timestamp)
push!(ballotbox, record)

end
Expand Down

0 comments on commit 7aec558

Please sign in to comment.