Skip to content

Commit

Permalink
Compute correct IOArg size for zero-values.
Browse files Browse the repository at this point in the history
  • Loading branch information
markkurossi committed Oct 2, 2023
1 parent 105d831 commit 2cc19af
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
15 changes: 10 additions & 5 deletions circuit/ioarg.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package circuit
import (
"fmt"
"math/big"
"strings"

"github.com/markkurossi/mpc/types"
)
Expand Down Expand Up @@ -132,12 +133,16 @@ func InputSizes(inputs []string) ([]int, error) {
result = append(result, 1)

default:
val := new(big.Int)
_, ok := val.SetString(input, 0)
if !ok {
return nil, fmt.Errorf("invalid input: %s", input)
if strings.HasPrefix(input, "0x") {
result = append(result, (len(input)-2)*4)
} else {
val := new(big.Int)
_, ok := val.SetString(input, 0)
if !ok {
return nil, fmt.Errorf("invalid input: %s", input)
}
result = append(result, val.BitLen())
}
result = append(result, val.BitLen())
}
}

Expand Down
8 changes: 8 additions & 0 deletions circuit/ioarg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ var inputSizeTests = []struct {
32, 8,
},
},
{
inputs: []string{
"0x0", "0x00", "0x000", "0x0000",
},
sizes: []int{
4, 8, 12, 16,
},
},
}

func TestInputSizes(t *testing.T) {
Expand Down

0 comments on commit 2cc19af

Please sign in to comment.