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

Draft: Starting to implement CHIP-2021-05-vm-limits and CHIP-2024-07-BigInt #1

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion blockchain/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const (

// MinTransactionSize is the minimum transaction size allowed on the
// network after the magneticanomaly hardfork
MinTransactionSize = 100
MinTransactionSize = 65

// BlockMaxBytesMaxSigChecksRatio is the ratio between the maximum allowable
// block size and the maximum allowable * SigChecks (executed signature check
Expand Down
98 changes: 96 additions & 2 deletions chaincfg/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ type Params struct {
BIP0065Height int32
BIP0066Height int32

// Only testnet4 uses CSV activation by height. All the others use the
// Only testnet4 and chipnet uses CSV activation by height. All the others use the
// deployment schedule. If this value is set to anything other than zero
// then it will activate at this height.
CSVHeight int32
Expand All @@ -154,6 +154,8 @@ type Params struct {
AxionActivationHeight int32 // Nov 15, 2020 hardfork
CosmicInflationActivationTime uint64 // May 15, 2022 hardfork

VMLimitsAndBigIntUpgradeActivationTime uint64

// CoinbaseMaturity is the number of blocks required before newly mined
// coins (coinbase transactions) can be spent.
CoinbaseMaturity uint16
Expand Down Expand Up @@ -262,7 +264,7 @@ var MainNetParams = Params{
Name: "mainnet",
Net: wire.MainNet,
DefaultPort: "8333",
DNSSeeds: []DNSSeed{
DNSSeeds: []DNSSeed{ // TODO change this to proper dns seed
{"seed.bchd.cash", true},
{"btccash-seeder.bitcoinunlimited.info", true},
{"seed.bch.loping.net", true},
Expand All @@ -288,6 +290,8 @@ var MainNetParams = Params{

CosmicInflationActivationTime: 1652616000,

VMLimitsAndBigIntUpgradeActivationTime: 1747310400,

CoinbaseMaturity: 100,
SubsidyReductionInterval: 210000,
TargetTimespan: time.Hour * 24 * 14, // 14 days
Expand Down Expand Up @@ -623,6 +627,96 @@ var TestNet3Params = Params{
SlpAddressPrefix: "slptest",
}

var ChipNetParams = Params{
Name: "chipnet",
Net: wire.ChipNet,
DefaultPort: "48333",
DNSSeeds: []DNSSeed{
{"chipnet.bitjson.com", true},
},

// Chain parameters
GenesisBlock: &testNet4GenesisBlock, // Same value as testnet4
GenesisHash: &testNet4GenesisHash, // Same value as testnet4
PowLimit: testNet3PowLimit, // Same value as testnet3
PowLimitBits: 0x1d00ffff,
BIP0034Height: 2,
BIP0065Height: 3,
BIP0066Height: 4,
CSVHeight: 5,

UahfForkHeight: 5,
DaaForkHeight: 3000,
MagneticAnonomalyForkHeight: 3999,
GreatWallForkHeight: 0,
GravitonForkHeight: 4999,
PhononForkHeight: 0,
AxionActivationHeight: 16844,

CosmicInflationActivationTime: 1637694000,

VMLimitsAndBigIntUpgradeActivationTime: 1731672000,

CoinbaseMaturity: 100,
SubsidyReductionInterval: 210000,
TargetTimespan: time.Hour * 24 * 14, // 14 days
TargetTimePerBlock: time.Minute * 10, // 10 minutes
RetargetAdjustmentFactor: 4, // 25% less, 400% more
ReduceMinDifficulty: true,
NoDifficultyAdjustment: false,
MinDiffReductionTime: time.Minute * 20, // TargetTimePerBlock * 2
AsertDifficultyHalflife: 3600, // 1 hour
AsertDifficultyAnchorHeight: 16844,
AsertDifficultyAnchorParentTimestamp: 1605451779,
AsertDifficultyAnchorBits: 0x1d00ffff,
GenerateSupported: false,

// Checkpoints ordered from oldest to newest.
Checkpoints: []Checkpoint{},

// Consensus rule change deployments.
//
// The miner confirmation window is defined as:
// target proof of work timespan / target proof of work spacing
RuleChangeActivationThreshold: 1512, // 75% of MinerConfirmationWindow
MinerConfirmationWindow: 2016,
Deployments: [DefinedDeployments]ConsensusDeployment{
DeploymentTestDummy: {
BitNumber: 28,
StartTime: 1199145601, // January 1, 2008 UTC
ExpireTime: 1230767999, // December 31, 2008 UTC
},
DeploymentCSV: {
BitNumber: 0,
StartTime: 1456790400, // March 1st, 2016
ExpireTime: 1493596800, // May 1st, 2017
},
},

// Mempool parameters
RelayNonStdTxs: false,

// The prefix for the cashaddress
CashAddressPrefix: "bchtest", // always bchtest for testnet

// Address encoding magics
LegacyPubKeyHashAddrID: 0x6f, // starts with m or n
LegacyScriptHashAddrID: 0xc4, // starts with 2
PrivateKeyID: 0xef, // starts with 9 (uncompressed) or c (compressed)

// BIP32 hierarchical deterministic extended key magics
HDPrivateKeyID: [4]byte{0x04, 0x35, 0x83, 0x94}, // starts with tprv
HDPublicKeyID: [4]byte{0x04, 0x35, 0x87, 0xcf}, // starts with tpub

// BIP44 coin type used in the hierarchical deterministic path for
// address generation.
HDCoinType: 1, // all coins use 1

// slp indexer parameters
SlpIndexStartHeight: 0,
SlpAddressPrefix: "slptest",
}

// TestNet4Params defines the network parameters for the test Bitcoin network
// (version 4). Not to be confused with the regression test network, this
// network is sometimes simply called "testnet".
Expand Down
7 changes: 6 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ type config struct {
TorIsolation bool `long:"torisolation" description:"Enable Tor stream isolation by randomizing user credentials for each connection."`
TestNet3 bool `long:"testnet" description:"Use the test network"`
TestNet4 bool `long:"testnet4" description:"Use the test 4 network"`
ChipNet bool `long:"chipnet" description:"Use the chip network"`
RegressionTest bool `long:"regtest" description:"Use the regression test network"`
RegressionTestAnyHost bool `long:"regtestanyhost" description:"In regression test mode, allow connections from any host, not just localhost"`
RegressionTestNoReset bool `long:"regtestnoreset" description:"In regression test mode, don't reset the network db on node restart"`
Expand Down Expand Up @@ -595,6 +596,10 @@ func loadConfig() (*config, []string, error) {
numNets++
activeNetParams = &testNet4Params
}
if cfg.ChipNet {
numNets++
activeNetParams = &chipNetParams
}
if cfg.RegressionTest {
numNets++
activeNetParams = &regressionNetParams
Expand All @@ -606,7 +611,7 @@ func loadConfig() (*config, []string, error) {
cfg.DisableDNSSeed = true
}
if numNets > 1 {
str := "%s: The testnet, regtest, segnet, and simnet params " +
str := "%s: The testnet, chipnet, regtest, segnet, and simnet params " +
"can't be used together -- choose one of the four"
err := fmt.Errorf(str, funcName)
fmt.Fprintln(os.Stderr, err)
Expand Down
9 changes: 9 additions & 0 deletions params.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ var testNet4Params = params{
gRRPPort: "18335",
}

// chipNetParams contains parameters specific to the chip network
// (wire.ChipNet). NOTE: The RPC port is intentionally different than the
// reference implementation - see the mainNetParams comment for details.
var chipNetParams = params{
Params: &chaincfg.ChipNetParams,
rpcPort: "18334",
gRRPPort: "18335",
}

// simNetParams contains parameters specific to the simulation test network
// (wire.SimNet).
var simNetParams = params{
Expand Down
20 changes: 15 additions & 5 deletions txscript/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ const (
// ScriptVerifyNativeIntrospection enables the suite of native introspection
// opcodes.
ScriptVerifyNativeIntrospection

// ScriptIncreasedVMLimits enables the upgrade '25 vm limits
ScriptIncreasedVMLimits
)

// HasFlag returns whether the ScriptFlags has the passed flag set.
Expand Down Expand Up @@ -158,6 +161,7 @@ type Engine struct {
txIdx int
condStack []int
numOps int
opCost int
flags ScriptFlags
sigCache *SigCache
hashCache *TxSigHashes
Expand Down Expand Up @@ -204,11 +208,15 @@ func (vm *Engine) executeOpcode(pop *parsedOpcode) error {

// Note that this includes OP_RESERVED which counts as a push operation.
if pop.opcode.value > OP_16 {
vm.numOps++
if vm.numOps > MaxOpsPerScript {
str := fmt.Sprintf("exceeded max operation limit of %d",
MaxOpsPerScript)
return scriptError(ErrTooManyOperations, str)
if vm.hasFlag(ScriptIncreasedVMLimits) {
vm.opCost += 100
} else {
vm.numOps++
if vm.numOps > MaxOpsPerScript {
str := fmt.Sprintf("exceeded max operation limit of %d",
MaxOpsPerScript)
return scriptError(ErrTooManyOperations, str)
}
}

} else if len(pop.data) > MaxScriptElementSize {
Expand Down Expand Up @@ -407,6 +415,7 @@ func (vm *Engine) Step() (done bool, err error) {
_ = vm.astack.DropN(vm.astack.Depth())

vm.numOps = 0 // number of ops is per script.
vm.opCost = 0
vm.scriptOff = 0
if vm.scriptIdx == 0 && vm.bip16 {
vm.scriptIdx++
Expand Down Expand Up @@ -833,6 +842,7 @@ func (vm *Engine) Clone() *Engine {
scriptOff: vm.scriptOff,
scriptIdx: vm.scriptIdx,
numOps: vm.numOps,
opCost: vm.opCost,
lastCodeSep: vm.lastCodeSep,
tx: vm.tx,
bip16: vm.bip16,
Expand Down
Loading