-
Notifications
You must be signed in to change notification settings - Fork 699
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
P-chain - Memo field zeroed post Durango #2607
Changes from 14 commits
d01b7ee
3181e9a
5bbe14c
46de238
6854972
80332a3
9b5ac0a
c0ce5ad
53e9a44
b8df184
1fdf681
1b01c22
3d33013
dcf5591
1e10b39
557bfb9
99e56de
6009d83
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -65,3 +65,20 @@ func (t *BaseTx) Verify(ctx *snow.Context) error { | |||||||
return nil | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
func VerifyMemoFieldLength(memo types.JSONByteSlice, isDurangoActive bool) error { | ||||||||
if !isDurangoActive { | ||||||||
return nil // already validated in SyntacticVerify | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||||||||
} | ||||||||
|
||||||||
if len(memo) != 0 { | ||||||||
return fmt.Errorf( | ||||||||
"%w: %d > %d", | ||||||||
ErrMemoTooLarge, | ||||||||
len(memo), | ||||||||
0, | ||||||||
) | ||||||||
} | ||||||||
|
||||||||
return nil | ||||||||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -103,11 +103,16 @@ func verifyAddValidatorTx( | |||||
var ( | ||||||
currentTimestamp = chainState.GetTimestamp() | ||||||
isDurangoActive = backend.Config.IsDurangoActivated(currentTimestamp) | ||||||
startTime = currentTimestamp | ||||||
) | ||||||
if err := avax.VerifyMemoFieldLength(tx.Memo, isDurangoActive); err != nil { | ||||||
return nil, err | ||||||
} | ||||||
|
||||||
startTime := currentTimestamp | ||||||
if !isDurangoActive { | ||||||
startTime = tx.StartTime() | ||||||
} | ||||||
|
||||||
duration := tx.EndTime().Sub(startTime) | ||||||
switch { | ||||||
case tx.Validator.Wght < backend.Config.MinValidatorStake: | ||||||
|
@@ -194,8 +199,12 @@ func verifyAddSubnetValidatorTx( | |||||
var ( | ||||||
currentTimestamp = chainState.GetTimestamp() | ||||||
isDurangoActive = backend.Config.IsDurangoActivated(currentTimestamp) | ||||||
startTime = currentTimestamp | ||||||
) | ||||||
if err := avax.VerifyMemoFieldLength(tx.Memo, isDurangoActive); err != nil { | ||||||
return err | ||||||
} | ||||||
|
||||||
startTime := currentTimestamp | ||||||
if !isDurangoActive { | ||||||
startTime = tx.StartTime() | ||||||
} | ||||||
|
@@ -283,6 +292,14 @@ func verifyRemoveSubnetValidatorTx( | |||||
return nil, false, err | ||||||
} | ||||||
|
||||||
var ( | ||||||
currentTimestamp = chainState.GetTimestamp() | ||||||
isDurangoActive = backend.Config.IsDurangoActivated(currentTimestamp) | ||||||
) | ||||||
if err := avax.VerifyMemoFieldLength(tx.Memo, isDurangoActive); err != nil { | ||||||
return nil, false, err | ||||||
} | ||||||
|
||||||
isCurrentValidator := true | ||||||
vdr, err := chainState.GetCurrentValidator(tx.Subnet, tx.NodeID) | ||||||
if err == database.ErrNotFound { | ||||||
|
@@ -351,8 +368,14 @@ func verifyAddDelegatorTx( | |||||
var ( | ||||||
currentTimestamp = chainState.GetTimestamp() | ||||||
isDurangoActive = backend.Config.IsDurangoActivated(currentTimestamp) | ||||||
endTime = tx.EndTime() | ||||||
startTime = currentTimestamp | ||||||
) | ||||||
if err := avax.VerifyMemoFieldLength(tx.Memo, isDurangoActive); err != nil { | ||||||
return nil, err | ||||||
} | ||||||
|
||||||
var ( | ||||||
endTime = tx.EndTime() | ||||||
startTime = currentTimestamp | ||||||
) | ||||||
if !isDurangoActive { | ||||||
startTime = tx.StartTime() | ||||||
|
@@ -458,15 +481,19 @@ func verifyAddPermissionlessValidatorTx( | |||||
return err | ||||||
} | ||||||
|
||||||
if !backend.Bootstrapped.Get() { | ||||||
return nil | ||||||
} | ||||||
|
||||||
var ( | ||||||
currentTimestamp = chainState.GetTimestamp() | ||||||
isDurangoActive = backend.Config.IsDurangoActivated(currentTimestamp) | ||||||
startTime = currentTimestamp | ||||||
) | ||||||
if err := avax.VerifyMemoFieldLength(tx.Memo, isDurangoActive); err != nil { | ||||||
return err | ||||||
} | ||||||
|
||||||
if !backend.Bootstrapped.Get() { | ||||||
return nil | ||||||
} | ||||||
|
||||||
startTime := currentTimestamp | ||||||
if !isDurangoActive { | ||||||
startTime = tx.StartTime() | ||||||
} | ||||||
|
@@ -578,15 +605,21 @@ func verifyAddPermissionlessDelegatorTx( | |||||
return err | ||||||
} | ||||||
|
||||||
var ( | ||||||
currentTimestamp = chainState.GetTimestamp() | ||||||
isDurangoActive = backend.Config.IsDurangoActivated(currentTimestamp) | ||||||
) | ||||||
if err := avax.VerifyMemoFieldLength(tx.Memo, isDurangoActive); err != nil { | ||||||
return err | ||||||
} | ||||||
|
||||||
if !backend.Bootstrapped.Get() { | ||||||
return nil | ||||||
} | ||||||
|
||||||
var ( | ||||||
currentTimestamp = chainState.GetTimestamp() | ||||||
isDurangoActive = backend.Config.IsDurangoActivated(currentTimestamp) | ||||||
endTime = tx.EndTime() | ||||||
startTime = currentTimestamp | ||||||
endTime = tx.EndTime() | ||||||
startTime = currentTimestamp | ||||||
) | ||||||
if !isDurangoActive { | ||||||
startTime = tx.StartTime() | ||||||
|
@@ -728,6 +761,10 @@ func verifyTransferSubnetOwnershipTx( | |||||
return err | ||||||
} | ||||||
|
||||||
if err := avax.VerifyMemoFieldLength(tx.Memo, true /*isDurangoActive*/); err != nil { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||||||
return err | ||||||
} | ||||||
|
||||||
if !backend.Bootstrapped.Get() { | ||||||
// Not bootstrapped yet -- don't need to do full verification. | ||||||
return nil | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -54,13 +54,20 @@ func (e *StandardTxExecutor) CreateChainTx(tx *txs.CreateChainTx) error { | |||||
return err | ||||||
} | ||||||
|
||||||
var ( | ||||||
timestamp = e.State.GetTimestamp() | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||||||
isDurangoActive = e.Config.IsDurangoActivated(timestamp) | ||||||
) | ||||||
if err := avax.VerifyMemoFieldLength(tx.Memo, isDurangoActive); err != nil { | ||||||
return err | ||||||
} | ||||||
|
||||||
baseTxCreds, err := verifyPoASubnetAuthorization(e.Backend, e.State, e.Tx, tx.SubnetID, tx.SubnetAuth) | ||||||
if err != nil { | ||||||
return err | ||||||
} | ||||||
|
||||||
// Verify the flowcheck | ||||||
timestamp := e.State.GetTimestamp() | ||||||
createBlockchainTxFee := e.Config.GetCreateBlockchainTxFee(timestamp) | ||||||
if err := e.FlowChecker.VerifySpend( | ||||||
tx, | ||||||
|
@@ -98,8 +105,15 @@ func (e *StandardTxExecutor) CreateSubnetTx(tx *txs.CreateSubnetTx) error { | |||||
return err | ||||||
} | ||||||
|
||||||
var ( | ||||||
timestamp = e.State.GetTimestamp() | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||||||
isDurangoActive = e.Config.IsDurangoActivated(timestamp) | ||||||
) | ||||||
if err := avax.VerifyMemoFieldLength(tx.Memo, isDurangoActive); err != nil { | ||||||
return err | ||||||
} | ||||||
|
||||||
// Verify the flowcheck | ||||||
timestamp := e.State.GetTimestamp() | ||||||
createSubnetTxFee := e.Config.GetCreateSubnetTxFee(timestamp) | ||||||
if err := e.FlowChecker.VerifySpend( | ||||||
tx, | ||||||
|
@@ -131,6 +145,14 @@ func (e *StandardTxExecutor) ImportTx(tx *txs.ImportTx) error { | |||||
return err | ||||||
} | ||||||
|
||||||
var ( | ||||||
currentTimestamp = e.State.GetTimestamp() | ||||||
isDurangoActive = e.Config.IsDurangoActivated(currentTimestamp) | ||||||
) | ||||||
if err := avax.VerifyMemoFieldLength(tx.Memo, isDurangoActive); err != nil { | ||||||
return err | ||||||
} | ||||||
|
||||||
e.Inputs = set.NewSet[ids.ID](len(tx.ImportedInputs)) | ||||||
utxoIDs := make([][]byte, len(tx.ImportedInputs)) | ||||||
for i, in := range tx.ImportedInputs { | ||||||
|
@@ -209,6 +231,14 @@ func (e *StandardTxExecutor) ExportTx(tx *txs.ExportTx) error { | |||||
return err | ||||||
} | ||||||
|
||||||
var ( | ||||||
currentTimestamp = e.State.GetTimestamp() | ||||||
isDurangoActive = e.Config.IsDurangoActivated(currentTimestamp) | ||||||
) | ||||||
if err := avax.VerifyMemoFieldLength(tx.Memo, isDurangoActive); err != nil { | ||||||
return err | ||||||
} | ||||||
|
||||||
outs := make([]*avax.TransferableOutput, len(tx.Outs)+len(tx.ExportedOutputs)) | ||||||
copy(outs, tx.Outs) | ||||||
copy(outs[len(tx.Outs):], tx.ExportedOutputs) | ||||||
|
@@ -386,6 +416,14 @@ func (e *StandardTxExecutor) TransformSubnetTx(tx *txs.TransformSubnetTx) error | |||||
return err | ||||||
} | ||||||
|
||||||
var ( | ||||||
currentTimestamp = e.State.GetTimestamp() | ||||||
isDurangoActive = e.Config.IsDurangoActivated(currentTimestamp) | ||||||
) | ||||||
if err := avax.VerifyMemoFieldLength(tx.Memo, isDurangoActive); err != nil { | ||||||
return err | ||||||
} | ||||||
|
||||||
// Note: math.MaxInt32 * time.Second < math.MaxInt64 - so this can never | ||||||
// overflow. | ||||||
if time.Duration(tx.MaxStakeDuration)*time.Second > e.Backend.Config.MaxStakeDuration { | ||||||
|
@@ -512,6 +550,10 @@ func (e *StandardTxExecutor) BaseTx(tx *txs.BaseTx) error { | |||||
return err | ||||||
} | ||||||
|
||||||
if err := avax.VerifyMemoFieldLength(tx.Memo, true /*isDurangoActive*/); err != nil { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||||||
return err | ||||||
} | ||||||
|
||||||
// Verify the flowcheck | ||||||
if err := e.FlowChecker.VerifySpend( | ||||||
tx, | ||||||
|
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 added a different method rather than extending
SyntacticVerify
with config and chainTIme. We can revisit this choice down the line, in case other syntactic checks will depend on the specific fork used