Skip to content

Conversation

@temaniarpit27
Copy link
Contributor

🔄 Changes Summary

  • Add tests for backward and forward let

🐞 Issues

🔗 Related PRs

Stefan-Ethernal and others added 30 commits December 12, 2025 07:09
## 🔄 Changes Summary
This PR adds a function to rewind merkle tree to a previous root index.
(This will be used for backwarding of `LocalExitTree`).

## ⚠️ Breaking Changes
NA

## 📋 Config Updates
NA

## ✅ Testing
- 🤖 **Automatic**: `aggkit` CI
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Contributor

Copilot AI left a comment

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 adds support for testing backward and forward Last Exit Tree (LET) operations by adjusting the deposit count semantics to use 1-indexed counting in events while maintaining 0-indexed internal storage.

  • Modified processor logic to subtract 1 from event deposit counts when processing BackwardLET and ForwardLET events
  • Updated test data to use 1-indexed deposit counts (deposit counts in events are now 1 higher than before)
  • Enhanced error handling for Kurtosis artifact downloads with detailed troubleshooting information
  • Updated E2E workflow to use newer commit references

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
bridgesync/processor.go Adjusted BackwardLET and ForwardLET deposit count handling to subtract 1 from event values to convert from 1-indexed to 0-indexed internal representation
bridgesync/processor_test.go Updated test data to use 1-indexed deposit counts; removed unused math import and test cases for overlapping BackwardLET and invalid deposit count validation
scripts/local_config_helper Added dynamic artifact name construction, enhanced error messages for artifact downloads, and renamed variable from zkevm_rollup_chain_id to l2_chain_id
test/run-local-e2e.sh Fixed shell pattern to avoid matching bare -, corrected ENCLAVE_NAME for pessimistic tests, commented out tests except for backward/forward LET test with filter
.github/workflows/test-e2e.yml Updated agglayer-e2e-ref commit hashes to newer version
.github/test_e2e_op_args_base.json Enabled deploy_cdk_bridge_infra flag

@temaniarpit27 temaniarpit27 requested a review from rachit77 January 9, 2026 05:35
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

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

single-l2-network-op-succinct)
bats ./tests/aggkit/bridge-e2e.bats || exit 1
bats ./tests/aggkit/e2e-pp.bats || exit 1
bats ./tests/aggkit/bridge-sovereign-chain-e2e.bats || exit 1
Copy link

Copilot AI Jan 10, 2026

Choose a reason for hiding this comment

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

The removal of bats ./tests/aggkit/e2e-pp.bats test execution in the single-l2-network-op-succinct test type appears unrelated to the stated purpose of this PR (adding tests for backward and forward LET). This removal reduces test coverage for the op-succinct configuration. If this test is now obsolete or has been moved, this should be documented in the PR description. Otherwise, this appears to be an accidental deletion that reduces test coverage.

Copilot uses AI. Check for mistakes.
Comment on lines +245 to +246
# Extract service number from AGGKIT_SERVICE (e.g., aggkit-001 -> 001)
local SERVICE_NUMBER=$(echo "$AGGKIT_SERVICE" | sed 's/.*-//')
Copy link

Copilot AI Jan 10, 2026

Choose a reason for hiding this comment

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

The artifact name construction uses sed 's/.*-//' to extract the service number, which assumes the service name always ends with a hyphen followed by the number. This could fail if the AGGKIT_SERVICE variable has a different format (e.g., no hyphen, multiple hyphens in unexpected places, or trailing text after the number). Consider using a more robust pattern like sed -n 's/.*-\([0-9]\+\)$/\1/p' to ensure only numeric suffixes are extracted, or validate the format before extraction.

Suggested change
# Extract service number from AGGKIT_SERVICE (e.g., aggkit-001 -> 001)
local SERVICE_NUMBER=$(echo "$AGGKIT_SERVICE" | sed 's/.*-//')
# Extract numeric service number from AGGKIT_SERVICE (e.g., aggkit-001 -> 001)
local SERVICE_NUMBER
SERVICE_NUMBER=$(echo "$AGGKIT_SERVICE" | sed -n 's/.*-\([0-9]\+\)$/\1/p')
if [ -z "$SERVICE_NUMBER" ]; then
log_fatal "AGGKIT_SERVICE ('$AGGKIT_SERVICE') must end with a numeric suffix like 'aggkit-001'"
fi

Copilot uses AI. Check for mistakes.
}

newDepositCount := uint32(event.PreviousDepositCount.Uint64()) + 1
newDepositCount := uint32(event.PreviousDepositCount.Uint64())
Copy link

Copilot AI Jan 10, 2026

Choose a reason for hiding this comment

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

The change from uint32(event.PreviousDepositCount.Uint64()) + 1 to uint32(event.PreviousDepositCount.Uint64()) appears to change the semantics of how deposit counts are interpreted. This is a critical change that affects how bridges are indexed. The PreviousDepositCount now directly becomes the newDepositCount, rather than being incremented. Ensure this is the correct interpretation according to the contract's event semantics and that all consumers of this field are aware of this change in behavior.

Suggested change
newDepositCount := uint32(event.PreviousDepositCount.Uint64())
newDepositCount := uint32(event.PreviousDepositCount.Uint64()) + 1

Copilot uses AI. Check for mistakes.
Comment on lines +1408 to +1413
prev, err := aggkitcommon.SafeUint64(new(big.Int).Sub(backwardLET.PreviousDepositCount, big.NewInt(1)))
if err != nil {
return fmt.Errorf("invalid previous deposit count: %w", err)
}

next, err := aggkitcommon.SafeUint64(backwardLET.NewDepositCount)
next, err := aggkitcommon.SafeUint64(new(big.Int).Sub(backwardLET.NewDepositCount, big.NewInt(1)))
Copy link

Copilot AI Jan 10, 2026

Choose a reason for hiding this comment

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

The subtraction of 1 from both PreviousDepositCount and NewDepositCount in BackwardLET processing represents a significant semantic change. The adjustment is applied before converting to uint64 and storing in the database. This appears to change the interpretation of deposit counts from the contract events. Verify that this adjustment correctly aligns with the updated contract specification and that the query deposit_count > $1 AND deposit_count <= $2 in the restore logic still works correctly with the adjusted values.

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you explain why we are decreasing the (previous and next) deposit counts by one? I fail to understand the logic.

Comment on lines +1593 to +1594
adjustedCount := new(big.Int).Sub(event.BackwardLET.NewDepositCount, big.NewInt(1))
newDepositCount, leafIndex, err := normalizeDepositCount(adjustedCount)
Copy link

Copilot AI Jan 10, 2026

Choose a reason for hiding this comment

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

The adjustment of NewDepositCount by subtracting 1 before calling normalizeDepositCount changes the interpretation of BackwardLET events. This adjustment will affect which bridges are archived and deleted, as it changes the threshold value passed to archiveAndDeleteBridgesAbove. Ensure this aligns with the contract's actual behavior and that the corresponding forward LET handling has been updated consistently.

Suggested change
adjustedCount := new(big.Int).Sub(event.BackwardLET.NewDepositCount, big.NewInt(1))
newDepositCount, leafIndex, err := normalizeDepositCount(adjustedCount)
newDepositCount, leafIndex, err := normalizeDepositCount(event.BackwardLET.NewDepositCount)

Copilot uses AI. Check for mistakes.
},
processBlockErrMsg: "invalid deposit count: value=4294967296 exceeds uint32 max",
},
{
Copy link

Copilot AI Jan 10, 2026

Choose a reason for hiding this comment

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

The removal of test cases for invalid deposit counts (negative values and values exceeding uint32 range) eliminates important edge case testing. These tests verified that the system properly handles malformed or invalid contract events. Without these tests, there's no verification that the system will reject or properly handle invalid deposit count values that could potentially be emitted from a compromised or buggy contract. Consider keeping these tests or replacing them with equivalent validation tests that work with the new deposit count interpretation.

Copilot uses AI. Check for mistakes.
targetDepositCount: 8,
skipBlocks: []uint64{2, 3}, // all the bridges from these blocks were backwarded
archivedDepositCounts: []uint32{3, 4, 5},
},
Copy link

Copilot AI Jan 10, 2026

Choose a reason for hiding this comment

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

The removal of the "overlapping backward let events" test case removes coverage for an important scenario where multiple BackwardLET events might interact. This test case verified that the system correctly handles consecutive BackwardLET events that operate on overlapping deposit count ranges. Without this test, there's less confidence that the refactored deposit count handling correctly manages these complex scenarios. Consider whether this scenario is still relevant with the new deposit count interpretation and, if so, restore or replace this test case.

Copilot uses AI. Check for mistakes.
Comment on lines +1408 to +1413
prev, err := aggkitcommon.SafeUint64(new(big.Int).Sub(backwardLET.PreviousDepositCount, big.NewInt(1)))
if err != nil {
return fmt.Errorf("invalid previous deposit count: %w", err)
}

next, err := aggkitcommon.SafeUint64(backwardLET.NewDepositCount)
next, err := aggkitcommon.SafeUint64(new(big.Int).Sub(backwardLET.NewDepositCount, big.NewInt(1)))
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you explain why we are decreasing the (previous and next) deposit counts by one? I fail to understand the logic.

}

newDepositCount, leafIndex, err := normalizeDepositCount(event.BackwardLET.NewDepositCount)
adjustedCount := new(big.Int).Sub(event.BackwardLET.NewDepositCount, big.NewInt(1))
Copy link
Contributor

Choose a reason for hiding this comment

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

Does the NewDepositCount get decremented by 1, because leaf with the index NewDepositCount gets rollbacked from the tree as well?

If that's the case, would it make more sense if we would delete all the nodes that has the index greater than or equal to NewDepositCount (also adjust the comments of the functions), instead of decrementing. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so basically what smart contract emits is deposit count which is 1 indexed (starts from 1 and not 0)
we here consider deposit count related to bridges which is 0 indexed (starts from 0)
so we need to manage accordingly here

@sonarqubecloud
Copy link

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.

Testing bats

5 participants