Skip to content

Optimize contracts#123

Merged
RogerPodacter merged 2 commits into
evm-backend-demofrom
optimize
Oct 17, 2025
Merged

Optimize contracts#123
RogerPodacter merged 2 commits into
evm-backend-demofrom
optimize

Conversation

@RogerPodacter

@RogerPodacter RogerPodacter commented Oct 17, 2025

Copy link
Copy Markdown
Member

Note

Flattens on-chain Ethscription storage (removes nested ContentInfo and mediaType/mimeSubtype), updates ABI/calldata, renderer, prover, genesis script, Ruby readers/validator, and tests; also enforces a max mimetype length.

  • Contracts (Solidity):
    • Ethscriptions.sol: Flatten Ethscription (promote contentUriHash, contentSha, mimetype, esip6; add l1BlockHash; pack uint48 fields); remove ContentInfo and all mediaType/mimeSubtype usage; update getters, content lookups, event emission, and storage writes.
    • Renderer Lib: Use etsc.mimetype and flattened hashes; drop media/subtype attributes; adjust attribute JSON and media URI logic.
    • Prover: Compact proof structs to uint48 fields; include l1BlockHash; read flattened fields.
    • Genesis script: Write flattened fields in createGenesisEthscription; remove media/subtype params; parse JSON without them.
    • Scripts/Tests: Remove mediaType/mimeSubtype from CreateEthscriptionParams usage and assertions; update expected attributes (fewer traits) and field accessors.
  • Ruby Backend:
    • ethscription_transaction.rb: Update function signature and ABI encoding for createEthscription (no media/subtype); add MAX_MIMETYPE_LENGTH and truncate mimetype.
    • storage_reader.rb: Switch ABI decoding to flattened struct/uint48 fields and indexes; update get_ethscription_with_content/get_ethscription to return flattened fields; remove media/subtype outputs.
    • block_validator.rb: Stop validating media_type/mime_subtype; note they’re derived; continue mimetype/esip6 checks.
  • Events/Calldata:
    • Update function selector strings and ABI tuples to (bytes32,bytes32,address,bytes,string,bool,(string,string,bytes)) for create; fix event emission to use flattened contentUriHash/contentSha.

Written by Cursor Bugbot for commit 33c8891. This will update automatically on new commits. Configure here.

@RogerPodacter RogerPodacter requested a review from Copilot October 17, 2025 19:08

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request optimizes the contract structure by flattening the nested ContentInfo struct into the main Ethscription struct and reduces field sizes from uint256 to uint48 where appropriate. This improves gas efficiency by reducing storage slots and eliminating redundant nested structure access.

  • Flattened ContentInfo fields directly into the Ethscription struct
  • Changed numeric field types from uint256/uint64 to uint48 for gas optimization
  • Removed mediaType and mimeSubtype fields from storage, now derived from mimetype at runtime

Reviewed Changes

Copilot reviewed 24 out of 24 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
lib/storage_reader.rb Updates ABI decoding to match flattened struct and derives media_type/mime_subtype from mimetype
lib/block_validator.rb Removes validation for media_type and mime_subtype fields that are no longer stored
contracts/src/Ethscriptions.sol Flattens ContentInfo into Ethscription struct and optimizes field sizes
contracts/src/EthscriptionsProver.sol Updates struct fields to use uint48 types and adjusts field access patterns
contracts/src/libraries/EthscriptionsRendererLib.sol Updates field access to use flattened struct fields
app/models/ethscription_transaction.rb Removes media_type and mime_subtype from calldata construction
contracts/test/*.sol Updates test files to remove mediaType and mimeSubtype parameters
contracts/script/*.sol Updates script files to match new struct format

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +33 to +34
uint48 createdAt;
uint48 l1BlockNumber;

Copilot AI Oct 17, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using uint48 for timestamps and block numbers may cause overflow issues. Block numbers and timestamps can exceed the uint48 maximum value (281,474,976,710,655). Consider using uint64 or keeping uint256 for these critical fields to prevent future overflow.

Copilot uses AI. Check for mistakes.
Comment on lines +23 to +25
uint48 l2BlockNumber;
uint48 l2BlockTimestamp;
uint48 l1BlockNumber;

Copilot AI Oct 17, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using uint48 for block numbers and timestamps risks overflow. Ethereum block numbers and timestamps will eventually exceed uint48's maximum value of ~281 trillion. This could cause silent overflow and incorrect data storage.

Copilot uses AI. Check for mistakes.
Comment thread lib/storage_reader.rb Outdated

# Derive media_type and mime_subtype from mimetype
mimetype = ethscription_data[6] # mimetype is at index 6
media_type, mime_subtype = mimetype.split('/', 2) if mimetype

Copilot AI Oct 17, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The split method uses 2 as the limit parameter, but this should be at most 2 parts for a mimetype (e.g., 'text/plain'). Using split('/', 2) correctly limits to 2 parts, but consider using just split('/') or adding validation that exactly 2 parts exist.

Suggested change
media_type, mime_subtype = mimetype.split('/', 2) if mimetype
if mimetype
parts = mimetype.split('/')
if parts.size == 2
media_type, mime_subtype = parts
else
media_type = nil
mime_subtype = nil
end
end

Copilot uses AI. Check for mistakes.
mimetype = data_uri.mimetype.to_s
media_type = mimetype&.split('/')&.first
mime_subtype = mimetype&.split('/')&.last
mimetype = data_uri.mimetype.to_s.first(MAX_MIMETYPE_LENGTH)

Copilot AI Oct 17, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first method on String returns the first character, not the first N characters. Use [0, MAX_MIMETYPE_LENGTH] or truncate(MAX_MIMETYPE_LENGTH, omission: '') instead to limit the mimetype length properly.

Suggested change
mimetype = data_uri.mimetype.to_s.first(MAX_MIMETYPE_LENGTH)
mimetype = data_uri.mimetype.to_s[0, MAX_MIMETYPE_LENGTH]

Copilot uses AI. Check for mistakes.
@RogerPodacter

Copy link
Copy Markdown
Member Author

bugbot run

cursor[bot]

This comment was marked as outdated.

@RogerPodacter RogerPodacter merged commit d970ae2 into evm-backend-demo Oct 17, 2025
2 checks passed
@RogerPodacter RogerPodacter deleted the optimize branch October 17, 2025 19:19
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.

2 participants