Skip to content

Commit

Permalink
Add confidential inputs to spell cmd (#230)
Browse files Browse the repository at this point in the history
* Add confidential inputs to spell cmd

* Fix
  • Loading branch information
ferranbt authored Apr 4, 2024
1 parent 9413e91 commit 2cb89ce
Show file tree
Hide file tree
Showing 2 changed files with 64 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)'
```
39 changes: 37 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,14 @@ var (
return err
}

var confInput []byte
if input := ctx.String(confidentialInput.Name); input != "" {
confInput = []byte(input)
log.Info("Confidential input provided", "input", confInput)
} else {
log.Info("No confidential input provided, using empty string")
}

var contractAddr common.Address
if err := contractAddr.UnmarshalText([]byte(args[0])); err != nil {
return err
Expand All @@ -153,13 +166,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, confInput)
if err != nil {
return err
}
Expand Down

0 comments on commit 2cb89ce

Please sign in to comment.