From 606eb380cd203edae391891460b21b8c3ed9ffb6 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 16 Jun 2026 16:44:33 +0200 Subject: [PATCH 1/2] Use mstore/mload/sstore/sload from opcodes --- std/std.solc | 15 ++------------- test/examples/dispatch/hashes.solc | 1 + test/examples/dispatch/memory.solc | 1 + test/examples/dispatch/stringid.solc | 4 +++- 4 files changed, 7 insertions(+), 14 deletions(-) diff --git a/std/std.solc b/std/std.solc index 4686cf2c..dac817dc 100644 --- a/std/std.solc +++ b/std/std.solc @@ -1,3 +1,5 @@ +import std.opcodes.{mstore, mload, sstore, sload}; + pragma no-patterson-condition ABIEncode, Num; pragma no-coverage-condition ABIDecode, MemoryType; @@ -85,8 +87,6 @@ export { memberAccessBase, memory(*), memory_ref, - mload, - mstore, ne, not, or, @@ -805,21 +805,10 @@ data mapping(member, index) = mapping(word) ; // --- Low-level memory ops -function mload(a:word) -> word { - let res: word; - assembly { res := mload(a) } - return res; -} - -function mstore(a:word, v:word) -> () { - assembly { mstore(a,v) } -} - function strlen(s:memory(string)) -> word { match s { | memory(a) => return mload(a); } } - // --- Memory Utilities --- // Memory in solidity is bump allocated in a single arena diff --git a/test/examples/dispatch/hashes.solc b/test/examples/dispatch/hashes.solc index 453ae227..b6b14902 100644 --- a/test/examples/dispatch/hashes.solc +++ b/test/examples/dispatch/hashes.solc @@ -1,5 +1,6 @@ import std.{*}; import std.dispatch.{*}; +import std.opcodes.{mstore}; // Build a memory(bytes) holding the three-byte string "abc". function abcBytes() -> memory(bytes) { diff --git a/test/examples/dispatch/memory.solc b/test/examples/dispatch/memory.solc index 7c17bccb..eec43817 100644 --- a/test/examples/dispatch/memory.solc +++ b/test/examples/dispatch/memory.solc @@ -1,5 +1,6 @@ import std.{*}; import std.dispatch.{*}; +import std.opcodes.{mstore}; contract C { public function dirty_allocate() -> memory(bytes) { diff --git a/test/examples/dispatch/stringid.solc b/test/examples/dispatch/stringid.solc index a75b4cae..2798097e 100644 --- a/test/examples/dispatch/stringid.solc +++ b/test/examples/dispatch/stringid.solc @@ -1,6 +1,8 @@ import std.{*}; -import std.{memory, string, Typedef, log1, allocate_memory, mstore, uint256}; +import std.{memory, string, Typedef, log1, allocate_memory, uint256}; import std.dispatch.{*}; +import std.opcodes.{mstore, mload}; + pragma no-patterson-condition ; pragma no-coverage-condition ; pragma no-bounded-variable-condition ; From 4116cb937c0df49d48f8ac17248899cc21888315 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 16 Jun 2026 16:55:08 +0200 Subject: [PATCH 2/2] Remove obsolete sload_/sstore_/sloadViaWord/sstoreViaWord --- std/std.solc | 46 ++-------------------------------------------- 1 file changed, 2 insertions(+), 44 deletions(-) diff --git a/std/std.solc b/std/std.solc index dac817dc..f4321a59 100644 --- a/std/std.solc +++ b/std/std.solc @@ -105,10 +105,6 @@ export { sha256, slice(*), slice_, - sloadViaWord, - sload_, - sstore_, - sstoreViaWord, storage(*), storeBytesFromMemory, string, @@ -1529,20 +1525,6 @@ pragma no-coverage-condition MemberAccessProxy, LVA, RVA, CStructField, Assign; pragma no-bounded-variable-condition LVA, RVA; // -- storage -function sload_(x:word) -> word { - let res: word; - assembly { - res := sload(x) - } - return res; - } - -function sstore_(a:word, v:word) -> () { - assembly { sstore(a,v) } -} - - - forall self. class self:StorageSize { function size(x:Proxy(self)) -> word; @@ -1612,7 +1594,6 @@ forall a b. a:StorageSize, b:StorageSize => instance (a,b):StorageSize { } } - forall self. class self:StorageType { function load(ptr:word) -> self; @@ -1621,33 +1602,10 @@ class self:StorageType { instance word:StorageType { function load(ptr:word) -> word { - let r:word; - assembly { - r := sload(ptr) - } - return r; + return sload(ptr); } function store(ptr:word, value:word) -> () { - assembly { - sstore(ptr, value) - } - } -} - -forall a. a:Typedef(word) => -function sloadViaWord(ptr:word) -> a { - let r:word; - assembly { - r := sload(ptr) - } - return Typedef.abs(r); -} - -forall a. a:Typedef(word) => -function sstoreViaWord(ptr:word, value:a) -> () { - let w: word = Typedef.rep(value); - assembly { - sstore(ptr, w) + sstore(ptr, value); } }