feat(EDSL): arrayLength for Bytes/String dynamic values (supersedes #1991)#2003
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
…d String, docs + artifact - Remove `ArrayLength Bytes32` (reducible abbrev of Uint256 — made `arrayLength` typecheck and return 32 for arbitrary words; unreachable from contract bodies anyway since the macro gate rejects non-dynamic values and bytes32 has no ABI length word) - Add `ArrayLength String` (utf8ByteSize = ABI length-word semantics); string members pass the same macro projection gate as bytes - Extend smoke with String-member case; normalize formatting - Commit generated PropertyArrayElementDynamicMemberBytesSmoke.t.sol (the missing artifact that failed `checks` on #1991) - Document bytes/string arrayLength in edsl-api-reference
f449a7a to
0a78f9d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Supersedes #1991 (thanks @poonai — your commit is included as-is, you're a co-author of this PR). This lands
arrayLengthsupport forbytes/stringdynamic values at the executable level, plus the CI fix and a small architecture review pass.What's included
poonai's commit (cherry-picked, authorship preserved):
ArrayLengthtypeclass inContracts/Common.leansoarrayLengthaccepts non-Arraydynamic values.ArrayElementDynamicMemberBytesSmokecoveringarrayLength ops.callData(struct param member) andarrayLength (arrayElement ops idx).callData(struct-array element member).Follow-up commit (review findings):
Bytes32instance.Verity.Bytes32is a reducible abbrev ofUint256, soinstance : ArrayLength Bytes32 := 32silently madearrayLength (x : Uint256)typecheck and return32for every word value — a spec-level footgun. It was also unreachable from contract bodies: the macro type gate (Verity/Macro/Translate/Expr.lean) rejectsarrayLengthon non-dynamic named values, andbytes32carries no ABI length word. Documented the decision in a docstring.Stringinstance (String.utf8ByteSize)..stringdynamic members pass the exact same macro gate (paramDynamicMemberProjection?accepts.array | .bytes | .string), so without it the string analogue of the fixed case still failed executable elaboration.utf8ByteSizematches the EVM ABI length-word semantics (byte length, not codepoints).String-member case (labelLength, assertingparamDynamicMemberLength "ops" 1) and normalized formatting to matchArrayElementDynamicMemberLengthSmoke.PropertyArrayElementDynamicMemberBytesSmoke.t.sol(the missing artifact that failedcheckson make array length work for Bytes and Bytes32 #1991) viascripts/check_macro_property_test_generation.py.docs-site/content/edsl-api-reference.mdxdynamic-arrays section now documentsarrayLengthonBytes/Stringmembers, the lowering path, and why fixed-width word types intentionally have no length surface.Verification
make checkpasses locally (including the macro property-test artifact check — the job that failed on make array length work for Bytes and Bytes32 #1991).lake build Contracts.Smoke.ArrayElementDynamicMemberBytesSmokewas still running when this PR was opened; CI is the authority for the Lean compilation of the smokerflexamples and the executable elaboration through the new instances.Relation to issues
This is an EDSL-surface primitive on the dynamic-ABI track (#1982 P0-1). It does not close #1975 (struct-array calldata decoding), which needs ABI head/tail lowering in codegen.
Note
Low Risk
EDSL executable/runtime surface and tests/docs only; no auth or on-chain behavior changes, and the Bytes32 removal reduces incorrect typechecking risk.
Overview
Replaces the old
arrayLengthonArray αonly with anArrayLengthtypeclass so executable Lean code can take byte length fromByteArray,String(utf8ByteSize), andArray α, matching ABI length-word semantics for dynamic types.Deliberately omits a
Bytes32instance soarrayLengthcannot typecheck on arbitrary words (sinceBytes32abbreviatesUint256).Adds
ArrayElementDynamicMemberBytesSmokewithrflproofs thatarrayLengthon structbytes/stringmembers and on(arrayElement ops idx).callDatalowers toparamDynamicMemberLength/arrayElementDynamicMemberLength. Commits the generated Solidity property-test stub for CI. Docs now describe member-levelarrayLengthand why fixed-width words have no length surface.Reviewed by Cursor Bugbot for commit 0a78f9d. Bugbot is set up for automated code reviews on this repo. Configure here.