-
Notifications
You must be signed in to change notification settings - Fork 48
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
docs(adr): ADR-007: Address generation of chain link proof #727
docs(adr): ADR-007: Address generation of chain link proof #727
Conversation
We propose to apply `Strategy` design pattern by a new interface to handle address generation from public key, which includes `GenerateAddress` function. | ||
```go | ||
type AddressGenerationStrategy interface{ | ||
GenerateAddress(pk PubKey) []byte | ||
} | ||
``` | ||
|
||
Subsequently, the `AddressData` instance like `Bech32Address` can include the any value of the strategy instance which implements `AddressGenerationStrategy` as a property. | ||
```proto | ||
message Bech32Address{ | ||
... | ||
google.protobuf.Any strategy = 3 [(cosmos_proto.accepts_interface) = "AddressGenerationStrategy"]; | ||
} | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly I'm not a big fan if this approach. We should use an interface
(and the related serialization strategy - Any
) only when there are different implementations that need different data to be created. This was true for AddressData
:
Bech32AddressData
requires a prefix and a valueHexAddressData
requires only a valueBase58AddressData
requires only a value
In this case, each address generation strategy does not require anything else aside from the public key, which is passed to the GenerateAddress
method itself. For this reason, I think the best alternative is to simply add a new method to the AddressData
interface instead:
// AddressData is an interface representing a generic external chain address
type AddressData interface {
proto.Message
// Validate checks the validity of the AddressData
Validate() error
// GetValue returns the address value
GetValue() string
// GetAddressGenerationStrategy returns the address generation strategy to be used
GetAddressGenerationStrategy() AddressGenerationStrategy
// VerifyAddress verifies that the given address is associated with this address data
VerifyAddress(address []byte) (bool, error)
}
As you can see, I've also changed VerifyPubKey
to VerifyAddress
. Now the flow should become:
- generate the proper address using the associated strategy;
- verify that the address matches the address data value.
address, err := GenerateAddress(b.GetAddressGenerationStrategy(), key)
if err != nil {
return err
}
valid, err := addressData.VerifyAddress(bz)
if err != nil {
return err
}
The GenerateAddress
is going to be a public function that simply takes an AddressGenerationStrategy
, a public key and generates the address properly:
func GenerateAddress(strategy AddressGenerationStrategy, pubKey cryptotypes.PubKey) (address []byte, err error) {
switch strategy {
case StrategyRipemd160:
return generateRipemd160Address(pubKey)
// ...
}
This implementation will also require to change all the AddressData
instances constructors to allow passing an (optional) address generation strategy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll wait for this to be included in the ADR and then review it. Notify me when ready @dadamu.
…007-chain-link-proof-address-generation
…007-chain-link-proof-address-generation
## Abstract | ||
|
||
Currently, Desmos chain link supports `Bech32`, `Base58` and `Hex` address formats. Besides, each of them only couples one address generation algorithms. | ||
Since Desmos will support more addresses from other chains, which might apply the supported address format but with the unsupported algorithm, we SHOULD split the address algorithm from `AddressData` instances. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
which might apply the supported address format but with the unsupported algorithm
I was wondering: do we have such examples?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
elrond address is a bech32 format, but it encode public key into bech32 directly instead of ripemd160(sha256(pubKey))
as cosmos ecosystem.
…007-chain-link-proof-address-generation
Signed-off-by: Riccardo Montagnin <[email protected]>
|
||
// Address contains the data of an external address | ||
message Address { | ||
// Hex-encoded value of the address |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of requesting the developers to put the hex-encoded address bytes here, we can also allow them to put the already-encoded address using the specified encoding algorithm. Then, inside the Validate
check we simply:
- generate the addresss bytes from the public key;
- encode the address using the provided encoding method;
- check if the resulting encoded address is equals to the provided value
docs/architecture/adr-007-address-generation-of-chain-link-proof.md
Outdated
Show resolved
Hide resolved
docs/architecture/adr-007-address-generation-of-chain-link-proof.md
Outdated
Show resolved
Hide resolved
…of.md Co-authored-by: Leonardo Bragagnolo <[email protected]>
…thub.com:desmos-labs/desmos into paul/adr-007-chain-link-proof-address-generation
option (cosmos_proto.implements_interface) = "AddressEncoding"; | ||
|
||
// Prefix to be used | ||
string prefix = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should provide the prefix field since Polkadot base58 address format has prefix.
References:
https://wiki.polkadot.network/docs/learn-accounts#address-format
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've nothing against this, since it brings more support for other chains.
Thoughts? @RiccardoM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing against, just made it optional though
Signed-off-by: Riccardo Montagnin <[email protected]>
Signed-off-by: Riccardo Montagnin <[email protected]>
Description
References: #724
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!
to the type prefix if API or client breaking changeCHANGELOG.md
Reviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
I have...
!
in the type prefix if API or client breaking change