-
Notifications
You must be signed in to change notification settings - Fork 101
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
May 2022 Hardfork #499
May 2022 Hardfork #499
Conversation
This commit adds a flag to the script engine to use 64 bit integers and updates the ScriptNum class to optionally support 64 bit integers. This is the first part of the May 2022 hardfork.
tx1 := createSpendTx(outs[0], 0) | ||
builder := txscript.NewScriptBuilder(). | ||
AddOp(txscript.OP_1). | ||
AddOp(txscript.OP_ADD). | ||
AddInt64(1152921504606846976). | ||
AddOp(txscript.OP_EQUAL) | ||
redeemScript, err := builder.Script() | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
addr, err := bchutil.NewAddressScriptHash(redeemScript, &chaincfg.RegressionNetParams) | ||
if err != nil { | ||
panic(err) | ||
} | ||
script, err := txscript.PayToAddrScript(addr) | ||
if err != nil { | ||
panic(err) | ||
} | ||
tx1.TxOut[0].PkScript = script | ||
|
||
block.AddTransaction(tx1) | ||
unsortedTxs = append(unsortedTxs, bchutil.NewTx(tx1)) | ||
|
||
// Spend from tx1 | ||
so1 := &spendableOut{ | ||
amount: bchutil.Amount(tx1.TxOut[0].Value), | ||
prevOut: wire.OutPoint{ | ||
Hash: tx1.TxHash(), | ||
Index: 0, | ||
}, | ||
} | ||
|
||
tx2 := createSpendTx(so1, 0) | ||
scriptSig, err := txscript.NewScriptBuilder(). | ||
AddInt64(1152921504606846975). | ||
AddData(redeemScript).Script() |
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.
Ah shit sorry. This suggestion (deleted) just came out as a big red block. It just has 3 line changes:
sixtyBitInt := int64(1152921504606846976)
...
AddInt64(sixtyBitInt).
...
AddInt64(sixtyBitInt - 1).
I suggest it because it took me a while to realize the two scripts are connected.
Could add an op_1 op_mul too (or in replacement of add) if you want to exercise both 64 and the re-enabled op together.
Needs OP_MUL to be re-enabled / implemented with appropriate overflow mechanic. (resolved now) |
Do you want me to take a shot at re-documenting these two?
Also do these need a documentation update since there is going to be a boundary between 32 vs 64 script int behavior? e.g. in
|
Finished one pass of review.
|
sure |
Made a first draft only for It's set so you can make commits directly or if you mention any changes, I can make them. |
blockchain/thresholdstate.go
Outdated
@@ -6,6 +6,7 @@ package blockchain | |||
|
|||
import ( | |||
"fmt" | |||
"github.com/gcash/bchd/chaincfg" | |||
|
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.
NIT: extra newline.
chaincfg/genesis.go
Outdated
// for the main network. | ||
var testNet4GenesisMerkleRoot = genesisMerkleRoot | ||
|
||
// testNet3GenesisBlock defines the genesis block of the block chain which |
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.
testNet4GenesisBlock
chaincfg/params.go
Outdated
@@ -611,6 +623,97 @@ var TestNet3Params = Params{ | |||
SlpAddressPrefix: "slptest", | |||
} | |||
|
|||
// TestNet4Params defines the network parameters for the test Bitcoin network | |||
// (version 3). Not to be confused with the regression test network, this |
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.
(version 4).
// Chain parameters | ||
GenesisBlock: &testNet4GenesisBlock, | ||
GenesisHash: &testNet4GenesisHash, | ||
PowLimit: testNet3PowLimit, |
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.
Should we have another variable for the PowLimit? Odd to use testNet3 values here.
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.
This looks amazing. Thank you for doing this work @cpacia.
Have we synced this against both testnet3 and testnet4?
im_uname says it has been tested against testnet4. The problem is that it didn't fail before op_mul was implemented in this PR. So it probably still needs to be synced against some op_mul tx. |
Yeah it synced to testnet4 but it was odd that it did because OP_MUL wasn't activated when I did it. Are there OP_MUL transactions on that chain? |
These are supposed to have op_mul: |
This PR upgrades BCHD to support the May 2022 hardfork
Tasks:
Spec:
64 Bit Integers: https://gitlab.com/GeneralProtocols/research/chips/-/blob/master/CHIP-2021-02-Bigger-Script-Integers.md
Native Introspection Opcodes: https://gitlab.com/GeneralProtocols/research/chips/-/blob/master/CHIP-2021-02-Add-Native-Introspection-Opcodes.md