diff --git a/yarn-project/circuits.js/src/barretenberg/crypto/ecdsa/index.ts b/yarn-project/circuits.js/src/barretenberg/crypto/ecdsa/index.ts index 1d7dd10f61b1..658448253860 100644 --- a/yarn-project/circuits.js/src/barretenberg/crypto/ecdsa/index.ts +++ b/yarn-project/circuits.js/src/barretenberg/crypto/ecdsa/index.ts @@ -1,9 +1,5 @@ -import { toBufferBE } from '@aztec/foundation/bigint-buffer'; -import { numToUInt32BE } from '@aztec/foundation/serialize'; import { IWasmModule } from '@aztec/foundation/wasm'; -import { secp256k1 } from '@noble/curves/secp256k1'; - import { CircuitsWasm, PrivateKey } from '../../../index.js'; import { Signer } from '../index.js'; import { EcdsaSignature } from './signature.js'; @@ -47,18 +43,10 @@ export class Ecdsa implements Signer { this.wasm.writeMemory(mem, msg); this.wasm.call('ecdsa__construct_signature', mem, msg.length, 0, 32, 64, 96); - // TODO(#913): Understand why this doesn't work - // const sig = new EcdsaSignature( - // Buffer.from(this.wasm.getMemorySlice(32, 64)), - // Buffer.from(this.wasm.getMemorySlice(64, 96)), - // Buffer.from(this.wasm.getMemorySlice(96, 97)), - // ); - - const signature = secp256k1.sign(msg, privateKey.value); return new EcdsaSignature( - toBufferBE(signature.r, 32), - toBufferBE(signature.s, 32), - numToUInt32BE(signature.recovery!).subarray(3, 4), + Buffer.from(this.wasm.getMemorySlice(32, 64)), + Buffer.from(this.wasm.getMemorySlice(64, 96)), + Buffer.from(this.wasm.getMemorySlice(96, 97)), ); } diff --git a/yarn-project/noir-contracts/src/contracts/ecdsa_account_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/ecdsa_account_contract/src/main.nr index d59ade37c2c1..67b1f3592851 100644 --- a/yarn-project/noir-contracts/src/contracts/ecdsa_account_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/ecdsa_account_contract/src/main.nr @@ -49,17 +49,13 @@ contract EcdsaAccount { let public_key = storage.public_key.get_note(&mut context); // Verify payload signature using Ethereum's signing scheme + // Note that noir expects the hash of the message/challenge as input to the ECDSA verification. let payload_bytes: [u8; entrypoint::ENTRYPOINT_PAYLOAD_SIZE_IN_BYTES] = payload.to_be_bytes(); let challenge: [u8; 32] = std::hash::sha256(payload_bytes); - let verification = std::ecdsa_secp256k1::verify_signature(public_key.x, public_key.y, signature, challenge); + let hashed_challenge: [u8; 32] = std::hash::sha256(challenge); + let verification = std::ecdsa_secp256k1::verify_signature(public_key.x, public_key.y, signature, hashed_challenge); assert(verification == true); - // debug_log::debug_log_format("Verification result is {0}", [verification as Field]); - // debug_log::debug_log_array_with_prefix("public_key.x", public_key.x); - // debug_log::debug_log_array_with_prefix("public_key.y", public_key.y); - // debug_log::debug_log_array_with_prefix("challenge", challenge); - // debug_log::debug_log_array_with_prefix("signature", signature); - payload.execute_calls(&mut context); context.finish()