Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: optimize gas usage #4

Open
wants to merge 1 commit into
base: feat/v0.2.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/evm/contracts/adapters/Spectre/SpectreAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ contract SpectreAdapter is AccessControl, BlockHashAdapter {
);

if (!parsedReceipt.isValid) revert ErrorParseReceipt();
if (bytes32(parsedReceipt.topics[0]) != MESSAGE_DISPATCHED_EVENT_SIG) revert InvalidEventSignature();
if (parsedReceipt.topics[0] != MESSAGE_DISPATCHED_EVENT_SIG) revert InvalidEventSignature();
if (parsedReceipt.eventSource != SOURCE_YAHO) revert InvalidEventSource();

uint256 messageId = uint256(parsedReceipt.topics[1]);
Expand Down
16 changes: 1 addition & 15 deletions packages/evm/contracts/adapters/Spectre/lib/Merkle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ library Merkle {
index = concatGindices(receiptGindexes);
} else if (lcSlot - txSlot > SLOTS_PER_HISTORICAL_ROOT) {
revert("txSlot lags by >8192 blocks. Not supported.");
} else {
revert("txSlot can't be greater than lightclient slot");
}

bytes32 computedRoot = restoreMerkleRoot(receiptsRootBranch, receiptsRoot, calculateIndex(index));
Expand All @@ -75,9 +73,6 @@ library Merkle {
}

function bitLength(uint256 number) internal pure returns (uint256) {
if (number == 0) {
return 0;
}
uint256 length = 0;
while (number > 0) {
length++;
Expand All @@ -87,16 +82,7 @@ library Merkle {
}

function calculateArrayGindex(uint256 elementIndex) internal pure returns (uint256) {
uint256 gindex = 1;
uint256 depth = 0;
while ((1 << depth) < SLOTS_PER_HISTORICAL_ROOT) {
depth++;
}

for (uint256 d = 0; d < depth; d++) {
gindex = (gindex << 1) | ((elementIndex >> (depth - d - 1)) & 1);
}
return gindex;
return SLOTS_PER_HISTORICAL_ROOT + (elementIndex % SLOTS_PER_HISTORICAL_ROOT);
}

function calculateIndex(uint256 gindex) internal pure returns (uint256 index) {
Expand Down
2 changes: 1 addition & 1 deletion packages/evm/contracts/adapters/Spectre/lib/Receipt.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ library Receipt {
// memory pointer to the RLP Receipt
uint256 memPtr;
assembly {
memPtr := add(value, add(0x20, mul(0x01, offset)))
memPtr := add(value, add(0x20, offset))
}

// read Receipt as a list of RLPItem
Expand Down