Skip to content

[DONT MERGE] Seismic => upstream diff#63

Open
cdrappi wants to merge 387 commits intodevelopfrom
seismic
Open

[DONT MERGE] Seismic => upstream diff#63
cdrappi wants to merge 387 commits intodevelopfrom
seismic

Conversation

@cdrappi
Copy link
Copy Markdown
Contributor

@cdrappi cdrappi commented Jul 15, 2025

No description provided.

sfyll and others added 30 commits December 20, 2024 11:30
* sbool type

* adding sbool to AbiV2

* ShieldedBoolType

* add SBOOL Token

* shielded bool ops test

* isConvertible functions for bools

* isConvertible func sig for bools

* compiler handles isConvertible cases for bools

* further wiring for bools

* adding bool tests

* intermediary isShielded func inclusion

* adding new test for shielded arrays of all types

* replacing with containsShieldedType

* containsShieldedType def

* replacing arrays with containsShieldedType

* yulUtil use containsShieldedType

* updating tests

* isShielded func call

* typeChecker check literal assignments

* shielded event tests

* logic for bool ops

* rm implicit casting shielded types

* rm conversion from rational types

* adding shielded requirements

* expectBoolOrShieldedBool for bools

* fix if statement

* wip, not working, tries to cast uint to bool

* adding all new tests

* adding some prints

* working sbool IR

* no sbool can be returned

* un-needed changes

* modify test

* adding more tests

* array can now take suint

* check on push() that type match array's

* rm comment

* dyn array length shielded or not depending on arr type

* updating bunch of tests for explicit casting

* shielded push

* remove import

* rm prints

* rm more prints

* rm precompile from here
* missing semantic tests

* last missing test
Compiler no longer allows "suint immutable x" syntax, as the constructor embeds the value directly into the runtimeCode at a known offset and runtimeCode is stored publicly on-chain
drappi-ai and others added 30 commits March 3, 2026 16:29
Add built-in random number generation functions that call the RNG
precompile at address 0x64, with both legacy and IR codegen paths.

Cherry-picked from 9a2f3c7
Add built-in ECDH key derivation function that calls the precompile
at address 0x65, with both legacy and IR codegen paths.

Cherry-picked from b76e6dc
…nctions

Add built-in AES-GCM encryption/decryption functions that call
precompiles at addresses 0x66 and 0x67, with both legacy and IR
codegen paths.

Cherry-picked from 5f89df2
Add built-in HKDF key derivation function that calls the precompile
at address 0x68, with both legacy and IR codegen paths.

Cherry-picked from 86044a2
Add built-in secp256k1 signing function that calls the precompile
at address 0x69, with both legacy and IR codegen paths.

Cherry-picked from 0cad3b0
## Summary

- Adds `CLAUDE.md` with repo conventions for AI-assisted development
- Documents that PRs should target `SeismicSystems/seismic-solidity`
against the `seismic` branch
- Includes build instructions, testing commands, and shielded type
conventions
## Summary

- Adds 57 new test files (966 lines) adapting upstream `uint` tests for
`suint` (shielded unsigned integer) equivalents
- Covers shifts, arithmetic, expressions, cleanup, exponentiation,
arrays, storage, conversions, compound assignments, ABI encoder cleanup,
syntax restrictions, and cmdline via-ir tests
- All semantic tests pass across 3 configurations: no optimizer, with
optimizer, and with via-ir

## Test Files by Category

| Commit | Category | Files |
|--------|----------|-------|
| Shift operators | `operators/shifts/` | 17 |
| Arithmetic | `arithmetics/` | 8 |
| Expressions | `expressions/` | 4 |
| Cleanup | `cleanup/` | 5 |
| Exponentiation | `exponentiation/` | 2 |
| Arrays | `array/copying/`, `array/pop/` | 3 |
| Storage | `storage/` | 2 |
| Conversions | `types/` | 1 |
| Compound assignment | `operators/` | 1 |
| ABI encoder cleanup | `abiEncoderV2/cleanup/` | 1 |
| Syntax restrictions | `syntaxTests/types/` | 7 |
| Cmdline via-ir | `cmdlineTests/` | 6 (2 test dirs) |

## Adaptation Rules Applied

1. `uintN` → `suintN` for parameters and locals
2. Return types stay unshielded with `return uintN(expr)` cast
3. `sstore`/`sload` → `cstore`/`cload` for shielded storage in assembly
4. `pragma abicoder v2` on all files
5. Literal wrapping: `suintN(42)` for assignments
6. Gas/storageEmpty annotations removed
7. Shielded array `.length` cast to `uint256()` before
arithmetic/comparison

## Test plan

- [x] `isoltest --no-semantic-tests` — all 7 syntax tests pass
- [x] `revme semantics` — all 1716 files pass (no optimizer)
- [x] `revme semantics --optimize` — all 1716 files pass
- [x] `revme semantics --via-ir` — all 1716 files pass
## Summary

Auditor recommendation: test more optimizer-runs configurations to catch
optimizer bugs.

Consolidates the 4 separate semantic test CI steps into 1 and expands
from 4 to 12 configurations:

| optimizer-runs | no IR | --via-ir |
|---|---|---|
| (none) | ✅ | ✅ |
| default (200) | ✅ | ✅ |
| 1 | ✅ | ✅ |
| 1,000 | ✅ | ✅ |
| 1,000,000 | ✅ | ✅ |
| 4,294,967,295 | ✅ | ✅ |

The default (200) case uses `--optimize` without `--optimizer-runs`,
relying on Solidity's built-in default.

### Why these values

- **default (200)** — Solidity default, most common in production
(OpenZeppelin)
- **1** — deploy-optimized (proxies, factories)
- **1,000** — moderate runtime optimization (DeFi protocols)
- **1,000,000** — heavy runtime optimization (Uniswap V3)
- **4,294,967,295** — type(uint32).max, maximum optimization
(Seaport/OpenSea)

These cover the full spectrum from deployment-cost-minimized to
maximum-runtime-optimized, matching real-world production usage.

## Test plan

- [ ] CI runs all 12 configurations successfully
## Summary

- Fix CI failure: `git checkout e962e217...` fails because that commit
only exists on the unmerged `ci-via-ir-support` branch in seismic-revm
- The `--unsafe-via-ir` flag has already been merged into seismic-revm's
`seismic` branch (commit `03f561fd`)
- Clone `--branch seismic` directly instead of cloning default branch +
checking out a hardcoded commit

## Test plan

- [ ] CI workflow successfully clones seismic-revm and runs semantic
tests
…fferent contexts (#220)

## Summary

Shielded literal warnings currently all emit the same warning IDs
regardless of AST context, making it impossible for downstream tools
(sforge) to selectively suppress false positives in test/script files.
Additionally, the compiler silently allows shielded types as constructor
parameters even though CREATE/CREATE2 does not encrypt calldata —
meaning shielded values passed to constructors are visible in deployment
transaction data.

### Changes

**1. New warning for shielded constructor parameters (5500)**

Fires on any non-abstract constructor with shielded parameter types.
Catches both literals and variables passed to constructors — the root
cause of CREATE-based leaks.

```
Warning 5500: Shielded types in constructor parameters are visible in deployment
transaction data. Contract creation (CREATE/CREATE2) does not encrypt calldata.
Consider setting shielded state via a post-deployment transaction instead.
This is expected to be fixed in a future release.
```

**2. Distinct warning IDs for literal context in `new(...)` args
(5501–5505)**

When a literal-to-shielded conversion occurs inside a `new` expression's
arguments, the child contract gets deployed via CREATE — the literal
leaks in init code even if the caller is a test contract.

```
Warning 5501: Literals converted to shielded integers will leak during contract
deployment. Contract creation (CREATE/CREATE2) does not encrypt calldata.
This is expected to be fixed in a future release.
```

**3. Distinct warning IDs for literal context in external call args
(5506–5510)**

When a literal-to-shielded conversion occurs inside an external function
call's arguments, the literal is in the caller's bytecode but calldata
is encrypted by TxSeismic. Safe to suppress in test/script files.

### Warning ID mapping

| Type | `new(...)` args | External call args | Other contexts |
|------|-----------------|--------------------|----------------|
| integer | 5501 | 5506 | 9660 |
| bool | 5502 | 5507 | 9661 |
| address | 5503 | 5508 | 9662 |
| fixedbytes | 5504 | 5509 | 9663 |
| enum | 5505 | 5510 | 1457 |
| constructor param | 5500 | — | — |

### Intended use by seismic-compilers

- **`src/`** files: show all warnings
- **`test/` and `script/`** files:
- **Keep**: 5500 (constructor param), 5501–5505 (literal in `new(...)` —
child gets deployed)
- **Suppress**: 5506–5510 (external call), 9660–9663 + 1457 (other —
test bytecode never deployed)

### Detection logic

External calls detected via `MemberAccess` on contract/interface-typed
variables and `this`. Built-in member functions (`arr.push()`) excluded.
When `new` and external call contexts are nested, `new` takes priority.

### Tests

29 new syntax test files. Full syntax test suite: 3807/3807, zero
regressions.
- Add 15 semantic tests covering signed-specific shielded integer
(`sint`) behavior that was previously untested
- Mirrors key upstream `int` tests as `sint` equivalents (signed mod,
negative shifts, signed exponentiation) and adds new edge case tests for
confidential storage (storage roundtrip, arithmetic overflow,
comparisons, type conversions)
- Complements the existing `suint` test suite (#215) with
signed-specific coverage: negative values, sign extension in shifts,
two's complement overflow, signed modulo, negative base exponentiation
## Summary
- Extracts all 5 Solidity code snippets from
`docs/gitbook/overview/use-cases.md` (in the seismic docs repo) and adds
them as compiler syntax tests in
`test/libsolidity/syntaxTests/docExamples/`.
- Tests cover: SRC20 private tokens, confidential AMM, compliance token
(Intelligence Contracts), private voting, and sealed-bid auctions.
- All 5 tests pass with `isoltest`.

## Doc issue found
The **Confidential DeFi (AMM)** example in the docs declares `function
swap(...) public returns (suint256 amountOut)`, but shielded types
cannot be returned from public/external functions. The test uses
`internal` visibility instead. The docs should be updated to fix this.

## Test plan
- [x] Verify all 5 syntax tests pass with `isoltest --no-smt
--no-semantic-tests -t "syntaxTests/docExamples/*"`
- [ ] CI passes

Co-authored-by: Christian Drappi <c@seismic.systems>
## Summary
- Adds a semantic test verifying manual slot packing of two `suint128`
values into a single confidential slot via inline assembly
(`cstore`/`cload`)
- Uses a `keccak256`-derived slot to avoid storage collisions
- Mirrors the code example in the storage docs
(`docs/gitbook/seismic-solidity/storage.md`)

## Test plan
- [x] Passes without optimizer
- [x] Passes with optimizer (--optimize --optimizer-runs 200)

---------

Co-authored-by: Christian Drappi <c@seismic.systems>
## Summary
- Rename all rngN built-in functions to sync_rngN
- Update magic variable ID mappings and declarations in
GlobalContext.cpp
- Update all existing semantic and syntax tests to use the new names

## Test plan
- [ ] Verify syntax tests pass
- [ ] Verify semantic tests pass
- [ ] Grep for any remaining rngN references
## Summary
- Add `sync_rng_b1` through `sync_rng_b32` built-in functions returning
`sbytesN` types via the RNG precompile (0x64)
- Update both legacy and IR codegen to handle `ShieldedFixedBytesType`
(left-aligned, no shift needed unlike integer variants)
- Add magic variable IDs (-41 through -72) and declarations in
`GlobalContext.cpp`

Stacked on #229.

## Test plan
- [x] Semantic tests for all 32 `sync_rng_bN` variants
(`rng_bytes_builtins.sol`)
- [x] Syntax test verifying correct return types
(`rng_bytes_type_check.sol`)
- [ ] Syntax test verifying view-not-pure enforcement
(`rng_bytes_view_not_pure.sol`)
## Summary
- Moves all Seismic-specific magic variable IDs (sync_rng*, ecdh,
aes_gcm_encrypt, aes_gcm_decrypt, hkdf, secp256k1_sign,
sync_rng_b1..b32) from the -30..-72 range to -100+
- Prevents future collisions with upstream Solidity built-in IDs, which
currently end at blobhash (-29) and grow downward
- No functional change: IDs are purely internal and resolved by name via
`magicVariableToID()`
## Summary
- Adds a semantic test verifying that `block.timestamp_ms / 1000 ==
block.timestamp` and `block.timestamp_seconds == block.timestamp` within
a single call
- Existing tests only check the weaker `block.timestamp_ms >=
block.timestamp * 1000` inequality; this test asserts exact equality
after integer division
- Runs via both legacy and IR (`compileViaYul: also`) pipelines

## Test plan
- [x] CI semantic tests pass for both legacy and via-IR compilation
## Summary
- Add `sync_rng96()` built-in function returning `suint96`, following
the same pattern as the existing `sync_rng8`/`16`/`32`/`64`/`128`/`256`
family
- Register the magic variable ID (-239) and declaration in
`GlobalContext.cpp`
- No codegen changes needed -- the RNG precompile dispatch already
derives `byteWidth` from the return type dynamically

## Test plan
- [ ] Updated `rng_type_check.sol` syntax test to include `sync_rng96`
- [ ] Updated `rng_builtins.sol` semantic test with a `testRng96()` that
verifies the returned value is in the expected random range
- [ ] Existing sync_rng tests continue to pass unchanged
…ning (#234)

## Summary

- Adds **40 new syntax tests** and **18 new semantic tests** for the
`sync_rng` / `sync_rng_b` built-in functions, massively expanding
coverage
- Adds **defensive assertions** to both codegen backends (legacy + IR)
to catch internal invariant violations early

### Syntax tests cover:
- **Pure rejection**: all integer variants, all bytes variants
- **Type safety**: wrong shielded width, cross-family (int↔bytes), no
implicit conversion to plain types (uint, bytes, address, bool)
- **Argument validation**: 0-arg functions reject arguments
- **Member access**: `.gas()` / `.value()` rejected
- **Visibility**: external, internal, private, non-view contexts
- **Usage patterns**: constructor, modifier, loop, ternary, function
argument, mapping, array, struct, inheritance, cross-contract
- **Edge cases**: local variable shadowing, shielded return from
public/external functions

### Semantic tests cover:
- Consecutive calls produce different values
- Bit-width integrity for all integer sizes (values fit within expected
range)
- Bytes alignment (left-aligned, zero-padded lower bytes)
- Storage round-trip through mappings, arrays, and structs
- Cross-contract calls, inheritance, internal function calls
- Constructor initialization, modifier context, ternary branches
- Mixed type calls in single transaction
- Loop diversity and XOR accumulation
- Explicit cast to plain types
- Raw precompile (0x64) staticcall validation
- Interaction with other built-ins (keccak256, gasleft)

### Defensive hardening:
- Legacy codegen: added `solAssert` for `valueSet`, `gasSet`,
`hasBoundFirstArgument` (matching IR codegen)
- Both backends: added `byteWidth` range assertion `[1, 32]`
- IR codegen: added descriptive messages to all existing `solAssert`
calls
## Summary

- Add `s` suffix for numeric literals to create shielded integer
constants (e.g. `suint8 x = 42s;` instead of `suint8 x = suint8(42);`)
- The literal's concrete shielded type (suint8 vs suint256, signed vs
unsigned) is inferred from context
- Works with hex (`0xDEADs`), underscores (`1_000s`), scientific
notation (`1e5s`), and unary minus (`-1s`)
- Mixed shielded/non-shielded arithmetic (`1s + 1`) is rejected — both
operands must use `s`
- Shielded literals cannot implicitly convert to non-shielded types
(`uint8 x = 1s;` errors)
- Warning 9660 emitted for all shielded literals (values visible in
deployment bytecode)
- No impact on bools or variable names ending in `s`

## Changes

**Scanner/Token** (`liblangutil/`): New `ShieldedNumber` token; scanner
consumes trailing `s` on numeric literals when not followed by an
identifier character.

**Parser** (`libsolidity/parsing/`): Handle `ShieldedNumber` in
literal/expression parsing; reject `s` + subdenomination combos.

**Type system** (`libsolidity/ast/`): `RationalNumberType` gains
`m_shielded` flag propagated through unary/binary ops, equality,
`mobileType()`, and `toString()`. New `shieldedIntegerType()` method.

**Analysis** (`libsolidity/analysis/`): `SyntaxChecker` validates
formatting; `TypeChecker` emits warning 9660.

**AST JSON** (`libsolidity/ast/`): Export/import `"shieldedNumber"`
literal kind.

## Test plan

- [x] 8129 unit tests (`soltest.sh`) — all pass
- [x] 3788 syntax tests (`isoltest`) — all pass, no regressions
- [x] 11 new syntax tests covering suint/sint basics, overflow, type
mismatch, mixed arithmetic, fractional, identifier regression
- [x] 2 new semantic tests (`shielded_literal_suint.sol`,
`shielded_literal_sint.sol`) — pass via seismic-revm
- [x] CI: full semantic test sweep with optimizer configurations
## Summary

Resolves #236. Migrates all Seismic-specific error codes from the
4-digit range (1000–9999) to 5-digit codes (10000+), eliminating
collisions with upstream Solidity error codes and fixing all 7 duplicate
error IDs.

- **`scripts/error_codes.py`**: Updated validation and test-scanning
regexes to accept both 4-digit (upstream) and 5-digit (Seismic) error
codes
- **49 Seismic error codes** reassigned into organized groups:
  - `10001–10004`: EVM version gates (Mercury EVM requirements)
- `10101–10110`: Shielded type restrictions (public vars, returns,
mapping keys, etc.)
- `10201–10208`: Encoding / type system errors (ABI encode/decode, array
push, etc.)
- `10301–10311`: Privacy leak warnings — runtime (overflow, gas, control
flow)
- `10401–10416`: Privacy leak warnings — deployment (literal leaks by
context)
- **All 7 duplicate IDs fixed**: each call site now has a unique code;
upstream codes restored to original messages
- **353 files touched**, all test expectations updated to match new
codes

### Duplicate resolution details

| Old ID | Issue | Resolution |
|--------|-------|-----------|
| 2311 ×2 | Upstream + shielded address payable | Keep 2311 upstream,
10108 Seismic |
| 3125 ×2 | Upstream + shielded address members | Keep 3125 upstream,
10208 Seismic |
| 3648 ×2 | Two shielded ABI encode checks | 10202 (function args),
10203 (external args) |
| 4281 ×2 | Upstream CHC + shielded div/mod | Keep 4281 upstream, 10303
Seismic |
| 5765 ×3 | sstore/sload + require + if/while | 10308, 10310, 10311 |
| 7804 ×2 | Upstream + shielded mapping keys | Keep 7804 upstream, 10109
Seismic |
| 9132 ×2 | Upstream EOF + CSTORE/CLOAD EOF | Keep 9132 upstream, 10110
Seismic |

### Still untested (pre-existing, tracked separately)

`10110`, `10203`, `10206`, `10407`, `10410`, `10413`

## Test plan

- [ ] `python3 scripts/error_codes.py --check` passes with 0 duplicates
- [x] `./scripts/soltest.sh` passes syntax tests
- [x] Semantic tests via seismic-revm pass
## Summary

Stacked on #238. Adds test coverage for the 6 previously untested
Seismic error codes, making `scripts/error_codes.py --check` pass
cleanly.

### Tests added (15 files)

| Code | What it checks | Tests |
|------|---------------|-------|
| **10110** | CSTORE/CLOAD not available in EOF | `cstore_in_eof.yul`,
`cload_in_eof.yul` |
| **10203** | Shielded types in `abi.encodeCall` |
`abi_encode_call_shielded_{suint,sbool,saddress}.sol` |
| **10206** | Push shielded type to non-shielded array |
`shielded_push_to_unshielded_array_{suint,sbool,saddress}.sol` |
| **10407** | Address literal → saddress in `new` expression | 3 tests
(single, multiple, payable conversion error) |
| **10410** | FixedBytes literal → sbytes in `new` expression |
`warn_shielded_literal_new_sbytes{,4}.sol` |
| **10413** | Enum → shielded int in `new` expression |
`warn_shielded_literal_new_enum{,_multiple}.sol` |

## Test plan

- [x] `python3 scripts/error_codes.py --check` passes with "No incorrect
IDs found"
- [x] `./scripts/soltest.sh` passes
- [x] Semantic tests via seismic-revm pass
## Summary

Adds a GitHub Actions workflow that mirrors upstream's CircleCI
`chk_errorcodes` job, running `scripts/error_codes.py --check` on
push/PR to the seismic branch.

This will currently fail due to 6 untested error codes — that's expected
and will be resolved in a follow-up once tests are added for those codes
(tracked in #236).

## Test plan

- [x] Workflow runs and correctly reports untested codes

Co-authored-by: Christian Drappi <c@seismic.systems>
## Summary
- Adds 16 new semantic test files (1560 lines) for the
`sbytes1`–`sbytes32` shielded fixed bytes types
- Existing semantic tests only covered 3 sizes (sbytes1/8/32) with basic
declarations and storage — this fills all gaps
- All files compile cleanly against current ssolc

## Test coverage added

| Category | Files | What's tested |
|----------|-------|---------------|
| Storage all sizes | `shielded_sbytes_storage_all_sizes.sol`,
`shielded_sbytes_bytes_roundtrip.sol` | cstore/cload roundtrip +
bytes↔sbytes conversion for all 32 sizes |
| Operations | `shielded_sbytes_bitwise_ops.sol`,
`shielded_sbytes_comparisons.sol`, `shielded_sbytes_shift_ops.sol` | &,
\|, ^, ~, all 6 comparisons, <<, >> |
| Conversions | `shielded_sbytes_cross_size_conversions.sol`,
`shielded_sbytes_suint_conversions.sol`,
`shielded_sbytes_saddress_conversions.sol` | Cross-size, sbytes↔suint,
sbytes20↔saddress |
| Storage edge cases | `shielded_sbytes_storage_overwrite.sol`,
`shielded_sbytes_storage_edge_values.sol`,
`shielded_sbytes_slot_isolation.sol` | Overwrites,
zeros/0xFF/alternating patterns, multi-var slot isolation |
| Compound features | `shielded_sbytes_function_params.sol`,
`shielded_sbytes_array_storage.sol`,
`shielded_sbytes_mapping_storage.sol`,
`shielded_sbytes_struct_storage.sol`, `shielded_sbytes_ternary.sol` |
Function param passing, arrays, mappings, structs, ternary operator |

## Test plan
- [x] CI semantic tests pass in all 12 configurations (optimizer ×
via-ir matrix)
## Summary
- Adds `--no-seismic-warnings` flag to suppress all Seismic-specific
warnings (error codes >= 10000) while preserving standard Solidity
warnings and all errors
- Filters warnings in both the compiler and Yul assembler error output
paths
- Includes cmdline test and updates CommandLineParser unit tests

## Test plan
- [x] `cmdlineTests.sh -t no_seismic_warnings` passes — verifies seismic
warning (10103) is suppressed while compilation succeeds
- [x] `soltest -t CommandLineParser*` — all 14 parser tests pass with
the new option
- [ ] CI build + full test suite

---------

Co-authored-by: Christian Drappi <c@seismic.systems>
## Summary
- Adds documentation to both `CLAUDE.md` and `README.md` explaining the
Seismic error/warning code numbering scheme
- Seismic-specific codes use 5-digit IDs >= 10000; upstream Solidity
uses 4-digit codes (1000–9999)
- Documents the 5 code groups by 3rd digit: `100__` (EVM compat),
`101__` (declaration constraints), `102__` (ABI/type interaction),
`103__` (info leak warnings), `104__` (deployment leak warnings)
- This convention is required for `--no-seismic-warnings` to correctly
suppress only Seismic warnings

## Test plan
- [ ] Documentation-only change — no code modified
- [ ] Verify section numbering in README renders correctly

---------

Co-authored-by: Christian Drappi <c@seismic.systems>
## Summary
- Renames all RNG built-in functions to start with `unsafe_` to signal
that randomness is sequencer-provided and not cryptographically
committed
- Integer variants: `sync_rng{N}` → `unsafe_rng_u{N}` (e.g.
`unsafe_rng_u256()`)
- Bytes variants: `sync_rng_b{N}` → `unsafe_rng_b{N}` (unchanged prefix,
e.g. `unsafe_rng_b32()`)
- Adds new "RNG Precompiles" section to README linking to
https://docs.seismic.systems/reference/precompiles/rng

## Test plan
- [ ] `scripts/soltest.sh` passes (unit tests)
- [ ] Semantic tests pass via seismic-revm (all 4 configurations)
- [ ] `isoltest --no-semantic-tests` passes for
`syntaxTests/seismic_builtins/rng_*`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants