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

feat(sequencer, bridge-withdrawer)!: enforce withdrawals consumed #1391

Merged
merged 23 commits into from
Aug 29, 2024

Conversation

joroshiba
Copy link
Member

@joroshiba joroshiba commented Aug 22, 2024

Summary

Adds state for bridge events and consumes the events as they occur. Updates proto for bridge unlock to no longer use memo for rollup information and instead include on main action. Renames rollup_transaction_hash to rollup_withdrawal_event_id.

Background

There was only implicit stop against reusing a withdrawal event, this adds consumption of withdrawal events. While this is not strictly security enhancing, consuming the event adds in protocol protection against accidental double spend by the bridge operator.

Changes

  • Proto updates for BridgeUnlockAction + ICS20WithdrawalMemo
  • Add stateless checks on bridging unlock and withdrawals of correct information filled out
  • Added state to enforce rollup event cannot be consumed twice.
  • Enforce that Ics20WithdrawalAction must have bridge_address set if making a bridge withdrawal

Testing

smoke test + minor test updates

Breaking Changelist

  • New stateful information about rollup withdrawal events
  • Adds new fields to BridgeUnlockAction

Related Issues

closes #1430

@github-actions github-actions bot added proto pertaining to the Astria Protobuf spec sequencer pertaining to the astria-sequencer crate labels Aug 22, 2024
@joroshiba joroshiba marked this pull request as ready for review August 28, 2024 00:14
@joroshiba joroshiba requested review from a team, SuperFluffy and noot as code owners August 28, 2024 00:14
Copy link
Contributor

@Fraser999 Fraser999 left a comment

Choose a reason for hiding this comment

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

Mostly nitpicks, but one issue in bridge/state_ext.rs causing the rollup block height to not be parsed correctly. Not blocking the PR though since the actual value isn't critical to the flow, only whether it exists in storage or not.

crates/astria-bridge-contracts/src/lib.rs Outdated Show resolved Hide resolved
crates/astria-sequencer/src/bridge/bridge_unlock_action.rs Outdated Show resolved Hide resolved
crates/astria-sequencer/src/bridge/bridge_unlock_action.rs Outdated Show resolved Hide resolved
crates/astria-sequencer/src/bridge/bridge_unlock_action.rs Outdated Show resolved Hide resolved
crates/astria-sequencer/src/bridge/bridge_unlock_action.rs Outdated Show resolved Hide resolved
@@ -106,6 +112,37 @@ async fn establish_withdrawal_target<S: StateRead>(
impl ActionHandler for action::Ics20Withdrawal {
async fn check_stateless(&self) -> Result<()> {
ensure!(self.timeout_time() != 0, "timeout time must be non-zero",);
ensure!(self.amount() > 0, "amount must be greater than zero",);
if self.bridge_address.is_some() {
let parsed_bridge_memo: Ics20WithdrawalFromRollupMemo =
Copy link
Contributor

Choose a reason for hiding this comment

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

We're JSON-encoding a PB version of this type, whereas here we're decoding straight into our domain type. The serde try_from = "raw::Ics20WithdrawalFromRollup" on the domain type handles that ok, but I still keep feeling uneasy when I see this.

Copy link
Member Author

Choose a reason for hiding this comment

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

I could either remove the domain type or modify the serialization on the other end, it uses the pb::name property when serializing for errors which is why it uses the raw type

Copy link
Contributor

Choose a reason for hiding this comment

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

It's certainly not a blocker, and maybe I'm being overly pedantic. But I guess I'd prefer if the domain type didn't derive serde traits, forcing us to always use the pb type for encoding to/decoding from JSON, and we use the domain type in the business logic.

No probs if you prefer to leave as is - I think we're doing similar things elsewhere. We can always try and get more strict on the separation of pb and domain types in the future.

Copy link
Member Author

Choose a reason for hiding this comment

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

I went ahead and went back to how the memos were defined in domain type as reexporting, less code changes here a bit cleaner I think.

Copy link
Member

Choose a reason for hiding this comment

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

IMO this check_stateless (and the other deseriailzation in check_and_execute) shows that using validated domain types that establish invariants is preferable over doing the validation here.

Copy link
Member Author

Choose a reason for hiding this comment

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

I have created an issue here for follow up

crates/astria-sequencer/src/ibc/ics20_withdrawal.rs Outdated Show resolved Hide resolved
crates/astria-sequencer/src/ibc/ics20_withdrawal.rs Outdated Show resolved Hide resolved
crates/astria-sequencer/src/ibc/ics20_withdrawal.rs Outdated Show resolved Hide resolved
crates/astria-sequencer/src/ibc/ics20_withdrawal.rs Outdated Show resolved Hide resolved
Co-authored-by: Fraser Hutchison <[email protected]>
Copy link
Member

@SuperFluffy SuperFluffy left a comment

Choose a reason for hiding this comment

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

Everything in this PR seems fine. I am still blocking this because I am uneasy about the keys used to put the events into state (see the comment there).

crates/astria-sequencer/src/ibc/ics20_transfer.rs Outdated Show resolved Hide resolved
transaction::StateReadExt as _,
};

#[async_trait::async_trait]
impl ActionHandler for BridgeUnlockAction {
async fn check_stateless(&self) -> Result<()> {
ensure!(self.amount > 0, "amount must be greater than zero",);
Copy link
Member

Choose a reason for hiding this comment

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

What would be so bad if it was 0?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's just kinda pointless? I would prefer not wasting compute time on pointless actions :)

crates/astria-sequencer/src/ibc/ics20_withdrawal.rs Outdated Show resolved Hide resolved
@@ -106,6 +112,37 @@ async fn establish_withdrawal_target<S: StateRead>(
impl ActionHandler for action::Ics20Withdrawal {
async fn check_stateless(&self) -> Result<()> {
ensure!(self.timeout_time() != 0, "timeout time must be non-zero",);
ensure!(self.amount() > 0, "amount must be greater than zero",);
if self.bridge_address.is_some() {
let parsed_bridge_memo: Ics20WithdrawalFromRollupMemo =
Copy link
Member

Choose a reason for hiding this comment

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

IMO this check_stateless (and the other deseriailzation in check_and_execute) shows that using validated domain types that establish invariants is preferable over doing the validation here.

crates/astria-sequencer/src/ibc/ics20_withdrawal.rs Outdated Show resolved Hide resolved
crates/astria-sequencer/src/bridge/state_ext.rs Outdated Show resolved Hide resolved
Copy link
Member

@SuperFluffy SuperFluffy left a comment

Choose a reason for hiding this comment

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

Discussed offline: BridgeUnlockAction::check_and_execute contains a check that no event with a given ID was previously processed, so a second action would not be able to overwrite the first. That addresses my issue.

Approving.

crates/astria-sequencer/src/bridge/bridge_unlock_action.rs Outdated Show resolved Hide resolved
Co-authored-by: Richard Janis Goldschmidt <[email protected]>
@joroshiba joroshiba added this pull request to the merge queue Aug 29, 2024
Merged via the queue into main with commit 9f61870 Aug 29, 2024
45 checks passed
@joroshiba joroshiba deleted the joroshiba/start-event-consumption branch August 29, 2024 20:05
steezeburger added a commit that referenced this pull request Sep 3, 2024
* main:
  chore: ibc e2e smoke test (#1284)
  chore(metrics): restrict `metrics` crate usage to `astria-telemetry` (#1192)
  fix(charts)!: sequencer-relayer chart correct startup env var (#1437)
  chore(bridge-withdrawer): Add instrumentation (#1324)
  chore(conductor): Add instrumentation (#1330)
  fix(cli, bridge-withdrawer): dont fail entire block due to bad withdraw event (#1409)
  feat(sequencer, bridge-withdrawer)!: enforce withdrawals consumed (#1391)
jbowen93 pushed a commit that referenced this pull request Sep 3, 2024
)

## Summary
Adds state for bridge events and consumes the events as they occur.
Updates proto for bridge unlock to no longer use memo for rollup
information and instead include on main action. Renames
`rollup_transaction_hash` to `rollup_withdrawal_event_id`.

## Background
There was only implicit stop against reusing a withdrawal event, this
adds consumption of withdrawal events. While this is not strictly
security enhancing, consuming the event adds in protocol protection
against accidental double spend by the bridge operator.

## Changes
- Proto updates for `BridgeUnlockAction` + `ICS20WithdrawalMemo`
- Add stateless checks on bridging unlock and withdrawals of correct
information filled out
- Added state to enforce rollup event cannot be consumed twice. 
- Enforce that `Ics20WithdrawalAction` must have `bridge_address` set if
making a bridge withdrawal

## Testing
smoke test + minor test updates

## Breaking Changelist
- New stateful information about rollup withdrawal events
- Adds new fields to `BridgeUnlockAction`

## Related Issues
closes #1430

---------

Co-authored-by: Fraser Hutchison <[email protected]>
Co-authored-by: Richard Janis Goldschmidt <[email protected]>
jbowen93 pushed a commit that referenced this pull request Sep 6, 2024
)

## Summary
Adds state for bridge events and consumes the events as they occur.
Updates proto for bridge unlock to no longer use memo for rollup
information and instead include on main action. Renames
`rollup_transaction_hash` to `rollup_withdrawal_event_id`.

## Background
There was only implicit stop against reusing a withdrawal event, this
adds consumption of withdrawal events. While this is not strictly
security enhancing, consuming the event adds in protocol protection
against accidental double spend by the bridge operator.

## Changes
- Proto updates for `BridgeUnlockAction` + `ICS20WithdrawalMemo`
- Add stateless checks on bridging unlock and withdrawals of correct
information filled out
- Added state to enforce rollup event cannot be consumed twice. 
- Enforce that `Ics20WithdrawalAction` must have `bridge_address` set if
making a bridge withdrawal

## Testing
smoke test + minor test updates

## Breaking Changelist
- New stateful information about rollup withdrawal events
- Adds new fields to `BridgeUnlockAction`

## Related Issues
closes #1430

---------

Co-authored-by: Fraser Hutchison <[email protected]>
Co-authored-by: Richard Janis Goldschmidt <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proto pertaining to the Astria Protobuf spec sequencer pertaining to the astria-sequencer crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

refactor stateless checks to be done on types with withdrawals
3 participants