Skip to content

Commit

Permalink
Showing 2 changed files with 16 additions and 8 deletions.
5 changes: 5 additions & 0 deletions config/consensus.go
Original file line number Diff line number Diff line change
@@ -483,6 +483,10 @@ type ConsensusParams struct {
// the rewardsLevel, but the rewardsLevel has no meaning because the account
// has fewer than RewardUnit algos.
UnfundedSenders bool

// EnablePrecheckECDSACurve means that ecdsa_verify opcode will bail early,
// returning false, if pubkey is not on the curve.
EnablePrecheckECDSACurve bool
}

// PaysetCommitType enumerates possible ways for the block header to commit to
@@ -1249,6 +1253,7 @@ func initConsensusProtocols() {
vFuture.ApprovedUpgrades = map[protocol.ConsensusVersion]uint64{}

vFuture.LogicSigVersion = 9 // When moving this to a release, put a new higher LogicSigVersion here
vFuture.EnablePrecheckECDSACurve = true

Consensus[protocol.ConsensusFuture] = vFuture

19 changes: 11 additions & 8 deletions data/transactions/logic/eval.go
Original file line number Diff line number Diff line change
@@ -3432,6 +3432,8 @@ var ecdsaVerifyCosts = []int{
Secp256r1: 2500,
}

var secp256r1 = elliptic.P256()

func opEcdsaVerify(cx *EvalContext) error {
ecdsaCurve := EcdsaCurve(cx.program[cx.pc+1])
fs, ok := ecdsaCurveSpecByField(ecdsaCurve)
@@ -3471,15 +3473,16 @@ func opEcdsaVerify(cx *EvalContext) error {
pubkey := secp256k1.S256().Marshal(x, y)
result = secp256k1.VerifySignature(pubkey, msg, signature)
} else if fs.field == Secp256r1 {
r := new(big.Int).SetBytes(sigR)
s := new(big.Int).SetBytes(sigS)

pubkey := ecdsa.PublicKey{
Curve: elliptic.P256(),
X: x,
Y: y,
if !cx.Proto.EnablePrecheckECDSACurve || secp256r1.IsOnCurve(x, y) {
pubkey := ecdsa.PublicKey{
Curve: secp256r1,
X: x,
Y: y,
}
r := new(big.Int).SetBytes(sigR)
s := new(big.Int).SetBytes(sigS)
result = ecdsa.Verify(&pubkey, msg, r, s)
}
result = ecdsa.Verify(&pubkey, msg, r, s)
}

cx.stack[fifth] = boolToSV(result)

0 comments on commit c573d2b

Please sign in to comment.