From c5c186f910c4bef4e5ad5dfd950a50d64e50ee1d Mon Sep 17 00:00:00 2001 From: Ferran Borreguero Date: Tue, 2 Apr 2024 08:49:30 +0100 Subject: [PATCH] Add confidential inputs to spell cmd --- cmd/geth/spellcmd/README.md | 27 +++++++++++++++++++++++++ cmd/geth/spellcmd/spellcmd.go | 38 +++++++++++++++++++++++++++++++++-- 2 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 cmd/geth/spellcmd/README.md diff --git a/cmd/geth/spellcmd/README.md b/cmd/geth/spellcmd/README.md new file mode 100644 index 000000000..436fe4de4 --- /dev/null +++ b/cmd/geth/spellcmd/README.md @@ -0,0 +1,27 @@ +# Spell command + +## Deploy a contract + +To deploy a contract, you need to be in the root of a Forge project that contains the built artifacts and run: + +```bash +$ suave-geth spell deploy [--artifacts out] : +``` + +Example: + +```bash +$ suave-geth spell deploy MyContract.sol:MyContract +``` + +## Send a confidential compute request + +```bash +$ suave-geth spell conf-request [--confidential-input ] '' ['(arg1,arg2)'] +``` + +Example: + +```bash +$ suave-geth spell conf-request 0x1234567890abcdef1234567890abcdef12345678 'set(uint256)' '(42)' +``` diff --git a/cmd/geth/spellcmd/spellcmd.go b/cmd/geth/spellcmd/spellcmd.go index 1a3622c7f..32e723c7c 100644 --- a/cmd/geth/spellcmd/spellcmd.go +++ b/cmd/geth/spellcmd/spellcmd.go @@ -49,6 +49,10 @@ var ( Usage: "The directory where the contract artifacts are located", Value: "out", } + confidentialInput = &cli.StringFlag{ + Name: "confidential-input", + Usage: "The confidential input to use for the confidential request", + } ) var ( @@ -124,6 +128,7 @@ var ( privateKeyFlag, rpcFlag, artifactsDirFlag, + confidentialInput, }, Action: func(ctx *cli.Context) error { args := ctx.Args().Slice() @@ -136,6 +141,13 @@ var ( return err } + confInput := ctx.String(confidentialInput.Name) + if confInput == "" { + log.Info("No confidential input provided, using empty string") + } else { + log.Info("Confidential input provided", "input", confInput) + } + var contractAddr common.Address if err := contractAddr.UnmarshalText([]byte(args[0])); err != nil { return err @@ -153,13 +165,35 @@ var ( return fmt.Errorf("failed to parse method signature: %w", err) } - calldata, err := method.Encode([]interface{}{}) + var methodArgs []interface{} + if len(args) == 3 { + // arguments are passed as an array of items '(0x000,1,2)' + methodArgsStr := args[2] + + // verify it has brackets and remove them + if !strings.HasPrefix(methodArgsStr, "(") { + return fmt.Errorf("expected method arguments to start with '('") + } + if !strings.HasSuffix(methodArgsStr, ")") { + return fmt.Errorf("expected method arguments to end with ')'") + } + + methodArgsStr = methodArgsStr[1 : len(methodArgsStr)-1] + parts := strings.Split(methodArgsStr, ",") + + for _, part := range parts { + methodArgs = append(methodArgs, strings.TrimSpace(part)) + } + } + + calldata, err := method.Encode(methodArgs) if err != nil { return err } log.Info("Sending offchain confidential compute request", "kettle", clt.KettleAddress().String()) - hash, err := sendConfRequest(clt, devchainKettleAddress, contractAddr, calldata, nil) + + hash, err := sendConfRequest(clt, devchainKettleAddress, contractAddr, calldata, []byte(confInput)) if err != nil { return err }