Skip to content
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

genvm.sdk.multisig.SelfSpawn takes wrong key type #6061

Open
lrettig opened this issue Jun 21, 2024 · 3 comments
Open

genvm.sdk.multisig.SelfSpawn takes wrong key type #6061

lrettig opened this issue Jun 21, 2024 · 3 comments

Comments

@lrettig
Copy link
Member

lrettig commented Jun 21, 2024

Description

This method takes pubs public keys as type ed25519.PublicKey:

func SelfSpawn(
ref uint8,
pk ed25519.PrivateKey,
template types.Address,
required uint8,
pubs []ed25519.PublicKey,
nonce core.Nonce,
opts ...sdk.Opt,
) *Aggregator {
args := multisig.SpawnArguments{Required: required}
args.PublicKeys = make([]core.PublicKey, len(pubs))
for i := range pubs {
copy(args.PublicKeys[i][:], pubs[i])
}
principal := core.ComputePrincipal(template, &args)
return Spawn(ref, pk, principal, template, &args, nonce, opts...)
}

However, internally it immediately converts these keys to core.PublicKey. What's more, the spawn arguments for the same type require an array of core.PublicKey:

// SpawnArguments contains a collection with PublicKeys.
type SpawnArguments struct {
Required uint8
PublicKeys []core.PublicKey `scale:"max=10"` // update StorageLimit if it changes.
}

Let's unify these types. SelfSpawn should probably take core.PublicKey.

This issue appears in commit hash: 1be211b

@dshulyak
Copy link
Contributor

dshulyak commented Jun 24, 2024

note that core.PublicKey is a 32 byte array, the reason why it is a an array is to avoid length prefixing every public key when encoding spawn arguments. obviously the same is true for decoding. this conversion is intentional.

ed25519.PublicKey is a slice, that doesn't do copy when passed around, and also every crypto library exposes public key as a slice, so it won't be convenient to do a cast to *[32]byte earlier.

i doubt that "unification" of types makes sense, it is better to close this issue

@lrettig
Copy link
Member Author

lrettig commented Jun 24, 2024

This was inspired by spacemeshos/smcli#115 where I was confused and frustrated by the need to pass multiple key types in different places

@dshulyak
Copy link
Contributor

is it because you had to use spawn arguments struct directly? and in addition to that used "sdk" API?
i looked at functions in sdk module and it doesn't accept core.PublicKey anywhere

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants