Self-Modifying Legal Code In Energy Systems .
SELF-MODIFYING LEGAL CODE IN ENERGY SYSTEMS
1. Concept and Meaning
Self-modifying legal code in energy systems refers to regulatory rules embedded within digital infrastructure that can automatically adjust operational parameters when predefined conditions change. Examples include automated electricity tariffs, congestion-management algorithms, smart-contract settlement rules, dynamic grid-access limits, automated balancing mechanisms and software that modifies dispatch or compliance requirements according to real-time system conditions.
The concept combines law, software and energy regulation. Traditional regulation is written as legislation, licences or regulatory decisions and subsequently implemented by humans. Self-modifying regulatory systems instead translate legal standards into executable code capable of adapting automatically.
However, software cannot legally acquire unlimited authority merely because it can technically modify itself. Any automated change affecting electricity prices, licences, market access or consumer rights must remain traceable to legislation or another lawful empowering instrument. South African constitutional law requires exercises of public power to remain lawful and rational even where sophisticated technologies are used.
2. Regulatory Architecture
A lawful self-modifying framework normally contains three layers.
Primary legal authority establishes the objectives, jurisdiction and boundaries within which automation may operate.
Executable regulatory code converts those rules into algorithms capable of changing operational variables according to defined inputs.
Human and institutional oversight permits regulators, courts and system operators to audit, suspend or override automated outcomes.
For example, an electricity algorithm might automatically increase scarcity prices when reserves fall below a statutory threshold. The software may calculate the adjustment, but the underlying authority to determine tariffs must still originate from the legally authorised regulator.
This distinction prevents what may be described as algorithmic delegation without legal accountability.
3. Major Legal Risks
The first concern is ultra vires modification. An algorithm cannot lawfully introduce regulatory requirements exceeding the statute or licence from which it derives authority.
Second, transparency and explainability become important where algorithms affect prices or access to essential infrastructure. Market participants must be able to understand the legal basis for regulatory outcomes.
Third, self-modifying code creates cybersecurity and manipulation risks. Malicious alteration of regulatory algorithms could influence dispatch, prices or network access.
Fourth, automated systems raise procedural-fairness questions. If code changes a regulated party's legal position without meaningful notice, reasons or an opportunity to challenge the outcome, administrative-law requirements may be violated.
Comparable energy regulation increasingly recognises automated activity. EU wholesale-energy rules expressly regulate algorithmic trading where computer algorithms determine parameters including timing, price and quantity with limited or no human intervention.
4. Case Law
PG Group Ltd v National Energy Regulator of South Africa 2018 (5) SA 150 (SCA)
Facts: Industrial gas users challenged NERSA's pricing methodology governing future maximum-price applications.
Legal Issue: Whether adoption of a regulatory methodology itself constituted reviewable administrative action under PAJA.
Judgment: The Supreme Court of Appeal examined whether the methodology had the required direct external legal effect. The litigation distinguished a regulatory methodology from later decisions applying it.
Legal Principle/Ratio: Regulatory frameworks or methodologies may structure future decisions without necessarily constituting final administrative action at the moment of adoption.
Significance: Self-modifying code may similarly operate as an underlying regulatory methodology, while particular automated decisions applying that code may create separately reviewable legal consequences.
AfriForum NPC v NERSA [2025] ZAGPPHC 1176
Facts: NERSA departed from prescribed procedural requirements while implementing a modernised regulatory process.
Legal Issue: Whether technological or administrative modernisation justified departure from legally prescribed procedures.
Judgment: The High Court held that modernisation did not permit NERSA to disregard binding law. It emphasised that the regulator was not free to substitute its preferred procedure for statutory requirements.
Legal Principle/Ratio: Regulatory innovation must occur within existing empowering legislation unless the legislation itself is lawfully amended.
Significance: This principle directly limits autonomous regulatory software: technological efficiency cannot authorise code to rewrite binding legal obligations.
Sasol Oil (Pty) Ltd v NERSA [2025] ZAGPPHC 919
Facts: Sasol challenged regulatory pricing decisions taken by NERSA.
Legal Issue: Whether regulatory decisions complied with statutory standards requiring systematic, fair, non-discriminatory, transparent and predictable methodology.
Judgment: The Court assessed the decision against statutory methodology and PAJA rationality requirements.
Legal Principle/Ratio: Regulatory decisions must remain rationally connected to their statutory purpose and prescribed methodology.
Significance: An adaptive algorithm must therefore remain auditable and capable of demonstrating why each automated modification corresponds with authorised legal objectives.
5. Conclusion
Self-modifying legal code could make energy governance faster and more responsive to rapidly changing electricity conditions. Nevertheless, executable regulation cannot become autonomous law-making. Its legitimacy depends on statutory authority, transparent algorithms, auditability, cybersecurity, procedural fairness, human override and judicial review. The central legal principle is that code may execute and adapt regulation, but it cannot independently escape the constitutional and statutory framework from which its authority originates.

comments