Skip to content

Commit

Permalink
Add confidential inputs to spell cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
ferranbt committed Apr 2, 2024
1 parent 858b058 commit c5c186f
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 2 deletions.
27 changes: 27 additions & 0 deletions cmd/geth/spellcmd/README.md
Original file line number Diff line number Diff line change
@@ -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] <solidity-file>:<contract-name>
```

Example:

```bash
$ suave-geth spell deploy MyContract.sol:MyContract
```

## Send a confidential compute request

```bash
$ suave-geth spell conf-request [--confidential-input <input>] <contract-addr> '<function signature>' ['(arg1,arg2)']
```

Example:

```bash
$ suave-geth spell conf-request 0x1234567890abcdef1234567890abcdef12345678 'set(uint256)' '(42)'
```
38 changes: 36 additions & 2 deletions cmd/geth/spellcmd/spellcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -124,6 +128,7 @@ var (
privateKeyFlag,
rpcFlag,
artifactsDirFlag,
confidentialInput,
},
Action: func(ctx *cli.Context) error {
args := ctx.Args().Slice()
Expand All @@ -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
Expand All @@ -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
}
Expand Down

0 comments on commit c5c186f

Please sign in to comment.