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

Fix obj-caps facility #2018

Closed
wants to merge 45 commits into from
Closed

Fix obj-caps facility #2018

wants to merge 45 commits into from

Conversation

hu55a1n1
Copy link
Member

@hu55a1n1 hu55a1n1 commented Mar 27, 2022

Closes: cosmos/ibc-rs#53

Description


PR author checklist:

  • Added changelog entry, using unclog.
  • Added tests: integration (for Hermes) or unit/mock tests (for modules).
  • Linked to GitHub issue.
  • Updated code comments and documentation (e.g., docs/).

Reviewer checklist:

  • Reviewed Files changed in the GitHub PR explorer.
  • Manually tested (in case integration/unit/mock tests are absent).

@hu55a1n1 hu55a1n1 changed the base branch from master to hu55a1n1/1758-complete-ics26 March 27, 2022 20:53
Base automatically changed from hu55a1n1/1758-complete-ics26 to master April 4, 2022 17:43
@hu55a1n1 hu55a1n1 force-pushed the hu55a1n1/2013-improve-obj-caps branch from c4d31de to 7fe7da1 Compare April 6, 2022 05:54
Copy link
Member Author

@hu55a1n1 hu55a1n1 left a comment

Choose a reason for hiding this comment

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

Adding some comments to help describe the main changes in this PR and the rationale for some design choices.

}

pub trait CapabilityReader {
pub trait CapabilityReader<M: Into<ModuleId>> {
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the main change in this PR. CapabilityReader and CapabilityKeeper are now generic over ModuleId. This follows from the intuition that they are always scoped to a module and the library never makes calls to the underlying host system's (unscoped) CapabilityReader.
I experimented with two other designs - one with a composition style approach (see ec20b5a) and another with a freestanding CapabilityReader with a blanket scoped implementation, but both those designs proved to be unwieldy. The benefit of this approach is that it makes the least assumptions on the host's capability system and allows users to write a blanket implementation for all modules.

}
}

pub trait PortKeeper: CapabilityKeeper + PortReader {
pub trait PortCapabilityKeeper<M: Into<ModuleId>>:
Copy link
Member Author

@hu55a1n1 hu55a1n1 Apr 13, 2022

Choose a reason for hiding this comment

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

PortCapabilityKeeper and ChannelCapabilityKeeper have been extracted out of Port/ChannelKeeper. These traits only have provided methods and are provided for convenience.

@@ -37,6 +37,7 @@ pub enum Path {
Connections(ConnectionsPath),
Ports(PortsPath),
ChannelEnds(ChannelEndsPath),
ChannelCapability(ChannelCapabilityPath),
Copy link
Member Author

Choose a reason for hiding this comment

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

This is a new Path that defines a key for the channel capability in the persistent store.

@@ -31,9 +44,12 @@ pub trait Ics26Context:
+ ConnectionKeeper
+ ChannelKeeper
+ ChannelReader
+ PortReader
+ ChannelCapabilityKeeper<CoreModuleId, Capability = <Self as Ics26Context>::Capability>
Copy link
Member Author

Choose a reason for hiding this comment

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

All Capability related keepers that the Ics26Context depends on, are scoped to the CoreModule and all associated Capability types are bound to be the same.

fn from(index: u64) -> Self {
Self { index }
}
pub trait Capability {
Copy link
Member Author

Choose a reason for hiding this comment

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

Capability is a trait now so the host system is free to define it's own non-forgeable and secure Capability type.

@@ -125,14 +136,18 @@ pub(crate) fn process(
// Transition the channel end to the new state & pick a version.
new_channel_end.set_state(State::TryOpen);

let (channel_id_state, channel_cap) = if msg.previous_channel_id.is_none() {
Copy link
Member Author

@hu55a1n1 hu55a1n1 Apr 13, 2022

Choose a reason for hiding this comment

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

We only create a new capability if a previous_channel_id isn't specified.

Self::new(
ChainId::new("mockgaia".to_string(), 0),
HostType::Mock,
5,
Height::new(0, 5),
)
.with_router(dummy_router(ocap.clone()))
Copy link
Member Author

Choose a reason for hiding this comment

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

The default implementation now comes with a dummy_router() and an ocap system where the default port is already owned by the DummyModule. This setup simplifies handler tests.

}
}

impl Clone for MockContext {
Copy link
Member Author

Choose a reason for hiding this comment

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

We manually implement Clone because ocap is a pointer. This implementation sets up the ocap pointer to it's initial state as per the Default impl.

@@ -365,7 +424,27 @@ impl MockContext {
channel_end: ChannelEnd,
) -> Self {
let mut channels = self.channels.clone();
channels.insert((port_id, chan_id), channel_end);
channels.insert((port_id.clone(), chan_id), channel_end);
let (module_id, _) = self
Copy link
Member Author

Choose a reason for hiding this comment

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

Adding a channel automatically creates a new associated capability and is claimed by the module that owns the port capability.

@@ -124,19 +128,60 @@ pub struct MockContext {

/// ICS26 router impl
router: MockRouter,

/// Object capabilites impl
ocap: Arc<Mutex<MockOCap>>,
Copy link
Member Author

Choose a reason for hiding this comment

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

This must be shared across modules, hence the Arc<Mutex<>>

@hu55a1n1 hu55a1n1 marked this pull request as ready for review April 13, 2022 10:40
@@ -32,7 +32,8 @@ pub fn send_packet(ctx: &dyn ChannelReader, packet: Packet) -> HandlerResult<Pac
return Err(Error::channel_closed(packet.source_channel));
}

let _channel_cap = ctx.authenticated_capability(&packet.source_port)?;
// Fixme(hu55a1n1)
Copy link
Member Author

Choose a reason for hiding this comment

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

To fix this, we would need Ics20Context to have access to a scoped CapabilityReader and since there's already a PR for ICS20 impl, I updated the PR author checklist to include this -> #1989.

@hu55a1n1 hu55a1n1 mentioned this pull request Apr 13, 2022
7 tasks
@romac
Copy link
Member

romac commented Apr 29, 2022

@hu55a1n1 Shall we close this now that we've decided not go forward with the OCap model for the time being?

@adizere adizere closed this May 2, 2022
@romac romac deleted the hu55a1n1/2013-improve-obj-caps branch November 22, 2023 14:57
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.

Incomplete object-capability system
4 participants