Skip to content

{integrationtests, services, sorobanauth}: Support contract account invocation #165

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

Merged
merged 22 commits into from
May 5, 2025

Conversation

marcelosalloum
Copy link
Collaborator

@marcelosalloum marcelosalloum commented Apr 29, 2025

What

Support contract account invocation.

Why

To make the wallet-backend production ready.

Known limitations

We'll enable the remaining operations in:

Issue that this PR addresses

#147

Checklist

PR Structure

  • It is not possible to break this PR down into smaller PRs.
  • This PR does not mix refactoring changes with feature changes.
  • This PR's title starts with name of package that is most changed in the PR, or all if the changes are broad or impact many packages.

Thoroughness

  • This PR adds tests for the new functionality or fixes.
  • All updated queries have been tested (refer to this check if the data set returned by the updated query is expected to be same as the original one).

Release

  • This is not a breaking change.
  • This is ready to be tested in development.
  • The new functionality is gated with a feature flag if this is not ready for production.

@marcelosalloum marcelosalloum self-assigned this Apr 29, 2025
@marcelosalloum marcelosalloum force-pushed the marcelo/support-contract-submission branch from 148d290 to 78541e3 Compare April 29, 2025 00:43
@marcelosalloum marcelosalloum changed the title Marcelo/support contract submission {integrationtests, services, sorobanauth}: Support contract account invocation Apr 29, 2025
@marcelosalloum marcelosalloum requested a review from Copilot April 29, 2025 21:42
Copy link

@Copilot 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 PR adds support for contract account invocation by integrating Soroban operations along with updates to tests, error handling, and configuration. Key changes include:

  • New tests and helper functions for identifying and processing Soroban-specific operations.
  • Adjustments in transaction service logic to handle Soroban transactions (e.g. manual sequence incrementation and base fee reduction).
  • Updates to error messages and configuration defaults regarding channel account usage and signature validation.

Reviewed Changes

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

Show a summary per file
File Description
pkg/utils/utils_test.go Added tests for Soroban operation type detection and conversion.
pkg/utils/utils.go Introduced SorobanOpTypes and helper functions (IsSorobanXDROp, etc.).
pkg/sorobanauth/sorobanauth.go & _test.go Updated authorization logic and tests to handle forbidden signers.
internal/tss/utils/operation_builder*.go Refined source account enforcement for Stellar Classic vs Soroban ops.
internal/tss/services/transaction_service.go Modified transaction construction and fee handling for Soroban flows.
internal/integrationtests/* Updated integration tests and fixture functions for Soroban operations.
cmd/utils/global_options.go Adjusted default base fee configuration for transactions.
internal/serve/serve.go & httphandler/tss_handler.go Updated server routing and error handling for TSS endpoints.
internal/signing/*.go Amended signature client mocks and channel account error handling.
Comments suppressed due to low confidence (3)

internal/serve/serve.go:38

  • The removal of OperationTypeInvokeHostFunction from the blockedOperationTypes list should be reviewed to ensure it aligns with the intended security model for allowed operations.
xdr.OperationTypeInvokeHostFunction,

cmd/utils/global_options.go:65

  • The default flag value for the base fee was increased significantly from 100 * txnbuild.MinBaseFee to 10000 * txnbuild.MinBaseFee. Please confirm that this change is intentional and aligns with the required fee scaling for transactions.
FlagDefault: 10000 * txnbuild.MinBaseFee,

internal/tss/services/transaction_service.go:132

  • Manually incrementing the sequence number while disabling IncrementSequenceNum may lead to subtle concurrency issues. It is recommended to double-check that this approach consistently maintains correct transaction ordering in all cases.
Sequence:  channelAccountSeq + 1,

@marcelosalloum marcelosalloum marked this pull request as ready for review April 29, 2025 21:46
@marcelosalloum marcelosalloum force-pushed the marcelo/support-contract-submission branch 3 times, most recently from 5e75b67 to 34f7716 Compare April 30, 2025 22:43
Base automatically changed from marcelo/start-contract-submission to main May 2, 2025 21:17
… the SourceAccount to be empty for Soroban ops.
…ll Soroban operations by adding support for ExtendFootprintTtl and RestoreFootprint.
…sSourceAccount, as long as the operation source account is set to something different from the channel account address.
…robanCredentialsTypeSorobanCredentialsSourceAccount
@marcelosalloum marcelosalloum force-pushed the marcelo/support-contract-submission branch from fb8ac20 to 461f24a Compare May 2, 2025 21:19
Copy link
Contributor

@aditya1702 aditya1702 left a comment

Choose a reason for hiding this comment

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

Looks good. Just a few small comments.

Also, can you please add some more comments in the important functions for someone new to understand.

}

return opXDR, string(simResBytes), nil
op.Auth = simulateResults[0].Auth
Copy link
Contributor

Choose a reason for hiding this comment

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

why are we using only the 0th index here?

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 question!

SimulateResults is a slice because the original design aimed to support multiple contract invocations within a single transaction. That plan was later dropped, and now only one contract invocation is allowed per transaction.

I asked around, and it seems the slice structure is just a leftover from that earlier design that never fully landed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Include more comments explaining this and other parts of the code:

0848476

}

switch sorobanOp := operations[0].(type) {
case *txnbuild.InvokeHostFunction:
Copy link
Contributor

Choose a reason for hiding this comment

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

you can actually combine the switch-case conditions into a single line:

case *txnbuild.InvokeHostFunction, *txnbuild.ExtendFootprintTtl, *txnbuild.RestoreFootprint

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Noted. The reason for doing 3 cases with the same (apparent) inner code is because we have an interface at operations[0] but we need to set a parameter not exposed by that interface. The .Ext parameter is only available at the concrete types *txnbuild.InvokeHostFunction, txnbuild.ExtendFootprintTtl, and txnbuild.RestoreFootprint and we need to parse the interface to the individual type in order to set that parameter.

Go doesn't have the concept of union types (common in typescript), so there's no way around it AFAIK.

switch sorobanOp := operations[0].(type) {
case *txnbuild.InvokeHostFunction:
sorobanOp.Ext = transactionExt
case *txnbuild.ExtendFootprintTtl:
sorobanOp.Ext = transactionExt
case *txnbuild.RestoreFootprint:
sorobanOp.Ext = transactionExt
default:
return txnbuild.TransactionParams{}, fmt.Errorf("%w: operation type %T is not a supported soroban operation", ErrInvalidArguments, operations[0])
}

@marcelosalloum
Copy link
Collaborator Author

Also, can you please add some more comments in the important functions for someone new to understand.

Done in 0848476.

@marcelosalloum marcelosalloum merged commit 8951bcb into main May 5, 2025
6 checks passed
@marcelosalloum marcelosalloum deleted the marcelo/support-contract-submission branch May 5, 2025 21:30
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.

2 participants