Skip to content

Commit

Permalink
Upgrade pyodide to 0.17
Browse files Browse the repository at this point in the history
  • Loading branch information
txus committed Apr 23, 2021
1 parent 58e0df7 commit a5bdd0f
Show file tree
Hide file tree
Showing 31 changed files with 298 additions and 284 deletions.
27 changes: 24 additions & 3 deletions .code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
"name": "Bulletin Board Gem",
"path": "bulletin_board/ruby-client"
},
{
"name": "Bulletin Board JS Client",
"path": "bulletin_board/js-client"
},
{
"name": "Documentation",
"path": "docs"
Expand All @@ -20,13 +24,30 @@
"name": "Dummy JS Adapter",
"path": "voting_schemes/dummy/js-adapter"
},
{
"name": "ElectionGuard Wrapper",
"path": "voting_schemes/electionguard/python-wrapper"
},
{
"name": "ElectionGuard JS Adapter",
"path": "voting_schemes/electionguard/js-adapter"
},
{
"name": "ElectionGuard Wrapper",
"path": "voting_schemes/electionguard/python-wrapper"
"name": "ElectionGuard Ruby Adapter",
"path": "voting_schemes/electionguard/ruby-adapter"
},
{
"name": "ElectionGuard Python2JS",
"path": "voting_schemes/electionguard/python-to-js"
},
{
"name": "ElectionGuard Pyodide Base Packages",
"path": "voting_schemes/electionguard/pyodide-base-packages"
},
{
"name": "ElectionGuard Pyodide Verifier",
"path": "voting_schemes/electionguard/verifier"
}
]
],
"settings": {}
}
4 changes: 2 additions & 2 deletions Dockerfile.release
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ ADD voting_schemes/electionguard/python-wrapper /code/voting_schemes/electiongua
RUN cd /code && make build_electionguard_python_wrapper

# This stage builds the pyodide packages for the previous python packages
FROM codegram/electionguard-pyodide-base-packages:0.0.1 as python-to-js-builder
FROM codegram/electionguard-pyodide-base-packages:0.0.3 as python-to-js-builder
LABEL author="[email protected]"

ENV PYODIDE_PACKAGES "electionguard,bulletin_board-electionguard"
Expand Down Expand Up @@ -86,4 +86,4 @@ RUN npm install --global yarn
RUN bundle exec rake assets:precompile

# Migrate and seed database
CMD ["bundle", "exec", "rake", "db:migrate"]
CMD ["bundle", "exec", "rake", "db:migrate"]
4 changes: 2 additions & 2 deletions Dockerfile.web
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ ADD voting_schemes/electionguard/python-wrapper /code/voting_schemes/electiongua
RUN cd /code && make build_electionguard_python_wrapper

# This stage builds the pyodide packages for the previous python packages
FROM codegram/electionguard-pyodide-base-packages:0.0.1 as python-to-js-builder
FROM codegram/electionguard-pyodide-base-packages:0.0.3 as python-to-js-builder
LABEL author="[email protected]"

ENV PYODIDE_PACKAGES "electionguard,bulletin_board-electionguard"
Expand Down Expand Up @@ -87,4 +87,4 @@ RUN bundle exec rake assets:precompile

# Run the entrypoint script
COPY ./docker-entrypoint.sh /
ENTRYPOINT ["/docker-entrypoint.sh"]
ENTRYPOINT ["/docker-entrypoint.sh"]
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export class KeyCeremonyComponent extends TrusteeComponent {
onBindBackupButton,
onBackupStarted,
}) {
const onSetupDone = this.trustee.setup();
const onSetupDone = await this.trustee.setup();

this.trustee.events.subscribe(onEvent);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ $(() => {

if (votingSchemeName === "dummy") {
trusteeWrapperAdapter = new DummyTrusteeWrapperAdapter({
trusteeId: trusteeContext.uniqueId,
trusteeId: trusteeContext.uniqueId
});
} else if (votingSchemeName === "electionguard") {
trusteeWrapperAdapter = new ElectionGuardTrusteeWrapperAdapter({
trusteeId: trusteeContext.uniqueId,
workerUrl: "/assets/electionguard/webworker.js",
workerUrl: "/assets/electionguard/webworker.js"
});
} else {
throw new Error(`Voting scheme ${votingSchemeName} not supported.`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ $(() => {
} else if (votingSchemeName === "electionguard") {
trusteeWrapperAdapter = new ElectionGuardTrusteeWrapperAdapter({
trusteeId: trusteeContext.uniqueId,
workerUrl: "/assets/electionguard/webworker.js",
workerUrl: "/assets/electionguard/webworker.js"
});
} else {
throw new Error(`Voting scheme ${votingSchemeName} not supported.`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ $(() => {
} else if (votingSchemeName === "electionguard") {
voterWrapperAdapter = new ElectionGuardVoterWrapperAdapter({
voterId: voterUniqueId,
workerUrl: "/assets/electionguard/webworker.js",
workerUrl: "/assets/electionguard/webworker.js"
});
} else {
throw new Error(`Voting scheme ${votingSchemeName} not supported.`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@
</div>
</section>

<%= javascript_include_tag "sandbox/key_ceremony" %>
<%= javascript_include_tag "sandbox/key_ceremony" %>
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@
</div>
</section>

<%= javascript_include_tag "sandbox/tally" %>
<%= javascript_include_tag "sandbox/tally" %>
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@
</form>
</section>

<%= javascript_include_tag "sandbox/vote" %>
<%= javascript_include_tag "sandbox/vote" %>
42 changes: 21 additions & 21 deletions bulletin_board/server/db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,32 +111,32 @@ def create_publish_results_log_entry(election)
)
end

TEST_ELECTION_ID_OFFSET = 10_000
[:created, :key_ceremony, :key_ceremony_ended, :vote, :vote_ended, :tally, :tally_ended, :results_published].each_with_index do |status, i|
election = FactoryBot.create(:election, status, election_id: TEST_ELECTION_ID_OFFSET + i)
# TEST_ELECTION_ID_OFFSET = 10_000
# [:created, :key_ceremony, :key_ceremony_ended, :vote, :vote_ended, :tally, :tally_ended, :results_published].each_with_index do |status, i|
# election = FactoryBot.create(:election, status, election_id: TEST_ELECTION_ID_OFFSET + i)

next if status == :created
# next if status == :created

create_start_key_ceremony_log_entry(election)
next if status == :key_ceremony
# create_start_key_ceremony_log_entry(election)
# next if status == :key_ceremony

create_key_ceremony_log_entries(election)
create_end_key_ceremony_log_entry(election)
next if status == :key_ceremony_ended
# create_key_ceremony_log_entries(election)
# create_end_key_ceremony_log_entry(election)
# next if status == :key_ceremony_ended

create_start_vote_log_entry(election)
next if status == :vote
# create_start_vote_log_entry(election)
# next if status == :vote

create_vote_log_entries(election)
create_end_vote_log_entry(election)
next if status == :vote_ended
# create_vote_log_entries(election)
# create_end_vote_log_entry(election)
# next if status == :vote_ended

create_start_tally_log_entries(election)
next if status == :tally
# create_start_tally_log_entries(election)
# next if status == :tally

create_tally_log_entries(election)
create_end_tally_log_entry(election)
next if status == :tally_ended
# create_tally_log_entries(election)
# create_end_tally_log_entry(election)
# next if status == :tally_ended

create_publish_results_log_entry(election)
end
# create_publish_results_log_entry(election)
# end
1 change: 1 addition & 0 deletions verifier/test/fixtures/electionguard/ballot-ok.txt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ export class TrusteeWrapperAdapter extends WrapperAdapter {
super();

this.trusteeId = trusteeId;
this.worker = new Worker(workerUrl);
this.worker = new Worker(workerUrl)
}

/**
* Setup the trustee wrapper.
*
* @returns {Promise<undefined>}
*/
setup() {
return this.processPythonCodeOnWorker(
async setup() {
return await this.processPythonCode(
`
from js import trustee_id
from bulletin_board.electionguard.trustee import Trustee
Expand All @@ -47,11 +47,14 @@ export class TrusteeWrapperAdapter extends WrapperAdapter {
* @returns {Promise<Object|undefined>}
*/
async processMessage(messageType, decodedData) {
const result = await this.processPythonCodeOnWorker(
const result = await this.processPythonCode(
`
import json
from js import message_type, decoded_data
trustee.process_message(message_type, json.loads(decoded_data))
import json
trustee.process_message(
message_type,
json.loads(decoded_data)
)
`,
{
message_type: messageType,
Expand All @@ -75,7 +78,7 @@ export class TrusteeWrapperAdapter extends WrapperAdapter {
* @returns {Promise<Boolean>}
*/
isFresh() {
return this.processPythonCodeOnWorker(
return this.processPythonCode(
`
trustee.is_fresh()
`
Expand All @@ -88,7 +91,7 @@ export class TrusteeWrapperAdapter extends WrapperAdapter {
* @returns {Promise<String>}
*/
backup() {
return this.processPythonCodeOnWorker(
return this.processPythonCode(
`
trustee.backup().hex()
`
Expand All @@ -102,10 +105,9 @@ export class TrusteeWrapperAdapter extends WrapperAdapter {
* @returns {Promise<Boolean>}
*/
restore(state) {
return this.processPythonCodeOnWorker(
return this.processPythonCode(
`
from js import state
trustee = Trustee.restore(bytes.fromhex(state))
True
`,
Expand All @@ -121,7 +123,7 @@ export class TrusteeWrapperAdapter extends WrapperAdapter {
* @returns {Promise<Boolean>}
*/
isKeyCeremonyDone() {
return this.processPythonCodeOnWorker(
return this.processPythonCode(
`
trustee.is_key_ceremony_done()
`
Expand All @@ -134,7 +136,7 @@ export class TrusteeWrapperAdapter extends WrapperAdapter {
* @returns {Promise<Boolean>}
*/
isTallyDone() {
return this.processPythonCodeOnWorker(
return this.processPythonCode(
`
trustee.is_tally_done()
`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ export class VoterWrapperAdapter extends WrapperAdapter {
super();

this.voterId = voterId;
this.worker = new Worker(workerUrl);
this.worker = new Worker(workerUrl)
}

/**
* Setup the voter wrapper.
*
* @returns {Promise<undefined>}
*/
setup() {
return this.processPythonCodeOnWorker(
async setup() {
return await this.processPythonCode(
`
from js import voter_id
from bulletin_board.electionguard.voter import Voter
Expand All @@ -47,10 +47,10 @@ export class VoterWrapperAdapter extends WrapperAdapter {
* @returns {Promise<Object|undefined>}
*/
async processMessage(messageType, decodedData) {
const result = await this.processPythonCodeOnWorker(
const result = await this.processPythonCode(
`
import json
from js import message_type, decoded_data
import json
voter.process_message(message_type, json.loads(decoded_data))
`,
{
Expand All @@ -64,7 +64,7 @@ export class VoterWrapperAdapter extends WrapperAdapter {
const { message_type, content } = result[0];
return {
messageType: message_type,
content,
content: content.toJs(),
};
}
}
Expand All @@ -80,10 +80,10 @@ export class VoterWrapperAdapter extends WrapperAdapter {
* @returns {Promise<Object|undefined>}
*/
async encrypt(plainVote, ballotStyle) {
const [auditableData, encryptedData] = await this.processPythonCodeOnWorker(
const [auditableData, encryptedData] = await this.processPythonCode(
`
from js import plain_vote, ballot_style
voter.encrypt(plain_vote, ballot_style)
voter.encrypt(plain_vote.to_py(), ballot_style)
`,
{
plain_vote: plainVote,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
*/
export class WrapperAdapter {
/**
* Runs an arbitrary python code in the web worker.
* Runs arbitrary python code
*
* @param {String} pythonCode - A string representing valid python code.
* @param {Object} pythonData - An Object which values can be referenced from
* the python code using the js module.
* @private
* @returns {Promise<Object>}
*/
processPythonCodeOnWorker(pythonCode, pythonData) {
async processPythonCode(pythonCode, pythonData) {
return new Promise((resolve, reject) => {
this.worker.onmessage = (event) => {
resolve(event.data.results);
Expand Down
6 changes: 4 additions & 2 deletions voting_schemes/electionguard/pyodide-base-packages/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
FROM iodide/pyodide:0.16.1
FROM codegram/pyodide:latest
LABEL author="[email protected]"

ENV PYODIDE_PACKAGES "pyasn1,libgmp,gmpy2,micropip,attrs,sortedcontainers,hypothesis,jsons,typish,rsa"

RUN apt-get update && apt-get install -y m4

# Add base packages meta files
ADD packages /packages

Expand All @@ -12,4 +14,4 @@ RUN cp -rf /packages/* /src/pyodide/packages
WORKDIR /src/pyodide

# Compile base packages
RUN make
RUN make
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ source:
patches:
- patches/disable_mpc_mpfr.patch
build:
skip_host: False
ldflags: |
-L../../../libgmp/gmp-6.2.1/.libs
cflags: |
-I../../../libgmp/gmp-6.2.1
skip_host: True
ldflags: -L/src/pyodide/packages/libgmp/build/gmp-6.2.1/.libs
cflags: -I/src/pyodide/packages/libgmp/build/gmp-6.2.1
test:
imports:
- gmpy2
Expand Down
Loading

0 comments on commit a5bdd0f

Please sign in to comment.