Actually it is usually entirely solidity’s fault, just take a look at all the simple functions in the solady library that are cheaper by avoiding solidity’s bytecode generation. Hence my suggestion that the energy be shifted towards the language and compiler for a much higher ROI.
Here’s an example: Writing a struct that fits in a single slot incurs additional SLOADs in Solidity 0.8.29. The assembly-only version costs 125 less gas, even though the result is identical.
pragma solidity =0.8.29;
import {Test} from "forge-std/Test.sol";
contract Target {
struct MyStruct {
uint64 a;
uint64 b;
uint128 c;
}
MyStruct public state;
constructor() {
state = MyStruct(3, 2, 1);
}
function solidityOnly() external {
state = MyStruct(1, 2, 3);
}
function assemblyOnly() external {
assembly ("memory-safe") {
sstore(0, or(or(1, shl(64, 2)), shl(128, 3)))
}
}
}
contract TestWasteTest is Test {
Target t;
function setUp() public {
t = new Target();
}
function test_solidityOnly() public {
t.solidityOnly();
vm.snapshotGasLastCall("solidity only");
(uint64 a, uint64 b, uint128 c) = t.state();
assertEq(a, 1);
assertEq(b, 2);
assertEq(c, 3);
}
function test_assemblyOnly() public {
t.assemblyOnly();
vm.snapshotGasLastCall("assembly only");
(uint64 a, uint64 b, uint128 c) = t.state();
assertEq(a, 1);
assertEq(b, 2);
assertEq(c, 3);
}
}
And I disagree with the premise anyway. If you are writing contracts that will handle billions of dollars, sorry but you’re going to need to have a deep understanding the platform you’re building on. EOF is going to make that a much bigger hurdle.