kkrt-labs / kakarot-ssj

Kakarot zkEVM - rewrite in the latest version of Cairo
https://www.kakarot.org
MIT License
137 stars 83 forks source link

feat: implement Jumpdest caching in account storage #839

Open enitrat opened 3 months ago

enitrat commented 3 months ago

In an effort to optimize step consumption when executing transactions, we can run analysis on bytecode upon deployment of a contract and save all valid jumpdests indexes in a contract's storage.

When a jump is performed later on, we can load whether the jump index is valid by reading the contract storage, and caching this value for later uses.

References: https://github.com/kkrt-labs/kakarot/blob/65e333a0d3475e81b0a6367b0f00561c763da0a0/src/kakarot/evm.cairo#L314-L338 https://github.com/kkrt-labs/kakarot/blob/65e333a0d3475e81b0a6367b0f00561c763da0a0/src/kakarot/accounts/library.cairo#L413-L430 https://github.com/kkrt-labs/kakarot/blob/65e333a0d3475e81b0a6367b0f00561c763da0a0/src/kakarot/accounts/library.cairo#L403-L411 https://github.com/kkrt-labs/kakarot/blob/65e333a0d3475e81b0a6367b0f00561c763da0a0/src/backend/starknet.cairo#L214-L221

ScottyDavies commented 3 months ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

I have a background in building efficient and responsive user experiences, can be greatly leveraged in the context of the Kakarot project. Understanding the optimization techniques used in the backend allows me to create a user interface that seamlessly complements the performance-driven approach of the Kakarot team.

How I plan on tackling this issue

I would approach this issue with following steps

1 Performance Optimization: My experience in optimizing web application performance will enable me to integrate the backend's caching mechanism in a way that minimizes the computational overhead on the frontend. This will result in faster transaction processing and a more responsive application, providing users with a smooth and efficient experience. 2 User Feedback: Leveraging the cached jump destination information, I can design intuitive user interfaces that provide clear and meaningful feedback to users during the transaction process. This could include displaying dynamic loading indicators, progress bars, and other visual cues that keep users informed about the status of their transactions. 3 Error Handling: By understanding the backend's validation of jump destinations, I can develop robust error handling mechanisms on the frontend. This will allow me to present users with informative error messages that guide them on how to troubleshoot issues, improving the overall user experience. 4 Caching and Optimization: Drawing on my expertise in frontend optimization, I can explore ways to further cache and reuse the validated jump destination information on the client-side. This will reduce the need for repeated backend calls, leading to improved responsiveness and a more efficient user interface. 5 Integration and Collaboration:
My background in frontend development and my understanding of the backend optimization techniques will enable me to work closely with the Kakarot team, fostering a collaborative environment. This collaboration will ensure that the user interface seamlessly integrates with the performance-driven backend, creating a cohesive and user-friendly application.

ShantelPeters commented 3 months ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

I am a frontend and smart contract developer . with this experience i will tackle the issue as expected this will be done between 3 to 4 working days please assign

How I plan on tackling this issue

To solve this problem i would do the following ;

  1. Bytecode Analysis: Implement a mechanism to analyze the contract's bytecode during deployment to identify all valid jumpdest indexes.

  2. Store Valid Jumpdests: Save these valid jumpdest indexes in the contract's storage for efficient retrieval during transaction execution.

  3. Optimize Jumps: During a jump, load the jump index from storage to check its validity. Implement caching to reduce storage read operations in future jumps.

  4. Reference Existing Code: Leverage the provided code references to integrate this functionality within

DIWAKARKASHYAP commented 3 months ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

I am a full stack web and blockchain developer on ethereum chain and also a opensource contributor https://diwakar-portfolio.vercel.app/, i think i am a perfect fit for this issue

obatirou commented 2 months ago

This issue is blocked by https://github.com/starkware-libs/cairo/issues/6265 It could be implemented with an array with .contains but might be expensive. A benchmark could be done with end2end tests once integrated (https://github.com/kkrt-labs/kakarot-ssj/issues/848) but not planned for now due a possible monorepo migration.

WIP implementation (far from ready, needs refactoring and improvements but can be used as inspiration): https://github.com/kkrt-labs/kakarot-ssj/compare/main...obatirou:kakarot-ssj:cache-jumpdest