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

Introduce TypeScript monitors #135

Merged
merged 7 commits into from
Oct 18, 2024
Merged

Introduce TypeScript monitors #135

merged 7 commits into from
Oct 18, 2024

Conversation

thpani
Copy link
Collaborator

@thpani thpani commented Oct 14, 2024

In order to evaluate how we write monitors, we need to iterate quickly based on several case studies.

The current TLA+ instrumentation is a bit too brittle to iterate quickly, and we have not fully understood how to translate Soroban's heterogeneous/duck-typed storage into TLA+ types.

Thus, we introduce a monitor driver for writing monitors in TypeScript.

Using the TS monitor driver introduced in this PR, writing a monitor in TypeScript is very simple: Create a TS class that extends SolarkraftJsMonitor and provide methods corresponding to the contract functions. In the body of those functions, use reverts_if and succeeds_with methods to specify the conditions under which the contract should revert or succeed. The monitor is then (programmatically) verified by instantiating the monitor class and calling the verify method with the hashes of the transactions to be verified.
For an example, see f6e994e.

Closes #134

Immutable.fromJS deeply converts all JS objects to Maps.
For deserializing storage, we want the target object to instead be
Map -> JS object {instance:, persistent:, temporary:} -> Map.
Thus, we provide a custom loader instead.
@thpani thpani added this to the M6: DevRel and case studies milestone Oct 14, 2024
@thpani thpani requested a review from konnov October 14, 2024 16:32
@thpani
Copy link
Collaborator Author

thpani commented Oct 14, 2024

@konnov This is a rather large change-set, so I recommend reviewing by commit.

@thpani thpani removed this from the M6: DevRel and case studies milestone Oct 14, 2024
Copy link
Contributor

@konnov konnov left a comment

Choose a reason for hiding this comment

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

I like this idea a lot. Obviously, we need more examples and iterations to figure out, what would be needed to specify monitors right in JS. However, it is a very good approach to avoiding the complexity of Rust and TLA+.

solarkraft/src/verify_js.ts Show resolved Hide resolved
/* the monitor */

class TimelockMonitor extends SolarkraftJsMonitor {
deposit(
Copy link
Contributor

Choose a reason for hiding this comment

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

I like this. One idea: When you write deposit, this may be confusing, as you do not describe the behavior of deposit. Would it make sense to have a name like on_deposit, before_deposit, or deposit_ensures?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point! I think on_deposit would work well.

I've put it in #141 to follow up on.

*/
import { Either } from '@sweet-monads/either'

export type Result<T> = Either<string, T>
Copy link
Contributor

Choose a reason for hiding this comment

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

I like that a lot!

@thpani thpani merged commit 9a5369e into main Oct 18, 2024
3 checks passed
@thpani thpani deleted the th/js-monitors branch October 18, 2024 08:20
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.

Introduce Solarkraft monitors in TypeScript
2 participants