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

GH-2463: Provide smart contract access to associated keys that signed a deploy #2468

Merged

Conversation

mpapierski
Copy link
Collaborator

@mpapierski mpapierski commented Dec 14, 2021

Closes #2463

This PR adds list_authorization_keys to the contract_api / wasm ffi, allowing smart contracts access to the set of associated AccountHashes that signed a deploy.

This is necessary for certain types of more advanced smart contracts that utilize multi signature accounts and need to impose some form of role based security in their app logic. For instance, a smart contract that has defined a "clerk", a "supervisor", and "registrar" roles and contains certain entrypoints or operations that are only allowed if one or more signatories of specific role(s) have signed a deploy.

@mpapierski mpapierski changed the base branch from release-1.4.1 to dev December 14, 2021 16:41
@mpapierski mpapierski marked this pull request as ready for review December 14, 2021 16:45
@EdHastingsCasperAssociation
Copy link
Collaborator

good start, quick turn around, but see notes

@EdHastingsCasperAssociation EdHastingsCasperAssociation changed the title GH-2463: Expose deploy signatures GH-2463: Provide smart contract access to associated keys that signed a deploy Dec 14, 2021
Vec::from_iter(self.context.authorization_keys().clone().into_iter());

let total_keys = authorization_keys.len() as u32;
let total_keys_bytes = total_keys.to_le_bytes();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we be using to_bytes() instead? It will call to_le_bytes() on u32 as well but we would be using a higher-level API that we had defined ourselves.

Copy link
Collaborator Author

@mpapierski mpapierski Dec 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, bytesrepr represents u32 as four little-endian bytes, but it may not be the case in the future. The intention is to write u32 as LE bytes under a pointer, rather than 'ABI serialized u32 integer', which is different (and more expensive). This approach also saves us from calling bytesrepr::deserialize on this memory.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So what are the rules about this? When do we choose ToBytes/FromBytes and when we do not?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you need to pass a single value of a type statically known on the Wasm side like a pointer to u32, then write to_le_bytes(), but if you need something more complex like Vec<AccountHash>, you should consider bytesrepr. Historically we weren't always careful, and we overused bytesrepr a lot on the Wasm side, but I hope to address this in 2.0 - for now, I'm trying to stay consistent and pass plain values as LE bytes

Michał Papierski added 2 commits December 15, 2021 15:02
- Replaces `authorized-keys` test contract with `set-action-thresholds`
  to avoid duplication of test code
- Few small renames
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, but will ping you w/ a nuance question

@goral09
Copy link
Contributor

goral09 commented Dec 21, 2021

My comment (#2468 (comment)) still stands. Why are we not exposing keys instead? They're more valuable to the smart contracts than hashes (one can always go key -> hash but not the other way around).

@mpapierski
Copy link
Collaborator Author

My comment (#2468 (comment)) still stands. Why are we not exposing keys instead? They're more valuable to the smart contracts than hashes (one can always go key -> hash but not the other way around).

Consistency with other associated keys APIs with _key suffix. There was also an idea to expose Key::Accounts (as the function has _keys suffix) but it's the same issue

@goral09
Copy link
Contributor

goral09 commented Dec 21, 2021

My comment (#2468 (comment)) still stands. Why are we not exposing keys instead? They're more valuable to the smart contracts than hashes (one can always go key -> hash but not the other way around).

Consistency with other associated keys APIs with _key suffix. There was also an idea to expose Key::Accounts (as the function has _keys suffix) but it's the same issue

If exposing keys is superior functionality we shouldn't disregard it b/c we've exposed hashes until now.

@mpapierski
Copy link
Collaborator Author

My comment (#2468 (comment)) still stands. Why are we not exposing keys instead? They're more valuable to the smart contracts than hashes (one can always go key -> hash but not the other way around).

Consistency with other associated keys APIs with _key suffix. There was also an idea to expose Key::Accounts (as the function has _keys suffix) but it's the same issue

If exposing keys is superior functionality we shouldn't disregard it b/c we've exposed hashes until now.

Can we address this is in separate work perhaps? I have some concerns with exposing casper_types::PublicKey in current shape to Wasm

@ashok-cl
Copy link

I agree with @goral09 here: #2468 (comment)

@mpapierski @piotr-dziubecki can we create a ticket and plan for this?

@goral09
Copy link
Contributor

goral09 commented Jan 14, 2022

@mpapierski any actions you need to take before merging the PR?

@mpapierski
Copy link
Collaborator Author

bors r+

@mpapierski
Copy link
Collaborator Author

@mpapierski, any actions you need to take before merging the PR?

I just notified Piotr about exposing PublicKeys in future work (2.0.0 perhaps). Merging now

@casperlabs-bors-ng
Copy link
Contributor

Build succeeded:

@casperlabs-bors-ng casperlabs-bors-ng bot merged commit da7fdc5 into casper-network:dev Jan 14, 2022
@operator(">")
graterThan(other: AccountHash): bool {
for (let i = 0; i < 32; i++) {
if (this.bytes[0] > other.bytes[0]) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should that be i instead of 0? (Also in lowerThan.)

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

Successfully merging this pull request may close these issues.

Make deploy signatures available to executing smart contract
7 participants