diff options
author | Karn Seth <karn@google.com> | 2023-09-25 16:18:43 -0400 |
---|---|---|
committer | Karn Seth <karn@google.com> | 2023-09-25 16:18:43 -0400 |
commit | 3dea51443eaabde75c00cd325bc31e3b848a767f (patch) | |
tree | 22502fb41773fc4aa5a688f7d38da93e3391359b | |
parent | 6263f3d94d1278ebea947fd855c3ccfb48b371f1 (diff) | |
download | anonymous-counting-tokens-3dea51443eaabde75c00cd325bc31e3b848a767f.tar.gz |
adds golden transcriptsupstream-main
-rw-r--r-- | WORKSPACE | 6 | ||||
-rw-r--r-- | act/act_v0/act_v0.cc | 25 | ||||
-rw-r--r-- | act/act_v0/testing/BUILD | 75 | ||||
-rw-r--r-- | act/act_v0/testing/generate_transcript.cc | 175 | ||||
-rw-r--r-- | act/act_v0/testing/golden_transcript_test.cc | 81 | ||||
-rw-r--r-- | act/act_v0/testing/transcript.proto | 34 | ||||
-rw-r--r-- | act/act_v0/testing/transcripts/golden_transcript_1_09122023 | bin | 0 -> 103186 bytes | |||
-rw-r--r-- | act/act_v0/testing/transcripts/golden_transcript_2_09122023 | bin | 0 -> 103202 bytes | |||
-rw-r--r-- | act/act_v0/testing/transcripts/golden_transcript_3_09122023 | bin | 0 -> 103197 bytes |
9 files changed, 374 insertions, 22 deletions
@@ -20,9 +20,9 @@ load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") # Private Join and Compute http_archive( name = "private_join_and_compute", - sha256 = "6026c6522b0119e48b697492d184ee60be97071344c2788095fcb2a489ad905f", - strip_prefix = "private-join-and-compute-e028e59420a9c36328705ed5064408de03d229a8", - urls = ["https://github.com/google/private-join-and-compute/archive/e028e59420a9c36328705ed5064408de03d229a8.zip"], + sha256 = "9304a6fe62c7227657e7cecf08c6234c14dfb558bd6a2fa778de845056fb9dd3", + strip_prefix = "private-join-and-compute-f77f26fab7f37e5e1e2d43250662c0281bd7fa4a", + urls = ["https://github.com/google/private-join-and-compute/archive/f77f26fab7f37e5e1e2d43250662c0281bd7fa4a.zip"], ) # loads boringssl, absl, googletest, protobuf. diff --git a/act/act_v0/act_v0.cc b/act/act_v0/act_v0.cc index 01921a5..228f0db 100644 --- a/act/act_v0/act_v0.cc +++ b/act/act_v0/act_v0.cc @@ -110,28 +110,15 @@ StatusOr<std::vector<BigNum>> GetNoncesForTokenRequest( challenge_sos.get()); challenge_cos->SetSerializationDeterministic(true); challenge_cos->WriteVarint64(scheme_parameters.ByteSizeLong()); - if (!scheme_parameters.SerializeToCodedStream(challenge_cos.get())) { - return absl::InternalError( - "GetNoncesForTokenRequest: Failed to serialize scheme_parameters."); - } + challenge_cos->WriteString(SerializeAsStringInOrder(scheme_parameters)); challenge_cos->WriteVarint64(server_public_parameters.ByteSizeLong()); - if (!server_public_parameters.SerializeToCodedStream(challenge_cos.get())) { - return absl::InternalError( - "GetNoncesForTokenRequest: Failed to serialize " - "server_public_parameters."); - } + challenge_cos->WriteString( + SerializeAsStringInOrder(server_public_parameters)); challenge_cos->WriteVarint64(client_public_parameters.ByteSizeLong()); - if (!client_public_parameters.SerializeToCodedStream(challenge_cos.get())) { - return absl::InternalError( - "GetNoncesForTokenRequest: Failed to serialize " - "client_public_parameters."); - } + challenge_cos->WriteString( + SerializeAsStringInOrder(client_public_parameters)); challenge_cos->WriteVarint64(tokens_request_part_1.ByteSizeLong()); - if (!tokens_request_part_1.SerializeToCodedStream(challenge_cos.get())) { - return absl::InternalError( - "GetNoncesForTokenRequest: Failed to serialize " - "client_public_parameters."); - } + challenge_cos->WriteString(SerializeAsStringInOrder(tokens_request_part_1)); challenge_cos->WriteVarint64(num_messages); // Delete the serialization objects to make sure they clean up and write. diff --git a/act/act_v0/testing/BUILD b/act/act_v0/testing/BUILD new file mode 100644 index 0000000..ccb192b --- /dev/null +++ b/act/act_v0/testing/BUILD @@ -0,0 +1,75 @@ +# Copyright 2023 Google LLC. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +load("@rules_cc//cc:defs.bzl", "cc_library") +load("@rules_proto//proto:defs.bzl", "proto_library") + +package(default_visibility = ["//visibility:public"]) + +proto_library( + name = "transcript_proto", + srcs = ["transcript.proto"], + deps = ["//act:act_proto"], +) + +cc_proto_library( + name = "transcript_cc_proto", + deps = [":transcript_proto"], +) + +cc_binary( + name = "generate_transcript", + srcs = ["generate_transcript.cc"], + deps = [ + ":transcript_cc_proto", + "//act", + "//act:act_cc_proto", + "//act/act_v0", + "//act/act_v0:act_v0_cc_proto", + "//act/act_v0:parameters", + "@com_google_absl//absl/flags:flag", + "@com_google_absl//absl/flags:parse", + "@com_google_absl//absl/log", + "@com_google_absl//absl/log:check", + "@com_google_absl//absl/strings", + "@private_join_and_compute//private_join_and_compute/util:proto_util", + "@private_join_and_compute//private_join_and_compute/util:status_includes", + ], +) + +filegroup( + name = "transcripts", + testonly = 1, + srcs = glob(["transcripts/*"]), +) + +cc_test( + name = "golden_transcript_test", + srcs = ["golden_transcript_test.cc"], + data = [ + ":transcripts", + ], + deps = [ + ":transcript_cc_proto", + "//act", + "//act:act_cc_proto", + "//act/act_v0", + "//act/act_v0:act_v0_cc_proto", + "//act/act_v0:parameters", + "@com_github_google_googletest//:gtest_main", + "@private_join_and_compute//private_join_and_compute/util:proto_util", + "@private_join_and_compute//private_join_and_compute/util:status_includes", + "@private_join_and_compute//private_join_and_compute/util:status_testing_includes", + ], +) diff --git a/act/act_v0/testing/generate_transcript.cc b/act/act_v0/testing/generate_transcript.cc new file mode 100644 index 0000000..915b960 --- /dev/null +++ b/act/act_v0/testing/generate_transcript.cc @@ -0,0 +1,175 @@ +/* + * Copyright 2023 Google LLC. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <cstddef> +#include <string> +#include <tuple> +#include <vector> + +#include "absl/flags/flag.h" +#include "absl/flags/parse.h" +#include "absl/log/check.h" +#include "absl/log/log.h" +#include "absl/strings/str_cat.h" +#include "absl/strings/string_view.h" +#include "act/act.h" +#include "act/act.pb.h" +#include "act/act_v0/act_v0.h" +#include "act/act_v0/act_v0.pb.h" +#include "act/act_v0/parameters.h" +#include "act/act_v0/testing/transcript.pb.h" +#include "private_join_and_compute/util/proto_util.h" +#include "private_join_and_compute/util/status.inc" + +ABSL_FLAG(std::string, transcript_path, "", + "Prefix of file to which the generated transcript will be " + "written/read from."); + +ABSL_FLAG(bool, verify, false, + "If true, will attempt to read the transcript from the specified " + "path to verify it."); + +namespace private_join_and_compute { +namespace anonymous_counting_tokens { +namespace { + +absl::Status GenerateTranscript(absl::string_view transcript_path) { + SchemeParameters scheme_parameters = + private_join_and_compute::anonymous_counting_tokens:: + ActV0SchemeParametersPedersen32Modulus2048CamenischShoupVector2(); + auto act = AnonymousCountingTokensV0::Create(); + + ASSIGN_OR_RETURN(ServerParameters server_parameters, + act->GenerateServerParameters(scheme_parameters)); + ASSIGN_OR_RETURN( + ClientParameters client_parameters, + act->GenerateClientParameters(scheme_parameters, + server_parameters.public_parameters())); + std::vector<std::string> messages; + size_t num_messages = + scheme_parameters.scheme_parameters_v0().pedersen_batch_size(); + messages.reserve(num_messages); + for (int i = 0; i < num_messages; ++i) { + messages.push_back(absl::StrCat("message", i)); + } + std::vector<std::string> client_fingerprints; + TokensRequest tokens_request; + TokensRequestPrivateState tokens_request_private_state; + ASSIGN_OR_RETURN( + std::tie(client_fingerprints, tokens_request, + tokens_request_private_state), + act->GenerateTokensRequest(messages, scheme_parameters, + client_parameters.public_parameters(), + client_parameters.private_parameters(), + server_parameters.public_parameters())); + + ASSIGN_OR_RETURN( + TokensResponse tokens_response, + act->GenerateTokensResponse(tokens_request, scheme_parameters, + client_parameters.public_parameters(), + server_parameters.public_parameters(), + server_parameters.private_parameters())); + + ASSIGN_OR_RETURN( + std::vector<Token> tokens, + act->RecoverTokens(messages, tokens_request, tokens_request_private_state, + tokens_response, scheme_parameters, + client_parameters.public_parameters(), + client_parameters.private_parameters(), + server_parameters.public_parameters())); + + Transcript transcript; + *transcript.mutable_scheme_parameters() = scheme_parameters; + *transcript.mutable_server_parameters() = server_parameters; + *transcript.mutable_client_parameters() = client_parameters; + *transcript.mutable_messages() = {messages.begin(), messages.end()}; + *transcript.mutable_fingerprints() = {client_fingerprints.begin(), + client_fingerprints.end()}; + *transcript.mutable_tokens_request() = tokens_request; + *transcript.mutable_tokens_request_private_state() = + tokens_request_private_state; + *transcript.mutable_tokens_response() = tokens_response; + *transcript.mutable_tokens() = {tokens.begin(), tokens.end()}; + + return ProtoUtils::WriteProtoToFile(transcript, transcript_path); +} + +absl::Status VerifyTranscript(absl::string_view transcript_path) { + ASSIGN_OR_RETURN(Transcript transcript, + ProtoUtils::ReadProtoFromFile<Transcript>(transcript_path)); + + auto act = AnonymousCountingTokensV0::Create(); + + if (!transcript.has_scheme_parameters() || + !transcript.scheme_parameters().has_scheme_parameters_v0() || + transcript.scheme_parameters() + .scheme_parameters_v0() + .pedersen_batch_size() <= 0) { + return InvalidArgumentError( + "VerifyTranscript: transcript should have a SchemeParametersV0 with a " + "positive pedersen_batch_size."); + } + + RETURN_IF_ERROR(act->CheckClientParameters( + transcript.scheme_parameters(), + transcript.client_parameters().public_parameters(), + transcript.server_parameters().public_parameters(), + transcript.server_parameters().private_parameters())); + + std::vector<std::string> client_fingerprints( + transcript.fingerprints().begin(), transcript.fingerprints().end()); + RETURN_IF_ERROR(act->CheckTokensRequest( + client_fingerprints, transcript.tokens_request(), + transcript.scheme_parameters(), + transcript.client_parameters().public_parameters(), + transcript.server_parameters().public_parameters(), + transcript.server_parameters().private_parameters())); + + std::vector<std::string> messages(transcript.messages().begin(), + transcript.messages().end()); + RETURN_IF_ERROR(act->VerifyTokensResponse( + messages, transcript.tokens_request(), + transcript.tokens_request_private_state(), transcript.tokens_response(), + transcript.scheme_parameters(), + transcript.client_parameters().public_parameters(), + transcript.client_parameters().private_parameters(), + transcript.server_parameters().public_parameters())); + + return OkStatus(); +} + +} // namespace +} // namespace anonymous_counting_tokens +} // namespace private_join_and_compute + +int main(int argc, char** argv) { + absl::ParseCommandLine(argc, argv); + std::string transcript_path = absl::GetFlag(FLAGS_transcript_path); + + bool verify = absl::GetFlag(FLAGS_verify); + if (verify) { + CHECK_OK( + private_join_and_compute::anonymous_counting_tokens::VerifyTranscript( + transcript_path)); + LOG(INFO) << "Successfully verified transcript."; + } else { + CHECK_OK( + private_join_and_compute::anonymous_counting_tokens::GenerateTranscript( + transcript_path)); + LOG(INFO) << "Successfully generated transcript."; + } + + return 0; +} diff --git a/act/act_v0/testing/golden_transcript_test.cc b/act/act_v0/testing/golden_transcript_test.cc new file mode 100644 index 0000000..df4efb0 --- /dev/null +++ b/act/act_v0/testing/golden_transcript_test.cc @@ -0,0 +1,81 @@ +/* + * Copyright 2023 Google LLC. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <gmock/gmock.h> +#include <gtest/gtest.h> + +#include <filesystem> +#include <memory> +#include <string> +#include <vector> + +#include "act/act.h" +#include "act/act.pb.h" +#include "act/act_v0/act_v0.h" +#include "act/act_v0/testing/transcript.pb.h" +#include "private_join_and_compute/util/proto_util.h" +#include "private_join_and_compute/util/status_testing.inc" + +namespace private_join_and_compute { +namespace anonymous_counting_tokens { +namespace { + +const char kTranscriptPathBase[] = "act/act_v0/testing/transcripts/"; + +TEST(GoldenTranscriptTest, TranscriptPassesValidityTests) { + auto act = AnonymousCountingTokensV0::Create(); + + std::vector<std::string> transcript_paths; + + for (const auto& entry : + std::filesystem::directory_iterator(kTranscriptPathBase)) { + transcript_paths.push_back(std::string(entry.path())); + } + + for (const auto& transcript_path : transcript_paths) { + ASSERT_OK_AND_ASSIGN( + Transcript transcript, + ProtoUtils::ReadProtoFromFile<Transcript>(transcript_path)); + + EXPECT_OK(act->CheckClientParameters( + transcript.scheme_parameters(), + transcript.client_parameters().public_parameters(), + transcript.server_parameters().public_parameters(), + transcript.server_parameters().private_parameters())); + + std::vector<std::string> client_fingerprints( + transcript.fingerprints().begin(), transcript.fingerprints().end()); + EXPECT_OK(act->CheckTokensRequest( + client_fingerprints, transcript.tokens_request(), + transcript.scheme_parameters(), + transcript.client_parameters().public_parameters(), + transcript.server_parameters().public_parameters(), + transcript.server_parameters().private_parameters())); + + std::vector<std::string> messages(transcript.messages().begin(), + transcript.messages().end()); + EXPECT_OK(act->VerifyTokensResponse( + messages, transcript.tokens_request(), + transcript.tokens_request_private_state(), transcript.tokens_response(), + transcript.scheme_parameters(), + transcript.client_parameters().public_parameters(), + transcript.client_parameters().private_parameters(), + transcript.server_parameters().public_parameters())); + } +} + +} // namespace +} // namespace anonymous_counting_tokens +} // namespace private_join_and_compute diff --git a/act/act_v0/testing/transcript.proto b/act/act_v0/testing/transcript.proto new file mode 100644 index 0000000..957335d --- /dev/null +++ b/act/act_v0/testing/transcript.proto @@ -0,0 +1,34 @@ +/* + * Copyright 2023 Google LLC. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +syntax = "proto3"; + +package private_join_and_compute.anonymous_counting_tokens; + +import "act/act.proto"; + +option java_multiple_files = true; + +message Transcript { + SchemeParameters scheme_parameters = 1; + ServerParameters server_parameters = 2; + ClientParameters client_parameters = 3; + repeated string messages = 4; + repeated bytes fingerprints = 5; + TokensRequest tokens_request = 6; + TokensRequestPrivateState tokens_request_private_state = 7; + TokensResponse tokens_response = 8; + repeated Token tokens = 9; +} diff --git a/act/act_v0/testing/transcripts/golden_transcript_1_09122023 b/act/act_v0/testing/transcripts/golden_transcript_1_09122023 Binary files differnew file mode 100644 index 0000000..8787824 --- /dev/null +++ b/act/act_v0/testing/transcripts/golden_transcript_1_09122023 diff --git a/act/act_v0/testing/transcripts/golden_transcript_2_09122023 b/act/act_v0/testing/transcripts/golden_transcript_2_09122023 Binary files differnew file mode 100644 index 0000000..5e99965 --- /dev/null +++ b/act/act_v0/testing/transcripts/golden_transcript_2_09122023 diff --git a/act/act_v0/testing/transcripts/golden_transcript_3_09122023 b/act/act_v0/testing/transcripts/golden_transcript_3_09122023 Binary files differnew file mode 100644 index 0000000..fcd1e82 --- /dev/null +++ b/act/act_v0/testing/transcripts/golden_transcript_3_09122023 |