diff --git a/src/aztec/crypto/schnorr/c_bind.cpp b/src/aztec/crypto/schnorr/c_bind.cpp index b91140ffd98..329c91d883a 100644 --- a/src/aztec/crypto/schnorr/c_bind.cpp +++ b/src/aztec/crypto/schnorr/c_bind.cpp @@ -14,6 +14,14 @@ WASM_EXPORT void compute_public_key(uint8_t const* private_key, uint8_t* public_ write(public_key_buf, pub_key); } +WASM_EXPORT void negate_public_key(uint8_t const* public_key_buffer, uint8_t* output) +{ + // Negate the public key (effectively negating the y-coordinate of the public key) and return the resulting public + // key. + auto account_public_key = from_buffer(public_key_buffer); + barretenberg::group_elements::write(output, -account_public_key); +} + WASM_EXPORT void construct_signature( uint8_t const* message, size_t msg_len, uint8_t const* private_key, uint8_t* s, uint8_t* e) { @@ -129,4 +137,4 @@ WASM_EXPORT bool multisig_combine_signatures(uint8_t const* message, return false; } } -} \ No newline at end of file +} diff --git a/src/aztec/ecc/curves/secp256k1/secp256k1.test.cpp b/src/aztec/ecc/curves/secp256k1/secp256k1.test.cpp index 6397bc3557c..98b8c391967 100644 --- a/src/aztec/ecc/curves/secp256k1/secp256k1.test.cpp +++ b/src/aztec/ecc/curves/secp256k1/secp256k1.test.cpp @@ -508,9 +508,9 @@ TEST(secp256k1, neg_and_self_neg_0_cmp_regression) TEST(secp256k1, montgomery_mul_big_bug) { - secp256k1::fq a(uint256_t{0xfffffffe630dc02f, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}); + secp256k1::fq a(uint256_t{ 0xfffffffe630dc02f, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff }); secp256k1::fq a_sqr = a.sqr(); - secp256k1::fq expected(uint256_t{0x60381e557e100000, 0x0, 0x0, 0x0}); + secp256k1::fq expected(uint256_t{ 0x60381e557e100000, 0x0, 0x0, 0x0 }); EXPECT_EQ((a_sqr == expected), true); } diff --git a/src/aztec/ecc/curves/secp256r1/secp256r1.test.cpp b/src/aztec/ecc/curves/secp256r1/secp256r1.test.cpp index af0ff4ba629..17f5f3f89d7 100644 --- a/src/aztec/ecc/curves/secp256r1/secp256r1.test.cpp +++ b/src/aztec/ecc/curves/secp256r1/secp256r1.test.cpp @@ -476,7 +476,7 @@ TEST(secp256r1, montgomery_mul_big_bug) a.data[2] = 0xAAAAAAAAAAAAAAAA; a.data[3] = 0xFFFFFFFFE38E38E3; secp256r1::fr a_sqr = a.sqr(); - secp256r1::fr expected(uint256_t{0x57abc6aa0349c084, 0x65b21b232a4cb7a5, 0x5ba781948b0fcd6e, 0xd6e9e0644bda12f7}); + secp256r1::fr expected(uint256_t{ 0x57abc6aa0349c084, 0x65b21b232a4cb7a5, 0x5ba781948b0fcd6e, 0xd6e9e0644bda12f7 }); EXPECT_EQ((a_sqr == expected), true); } diff --git a/src/aztec/rollup/proofs/account/account_tx.cpp b/src/aztec/rollup/proofs/account/account_tx.cpp index e40ce058cc5..1d419305cdd 100644 --- a/src/aztec/rollup/proofs/account/account_tx.cpp +++ b/src/aztec/rollup/proofs/account/account_tx.cpp @@ -42,56 +42,6 @@ void account_tx::sign(key_pair const& keys) std::string(message.begin(), message.end()), keys); } -void write(std::vector& buf, account_tx const& tx) -{ - using serialize::write; - write(buf, tx.merkle_root); - write(buf, tx.account_public_key); - write(buf, tx.new_account_public_key); - write(buf, tx.new_signing_pub_key_1); - write(buf, tx.new_signing_pub_key_2); - write(buf, tx.alias_hash); - write(buf, tx.create); - write(buf, tx.migrate); - write(buf, tx.account_note_index); - write(buf, tx.account_note_path); - write(buf, tx.signing_pub_key); - write(buf, tx.signature); -} - -void read(uint8_t const*& buf, account_tx& tx) -{ - using serialize::read; - read(buf, tx.merkle_root); - read(buf, tx.account_public_key); - read(buf, tx.new_account_public_key); - read(buf, tx.new_signing_pub_key_1); - read(buf, tx.new_signing_pub_key_2); - read(buf, tx.alias_hash); - read(buf, tx.create); - read(buf, tx.migrate); - read(buf, tx.account_note_index); - read(buf, tx.account_note_path); - read(buf, tx.signing_pub_key); - read(buf, tx.signature); -} - -std::ostream& operator<<(std::ostream& os, account_tx const& tx) -{ - return os << "merkle_root: " << tx.merkle_root << "\n" - << "account_public_key: " << tx.account_public_key << "\n" - << "new_account_public_key: " << tx.new_account_public_key << "\n" - << "new_signing_pub_key_1: " << tx.new_signing_pub_key_1 << "\n" - << "new_signing_pub_key_2: " << tx.new_signing_pub_key_2 << "\n" - << "alias_hash: " << tx.alias_hash << "\n" - << "create: " << tx.create << "\n" - << "migrate: " << tx.migrate << "\n" - << "account_note_index: " << tx.account_note_index << "\n" - << "account_note_path: " << tx.account_note_path << "\n" - << "signing_pub_key: " << tx.signing_pub_key << "\n" - << "signature: " << tx.signature << "\n"; -} - } // namespace account } // namespace proofs } // namespace rollup diff --git a/src/aztec/rollup/proofs/account/account_tx.hpp b/src/aztec/rollup/proofs/account/account_tx.hpp index bd9d89ed104..4c9dbbc0970 100644 --- a/src/aztec/rollup/proofs/account/account_tx.hpp +++ b/src/aztec/rollup/proofs/account/account_tx.hpp @@ -32,10 +32,57 @@ struct account_tx { bool operator==(account_tx const&) const = default; }; -void read(uint8_t const*& it, account_tx& tx); -void write(std::vector& buf, account_tx const& tx); +template inline void read(B& buf, account_tx& tx) +{ + using serialize::read; + read(buf, tx.merkle_root); + read(buf, tx.account_public_key); + read(buf, tx.new_account_public_key); + read(buf, tx.new_signing_pub_key_1); + read(buf, tx.new_signing_pub_key_2); + read(buf, tx.alias_hash); + read(buf, tx.create); + read(buf, tx.migrate); + read(buf, tx.account_note_index); + read(buf, tx.account_note_path); + read(buf, tx.signing_pub_key); + read(buf, tx.signature.s); + read(buf, tx.signature.e); +} -std::ostream& operator<<(std::ostream& os, account_tx const& tx); +template inline void write(B& buf, account_tx const& tx) +{ + using serialize::write; + write(buf, tx.merkle_root); + write(buf, tx.account_public_key); + write(buf, tx.new_account_public_key); + write(buf, tx.new_signing_pub_key_1); + write(buf, tx.new_signing_pub_key_2); + write(buf, tx.alias_hash); + write(buf, tx.create); + write(buf, tx.migrate); + write(buf, tx.account_note_index); + write(buf, tx.account_note_path); + write(buf, tx.signing_pub_key); + write(buf, tx.signature.s); + write(buf, tx.signature.e); +} + +inline std::ostream& operator<<(std::ostream& os, account_tx const& tx) +{ + return os << "merkle_root: " << tx.merkle_root << "\n" + << "account_public_key: " << tx.account_public_key << "\n" + << "new_account_public_key: " << tx.new_account_public_key << "\n" + << "new_signing_pub_key_1: " << tx.new_signing_pub_key_1 << "\n" + << "new_signing_pub_key_2: " << tx.new_signing_pub_key_2 << "\n" + << "alias_hash: " << tx.alias_hash << "\n" + << "create: " << tx.create << "\n" + << "migrate: " << tx.migrate << "\n" + << "account_note_index: " << tx.account_note_index << "\n" + << "account_note_path: " << tx.account_note_path << "\n" + << "signing_pub_key: " << tx.signing_pub_key << "\n" + << "signature: " << tx.signature << "\n"; +} } // namespace account } // namespace proofs diff --git a/src/aztec/rollup/proofs/account/index.hpp b/src/aztec/rollup/proofs/account/index.hpp index 5e90cebf9ad..de4fd6623fe 100644 --- a/src/aztec/rollup/proofs/account/index.hpp +++ b/src/aztec/rollup/proofs/account/index.hpp @@ -4,4 +4,5 @@ #include "account.hpp" #include "c_bind.h" #include "compute_circuit_data.hpp" -#include "create_proof.hpp" \ No newline at end of file +#include "create_proof.hpp" +#include "verify.hpp" diff --git a/src/aztec/rollup/proofs/account/verify.cpp b/src/aztec/rollup/proofs/account/verify.cpp new file mode 100644 index 00000000000..8dfe759211a --- /dev/null +++ b/src/aztec/rollup/proofs/account/verify.cpp @@ -0,0 +1,32 @@ +#include "./verify.hpp" +#include "./account.hpp" +#include "./account_tx.hpp" + +namespace rollup { +namespace proofs { +namespace account { + +namespace { +verify_result build_circuit(Composer& composer, account_tx& tx, circuit_data const&) +{ + verify_result result; + account_circuit(composer, tx); + return result; +} +} // namespace + +verify_result verify_logic(account_tx& tx, circuit_data const& cd) +{ + Composer composer = Composer(cd.proving_key, cd.verification_key, cd.num_gates); + return verify_logic_internal(composer, tx, cd, "account", build_circuit); +} + +verify_result verify(account_tx& tx, circuit_data const& cd) +{ + Composer composer = Composer(cd.proving_key, cd.verification_key, cd.num_gates); + return verify_internal(composer, tx, cd, "account", true, build_circuit); +} + +} // namespace account +} // namespace proofs +} // namespace rollup diff --git a/src/aztec/rollup/proofs/account/verify.hpp b/src/aztec/rollup/proofs/account/verify.hpp new file mode 100644 index 00000000000..ba469c480ef --- /dev/null +++ b/src/aztec/rollup/proofs/account/verify.hpp @@ -0,0 +1,19 @@ +#pragma once +#include "../verify.hpp" +#include "./compute_circuit_data.hpp" +#include "./account.hpp" +#include + +namespace rollup { +namespace proofs { +namespace account { + +using namespace plonk::stdlib::types::turbo; + +verify_result verify_logic(account_tx& tx, circuit_data const& cd); + +verify_result verify(account_tx& tx, circuit_data const& cd); + +} // namespace account +} // namespace proofs +} // namespace rollup diff --git a/src/aztec/rollup/rollup_cli/main.cpp b/src/aztec/rollup/rollup_cli/main.cpp index d148243af61..b5d79ba69a6 100644 --- a/src/aztec/rollup/rollup_cli/main.cpp +++ b/src/aztec/rollup/rollup_cli/main.cpp @@ -6,6 +6,7 @@ #include #include "../proofs/account/compute_circuit_data.hpp" +#include "../proofs/account/verify.hpp" #include "../proofs/join_split/compute_circuit_data.hpp" #include "../proofs/claim/get_circuit_data.hpp" #include "../proofs/claim/verify.hpp" @@ -183,6 +184,21 @@ bool create_root_verifier() return result.verified; } +bool create_account_proof() +{ + account::account_tx account_tx; + std::cerr << "Reading account tx..." << std::endl; + read(std::cin, account_tx); + + auto result = verify(account_tx, account_cd); + + write(std::cout, result.proof_data); + write(std::cout, result.verified); + std::cout << std::flush; + + return result.verified; +} + int main(int argc, char** argv) { std::vector args(argv, argv + argc); @@ -257,6 +273,11 @@ int main(int argc, char** argv) create_root_verifier(); break; } + case 4: { + std::cerr << "Serving request to create account proof..." << std::endl; + create_account_proof(); + break; + } case 100: { // Convert to buffer first, so when we call write we prefix the buffer length. std::cerr << "Serving join split vk..." << std::endl; @@ -282,4 +303,4 @@ int main(int argc, char** argv) } return 0; -} \ No newline at end of file +}