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

Consensus key operations #255

Merged
merged 2 commits into from
Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions pkg/signatory/signatory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,63 @@ func TestPolicy(t *testing.T) {
},
expected: "operation `vdf_revelation' is not allowed",
},
{
title: "Update consensus key",
msg: mustHex("03ebcaec6ed8ab1a8a515164df37f47be175fb92851249f2b83fb96b7434ec57d3720079cae4c9a1885f17d3995619bf28636c4394458bf102f31fcc08000202d56e7b5258aa58eeb61701476c46863e2f9f31b4b467ca3175fb2f1fed6b4106"),
policy: signatory.Policy{
AllowedRequests: []string{"generic", "block", "endorsement"},
AllowedOps: []string{"endorsement", "seed_nonce_revelation", "activate_account", "ballot", "reveal", "origination", "delegation", "update_consensus_key"},
LogPayloads: true,
},
},
{
title: "Update consensus key not allowed",
msg: mustHex("03ebcaec6ed8ab1a8a515164df37f47be175fb92851249f2b83fb96b7434ec57d3720079cae4c9a1885f17d3995619bf28636c4394458bf102f31fcc08000202d56e7b5258aa58eeb61701476c46863e2f9f31b4b467ca3175fb2f1fed6b4106"),
policy: signatory.Policy{
AllowedRequests: []string{"generic", "block", "endorsement"},
AllowedOps: []string{"endorsement", "seed_nonce_revelation", "activate_account", "ballot", "reveal", "origination", "delegation"},
LogPayloads: true,
},
expected: "operation `update_consensus_key' is not allowed",
},
{
title: "Drain delegate",
msg: mustHex("0375959f80af0577302c9ed036371bc6c18644eeabf441fbad257c1a67d36a57fe090244cd5d0b4cb5a18d926b25bc37e58105e6786f0802f846b9ed8834c257a6f0c3cebeab4f58508b20ad0244cd5d0b4cb5a18d926b25bc37e58105e6786f08"),
policy: signatory.Policy{
AllowedRequests: []string{"generic", "block", "endorsement"},
AllowedOps: []string{"endorsement", "seed_nonce_revelation", "activate_account", "ballot", "reveal", "origination", "delegation", "drain_delegate"},
LogPayloads: true,
},
},
{
title: "Drain delegate not allowed",
msg: mustHex("0375959f80af0577302c9ed036371bc6c18644eeabf441fbad257c1a67d36a57fe090244cd5d0b4cb5a18d926b25bc37e58105e6786f0802f846b9ed8834c257a6f0c3cebeab4f58508b20ad0244cd5d0b4cb5a18d926b25bc37e58105e6786f08"),
policy: signatory.Policy{
AllowedRequests: []string{"generic", "block", "endorsement"},
AllowedOps: []string{"endorsement", "seed_nonce_revelation", "activate_account", "ballot", "reveal", "origination", "delegation", "update_consensus_key"},
LogPayloads: true,
},
expected: "operation `drain_delegate' is not allowed",
},
{
title: "Delegate with consesus key",
msg: mustHex("03f6622bc2e0b99604f1f103f1cbda4fa1b07ad8a993838c4f62855bfe36e8fb6a6b02f846b9ed8834c257a6f0c3cebeab4f58508b20ade60215e807000202dbc1715493e74def32a7d219df06accd6ca75d775d4177dd09471f9a9a2302826e02f846b9ed8834c257a6f0c3cebeab4f58508b20adfa0116e80700ff02f846b9ed8834c257a6f0c3cebeab4f58508b20ad7202f846b9ed8834c257a6f0c3cebeab4f58508b20ad900217cc08000202ce4ab1f214186fc04b06383e012357ccf7b67f9bddbd5818dba80f704b3a79f4"),
policy: signatory.Policy{
AllowedRequests: []string{"generic", "block", "endorsement"},
AllowedOps: []string{"endorsement", "seed_nonce_revelation", "activate_account", "ballot", "reveal", "origination", "delegation", "update_consensus_key"},
LogPayloads: true,
},
},
{
title: "Delegate with consesus key not allowed",
msg: mustHex("03f6622bc2e0b99604f1f103f1cbda4fa1b07ad8a993838c4f62855bfe36e8fb6a6b02f846b9ed8834c257a6f0c3cebeab4f58508b20ade60215e807000202dbc1715493e74def32a7d219df06accd6ca75d775d4177dd09471f9a9a2302826e02f846b9ed8834c257a6f0c3cebeab4f58508b20adfa0116e80700ff02f846b9ed8834c257a6f0c3cebeab4f58508b20ad7202f846b9ed8834c257a6f0c3cebeab4f58508b20ad900217cc08000202ce4ab1f214186fc04b06383e012357ccf7b67f9bddbd5818dba80f704b3a79f4"),
policy: signatory.Policy{
AllowedRequests: []string{"generic", "block", "endorsement"},
AllowedOps: []string{"endorsement", "seed_nonce_revelation", "activate_account", "ballot", "reveal", "origination", "delegation"},
LogPayloads: true,
},
expected: "operation `update_consensus_key' is not allowed",
},
}

priv, err := tezos.ParsePrivateKey(pk, nil)
Expand Down
45 changes: 45 additions & 0 deletions pkg/tezos/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const (
tagBallot = 6
tagDoublePreendorsementEvidence = 7
tagVdfRevelation = 8
tagDrainDelegate = 9
tagEndorsementWithSlot = 10
tagFailingNoop = 17
tagPreendorsement = 20
Expand All @@ -34,6 +35,7 @@ const (
tagRegisterGlobalConstant = 111
tagSetDepositsLimit = 112
tagIncreasePaidStorageLimit = 113
tagUpdateConsensusKey = 114
tagTxRollupOrigination = 150
tagTxRollupSubmitBatch = 151
tagTxRollupCommit = 152
Expand All @@ -59,6 +61,7 @@ var opKinds = map[int]string{
tagBallot: "ballot",
tagDoublePreendorsementEvidence: "double_preendorsement_evidence",
tagVdfRevelation: "vdf_revelation",
tagDrainDelegate: "drain_delegate",
tagEndorsementWithSlot: "endorsement_with_slot",
tagFailingNoop: "failing_noop",
tagPreendorsement: "preendorsement",
Expand All @@ -70,6 +73,7 @@ var opKinds = map[int]string{
tagRegisterGlobalConstant: "register_global_constant",
tagSetDepositsLimit: "set_deposits_limit",
tagIncreasePaidStorageLimit: "increase_paid_storage",
tagUpdateConsensusKey: "update_consensus_key",
tagTxRollupOrigination: "tx_rollup_origination",
tagTxRollupSubmitBatch: "tx_rollup_submit_batch",
tagTxRollupCommit: "tx_rollup_commit",
Expand Down Expand Up @@ -467,6 +471,22 @@ type OpIncreasePaidStorage struct {

func (o *OpIncreasePaidStorage) OperationKind() string { return "increase_paid_storage" }

type OpUpdateConsensusKey struct {
Manager
ConsesusKey string
}

func (o *OpUpdateConsensusKey) OperationKind() string { return "update_consensus_key" }

type OpDrainDelegate struct {
Manager
ConsesusKey string
Delegate string
Destination string
}

func (o *OpDrainDelegate) OperationKind() string { return "drain_delegate" }

type Commitment struct {
CompressedState string
InboxLevel int32
Expand Down Expand Up @@ -499,6 +519,19 @@ func parseOperation(buf *[]byte) (op Operation, err error) {
}
return &op, nil

case tagDrainDelegate:
var op OpDrainDelegate
if op.ConsesusKey, err = parsePublicKeyHash(buf); err != nil {
return nil, fmt.Errorf("%s: %w", opKinds[int(t)], err)
}
if op.Delegate, err = parsePublicKeyHash(buf); err != nil {
return nil, fmt.Errorf("%s: %w", opKinds[int(t)], err)
}
if op.Destination, err = parsePublicKeyHash(buf); err != nil {
return nil, fmt.Errorf("%s: %w", opKinds[int(t)], err)
}
return &op, nil

case tagEmmyEndorsement:
var op OpEmmyEndorsement
if op.Level, err = utils.GetInt32(buf); err != nil {
Expand Down Expand Up @@ -712,6 +745,7 @@ func parseOperation(buf *[]byte) (op Operation, err error) {
tagRegisterGlobalConstant,
tagSetDepositsLimit,
tagIncreasePaidStorageLimit,
tagUpdateConsensusKey,
tagTxRollupOrigination,
tagTxRollupSubmitBatch,
tagTxRollupCommit,
Expand Down Expand Up @@ -873,6 +907,17 @@ func parseOperation(buf *[]byte) (op Operation, err error) {
op.Destination = string(dest)
return &op, nil

case tagUpdateConsensusKey:
op := OpUpdateConsensusKey{
Manager: common,
}
dest, err := parsePublicKey(buf)
if err != nil {
return nil, fmt.Errorf("%s: %w", opKinds[int(t)], err)
}
op.ConsesusKey = string(dest)
return &op, nil

case tagTxRollupOrigination:
return (*OpTxRollupOrigination)(&common), nil

Expand Down