ethereum-optimism / ethereum-optimism/optimism
Assembly block optimization
- Dominant language
- Go
- Stars
- 6.5k
- Forks
- 4k
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 145
Description
**Description**:
The referenced assembly lines can be replaced with the following, to use half the number of instructions:
```
datLen = mul(datLen, 8) // operate in bits from now on
let rightPaddingBits = sub(mul(space, 8), datLen))
dat := shr(sub(256, datLen), dat) // right-align data
dat := shl(rightPaddingBits, dat) // position data to insert into memory word
// mask of where data should be written to the memory word
let mask := sub(shl(datLen, 1), 1)
mask := shl(rightPaddingBits, mask)
```
[packages/contracts-bedrock/src/cannon/libraries/MIPS64Syscalls.sol](https://cantina.xyz/code/4ea41142-4359-4f62-bfaa-a542172cab5d/packages/contracts-bedrock/src/cannon/libraries/MIPS64Syscalls.sol#L277-L285)
```
dat := shr(sub(256, mul(datLen, 8)), dat) // right-align data
// position data to insert into memory word
dat := shl(mul(sub(sub(WORD_SIZE_BYTES, datLen), alignment), 8), dat)
// mask all bytes after start
let mask := sub(shl(mul(sub(WORD_SIZE_BYTES, alignment), 8), 1), 1)
// mask of all bytes
let suffixMask := sub(shl(mul(sub(sub(WORD_SIZE_BYTES, alignment), datLen), 8), 1), 1)
// starting from end, maybe none
mask := and(mask, not(suffixMask)) // reduce mask to just cover the data we insert
```
Contributor guide
Research direction
Read packages/contracts-bedrock/src/cannon/libraries/MIPS64Syscalls.sol around lines 277-285 and compare the existing assembly with the proposed instruction sequence. Verify the replacement preserves data alignment, padding, and masking behavior, then run the relevant contract test suite to confirm the optimized block is correct.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- solidity
- Domain
- blockchain
- Issue type
- Refactor
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 52/100