xian-network / xian-contracting

A subset of Python for developing smart contracts on the Xian Network
https://linktr.ee/xiannetwork
GNU General Public License v3.0
4 stars 1 forks source link

Improvements and optimizations for execution #84

Closed Endogen closed 1 month ago

Endogen commented 1 month ago

Description

Improvements and Optimizations:

  1. tracer.py Updated Opcode Costs: Adjusted the cu_costs dictionary to reflect Python 3.11's opcodes using opcode names to ensure compatibility. Instruction Cache Management: Added code to clear the instruction cache after execution to prevent holding contracts in memory. Static Imports Enforcement: Ensured that only code within contracts is traced, enforcing static imports and preventing dynamic imports during execution. Memory Usage Limit: Strictly enforced a memory usage limit and tracked incremental changes to prevent unexpected memory spikes.

  2. runtime.py Module Cache Clearing: Modified Runtime.clean_up() to clear the module cache, preventing all contracts from being held in memory. Context Resetting: Ensured proper resetting of the execution context to avoid residual state affecting subsequent executions. Compatibility Updates: Adjusted code for compatibility with Python 3.11 and optimized for performance.

  3. executor.py Module Cache Clearing: Added code to clear the module cache after contract execution to free up memory. Static Imports Enforcement: Adjusted code to ensure that contracts cannot perform dynamic imports at runtime. Exception Handling Optimization: Streamlined exception handling to ensure resources are properly cleaned up.

  4. module.py Restricted Imports Enforcement: Modified the restricted_import function to prevent dynamic imports within contracts, enforcing static imports. Module Cache Management: Changed the module cache to an instance variable and ensured it's cleared after execution to prevent memory buildup. Compatibility Adjustments: Updated module loading mechanisms to be compatible with Python 3.11's import system.

Type of change

Please delete options that are not relevant.

Checklist