Skip to content

Commit

Permalink
wrong signature
Browse files Browse the repository at this point in the history
  • Loading branch information
gaetbout committed Jun 28, 2024
1 parent 4d5b22f commit b44de8d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/signers/legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,9 @@ export class LongSigner extends LegacyStarknetKeyPair {
return ["", ...(await super.signRaw(messageHash))];
}
}

export class WrongSigner extends LegacyStarknetKeyPair {
public async signRaw(messageHash: string): Promise<string[]> {
return ["", ""];
}
}
1 change: 0 additions & 1 deletion src/contracts/escrow_account.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ mod EscrowAccount {
assert(signature.len() == 2, 'escrow/invalid-signature-len');

let tx_version = tx_info.version;
// Not tested
assert(
check_ecdsa_signature(execution_hash, gift.gift_pubkey, *signature[0], *signature[1])
|| tx_version == TX_V3_ESTIMATE
Expand Down
19 changes: 19 additions & 0 deletions tests-integration/account.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { CallData } from "starknet";
import {
LongSigner,
WrongSigner,
buildGiftCallData,
calculateEscrowAddress,
claimInternal,
Expand Down Expand Up @@ -121,6 +122,24 @@ describe("Escrow Account", function () {
);
});

it(`Wrong signature shouldn't be accepted`, async function () {
const { factory } = await setupGiftProtocol();
const { gift, giftPrivateKey } = await defaultDepositTestSetup({ factory });
const receiver = randomReceiver();

const escrowAccount = getEscrowAccount(gift, giftPrivateKey);
escrowAccount.signer = new WrongSigner();
await expectRevertWithErrorMessage("escrow/invalid-signature", () =>
escrowAccount.execute([
{
contractAddress: escrowAccount.address,
calldata: [buildGiftCallData(gift), receiver],
entrypoint: "claim_internal",
},
]),
);
});

it(`Shouldn't be possible to instantiate the library account`, async function () {
const classHash = await manager.declareLocalContract("EscrowLibrary");

Expand Down

0 comments on commit b44de8d

Please sign in to comment.