Skip to content

Commit

Permalink
dev: check fromAddress in starknet event (kkrt-labs#1291)
Browse files Browse the repository at this point in the history
* dev: check `fromAddress` in starknet event

* add comment

* trunk format

* update deno tests

* fix: address comparison

---------

Co-authored-by: Eugenio Paluello <eugypalu@gmail.com>
  • Loading branch information
swetshaw and eugypalu authored Aug 7, 2024
1 parent 836e04e commit 6ff3801
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
7 changes: 4 additions & 3 deletions indexer/src/types/log.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { assertEquals } from "https://deno.land/std@0.213.0/assert/mod.ts";
import { fromJsonRpcLog, IGNORED_KEYS, JsonRpcLog, toEthLog } from "./log.ts";
import { bigIntToHex, Event, JsonRpcTx } from "../deps.ts";
import { KAKAROT_ADDRESS } from "../constants.ts";

// Mock for hexToBytes
const mockHexToBytes = (hex: string): Uint8Array => {
Expand Down Expand Up @@ -101,7 +102,7 @@ Deno.test("toEthLog with valid input", () => {

const event: Event = {
index: 1,
fromAddress: "0x123456",
fromAddress: KAKAROT_ADDRESS as `0x${string}`,
keys: ["0x1234", "0x5678", "0x9abc", "0xdef0", "0x1111"],
data: ["0x01", "0x02", "0x03"],
};
Expand Down Expand Up @@ -233,7 +234,7 @@ Deno.test("toEthLog with empty event data", () => {
// No data in the event.
const event: Event = {
index: 1,
fromAddress: "0x123456",
fromAddress: KAKAROT_ADDRESS as `0x${string}`,
keys: ["0x1234", "0x5678", "0x9abc", "0xdef0", "0x1111"],
data: [],
};
Expand Down Expand Up @@ -286,7 +287,7 @@ Deno.test("toEthLog with pending block", () => {

const event: Event = {
index: 1,
fromAddress: "0x123456",
fromAddress: KAKAROT_ADDRESS as `0x${string}`,
keys: ["0x1234", "0x5678", "0x9abc", "0xdef0", "0x1111"],
data: ["0x01", "0x02", "0x03"],
};
Expand Down
9 changes: 7 additions & 2 deletions indexer/src/types/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { padBigint } from "../utils/hex.ts";

// Constants
import { NULL_BLOCK_HASH } from "../constants.ts";
import { KAKAROT_ADDRESS, NULL_BLOCK_HASH } from "../constants.ts";

// Starknet
import { Event, hash } from "../deps.ts";
Expand Down Expand Up @@ -47,9 +47,14 @@ export function toEthLog({
blockHash: PrefixedHexString;
isPendingBlock: boolean;
}): JsonRpcLog | null {
const { keys, data } = event;
const { keys, data, fromAddress } = event;
const { transactionIndex, hash } = transaction;

// Log events originated from kakarot address only
if (BigInt(fromAddress) !== BigInt(KAKAROT_ADDRESS)) {
return null;
}

// The event must have at least one key (since the first key is the address)
// and an odd number of keys (since each topic is split into two keys).
// <https://github.com/kkrt-labs/kakarot/blob/main/src/kakarot/evm.cairo#L169>
Expand Down

0 comments on commit 6ff3801

Please sign in to comment.