Skip to content

Commit

Permalink
Naming change to appease lint
Browse files Browse the repository at this point in the history
  • Loading branch information
jannotti committed Jan 9, 2023
1 parent 57d3900 commit 86e5228
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 117 deletions.
20 changes: 10 additions & 10 deletions data/transactions/logic/TEAL_opcodes.md
Original file line number Diff line number Diff line change
Expand Up @@ -1566,17 +1566,17 @@ For boxes that exceed 4,096 bytes, consider `box_create`, `box_extract`, and `bo
- Opcode: 0xe0 {uint8 curve}
- Stack: ..., A: []byte, B: []byte → ..., []byte
- for curve points A and B, return the curve point A + B
- **Cost**: BN254_G1=310 BN254_G2=430 BLS12_381_G1=540 BLS12_381_G2=750
- **Cost**: BN254g1=310 BN254g2=430 BLS12_381g1=540 BLS12_381g2=750
- Availability: v9

`EC` Groups:

| Index | Name | Notes |
| - | ------ | --------- |
| 0 | BN254_G1 | G1 of the BN254 curve. Points encoded as 32 byte X following by 32 byte Y |
| 1 | BN254_G2 | G2 of the BN254 curve. Points encoded as 64 byte X following by 64 byte Y |
| 2 | BLS12_381_G1 | G1 of the BLS 12-381 curve. Points encoded as 48 byte X following by 48 byte Y |
| 3 | BLS12_381_G2 | G2 of the BLS 12-381 curve. Points encoded as 96 byte X following by 48 byte Y |
| 0 | BN254g1 | G1 of the BN254 curve. Points encoded as 32 byte X following by 32 byte Y |
| 1 | BN254g2 | G2 of the BN254 curve. Points encoded as 64 byte X following by 64 byte Y |
| 2 | BLS12_381g1 | G1 of the BLS 12-381 curve. Points encoded as 48 byte X following by 48 byte Y |
| 3 | BLS12_381g2 | G2 of the BLS 12-381 curve. Points encoded as 96 byte X following by 48 byte Y |


A and B are curve points in affine representation: X concatenated with Y. Fails if A or B is not in G. Does _not_ check if A and B are in the main prime-order subgroup.
Expand All @@ -1586,7 +1586,7 @@ A and B are curve points in affine representation: X concatenated with Y. Fails
- Opcode: 0xe1 {uint8 curve}
- Stack: ..., A: []byte, B: []byte → ..., []byte
- for curve point A and scalar B, return the curve point BA
- **Cost**: BN254_G1=2200 BN254_G2=4460 BLS12_381_G1=3640 BLS12_381_G2=8530
- **Cost**: BN254g1=2200 BN254g2=4460 BLS12_381g1=3640 BLS12_381g2=8530
- Availability: v9

A is a curve point encoded and checked as described in `ec_add`. Scalar B is interpreted as a big-endian unsigned integer.
Expand All @@ -1596,7 +1596,7 @@ A is a curve point encoded and checked as described in `ec_add`. Scalar B is int
- Opcode: 0xe2 {uint8 curve}
- Stack: ..., A: []byte, B: []byte → ..., uint64
- 1 if all points in A (concatenated points in group G) are paired with the corresponding points of B (concatenated points in the associated group), else 0
- **Cost**: BN254_G1=18000 BN254_G2=18000 BLS12_381_G1=15000 BLS12_381_G2=15000
- **Cost**: BN254g1=18000 BN254g2=18000 BLS12_381g1=15000 BLS12_381g2=15000
- Availability: v9

A and B are concatenated points, encoded and checked as described in `ec_add`. A contains points of the group G, B contains points of the associated group (G2 if G is G1, and vice versa). Fails is A and B have a different number of points, or if any point is not in its described group or outside the main prime-order subgroup - a stronger condition than other opcodes.
Expand All @@ -1606,21 +1606,21 @@ A and B are concatenated points, encoded and checked as described in `ec_add`. A
- Opcode: 0xe3 {uint8 curve}
- Stack: ..., A: []byte, B: []byte → ..., []byte
- for curve points A and scalars B, return curve point B0A0 + B1A1 + B2A2 + ... + BnAn
- **Cost**: BN254_G1=800 BN254_G2=1800 BLS12_381_G1=1400 BLS12_381_G2=3500
- **Cost**: BN254g1=800 BN254g2=1800 BLS12_381g1=1400 BLS12_381g2=3500
- Availability: v9

## ec_subgroup_check g

- Opcode: 0xe4 {uint8 curve}
- Stack: ..., A: []byte → ..., uint64
- whether point A is in the main prime-order subgroup of G => {0 or 1}
- **Cost**: BN254_G1=50 BN254_G2=11500 BLS12_381_G1=5600 BLS12_381_G2=7100
- **Cost**: BN254g1=50 BN254g2=11500 BLS12_381g1=5600 BLS12_381g2=7100
- Availability: v9

## ec_map_to g

- Opcode: 0xe5 {uint8 curve}
- Stack: ..., A: []byte → ..., []byte
- maps field element A to group G
- **Cost**: BN254_G1=1700 BN254_G2=11000 BLS12_381_G1=5600 BLS12_381_G2=43000
- **Cost**: BN254g1=1700 BN254g2=11000 BLS12_381g1=5600 BLS12_381g2=43000
- Availability: v9
24 changes: 12 additions & 12 deletions data/transactions/logic/fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -680,14 +680,14 @@ var EcdsaCurves = FieldGroup{
type EcGroup int

const (
// BN254_G1 is the G1 group of BN254
BN254_G1 EcGroup = iota
// BN254_G2 is the G2 group of BN254
BN254_G2
// BL12_381_G1 specifies the G1 group of BLS 12-381
BLS12_381_G1
// BL12_381_G2 specifies the G2 group of BLS 12-381
BLS12_381_G2
// BN254g1 is the G1 group of BN254
BN254g1 EcGroup = iota
// BN254g2 is the G2 group of BN254
BN254g2
// BLS12_381g1 specifies the G1 group of BLS 12-381
BLS12_381g1
// BLS12_381g2 specifies the G2 group of BLS 12-381
BLS12_381g2
invalidEcGroup // compile-time constant for number of fields
)

Expand Down Expand Up @@ -715,10 +715,10 @@ func (fs ecGroupSpec) Note() string {
}

var ecGroupSpecs = [...]ecGroupSpec{
{BN254_G1, "G1 of the BN254 curve. Points encoded as 32 byte X following by 32 byte Y"},
{BN254_G2, "G2 of the BN254 curve. Points encoded as 64 byte X following by 64 byte Y"},
{BLS12_381_G1, "G1 of the BLS 12-381 curve. Points encoded as 48 byte X following by 48 byte Y"},
{BLS12_381_G2, "G2 of the BLS 12-381 curve. Points encoded as 96 byte X following by 48 byte Y"},
{BN254g1, "G1 of the BN254 curve. Points encoded as 32 byte X following by 32 byte Y"},
{BN254g2, "G2 of the BN254 curve. Points encoded as 64 byte X following by 64 byte Y"},
{BLS12_381g1, "G1 of the BLS 12-381 curve. Points encoded as 48 byte X following by 48 byte Y"},
{BLS12_381g2, "G2 of the BLS 12-381 curve. Points encoded as 96 byte X following by 48 byte Y"},
}

func ecGroupSpecByField(c EcGroup) (ecGroupSpec, bool) {
Expand Down
12 changes: 6 additions & 6 deletions data/transactions/logic/fields_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 12 additions & 12 deletions data/transactions/logic/opcodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -637,21 +637,21 @@ var OpSpecs = []OpSpec{

{0xe0, "ec_add", opEcAdd, proto("bb:b"), pairingVersion,
costByField("g", &EcGroups, []int{
BN254_G1: 310, BN254_G2: 430,
BLS12_381_G1: 540, BLS12_381_G2: 750})}, // eip: 500, 800
BN254g1: 310, BN254g2: 430,
BLS12_381g1: 540, BLS12_381g2: 750})}, // eip: 500, 800
{0xe1, "ec_scalar_mul", opEcScalarMul, proto("bb:b"), pairingVersion,
costByField("g", &EcGroups, []int{
BN254_G1: 2200, BN254_G2: 4460,
BLS12_381_G1: 3640, BLS12_381_G2: 8530})}, // eip: 12000, 45000
BN254g1: 2200, BN254g2: 4460,
BLS12_381g1: 3640, BLS12_381g2: 8530})}, // eip: 12000, 45000

// BN cost is 18k per elt, BLS is 45k + 40k per elt. Not putting those
// costs in yet because 1) that is bigger than allowed in logicsigs, so
// tests would fail. 2) We don't yet have support for field specific costs
// that _also_ depend on input sizes.
{0xe2, "ec_pairing_check", opEcPairingCheck, proto("bb:i"), pairingVersion,
costByField("g", &EcGroups, []int{
BN254_G1: 18_000, BN254_G2: 18_000,
BLS12_381_G1: 15_000, BLS12_381_G2: 15_000})}, // eip: 43000*k + 65000
BN254g1: 18_000, BN254g2: 18_000,
BLS12_381g1: 15_000, BLS12_381g2: 15_000})}, // eip: 43000*k + 65000

// This cost must be based on number of points. EIP proposes a complicated
// "discount" scheme. At any rate, as noted above, we don't yet have
Expand All @@ -662,17 +662,17 @@ var OpSpecs = []OpSpec{
// blsG2 seems to be 35000 + 1800 /elt
{0xe3, "ec_multi_exp", opEcMultiExp, proto("bb:b"), pairingVersion,
costByField("g", &EcGroups, []int{
BN254_G1: 800, BN254_G2: 1800, // LIES
BLS12_381_G1: 1400, BLS12_381_G2: 3500})}, // LIES
BN254g1: 800, BN254g2: 1800, // LIES
BLS12_381g1: 1400, BLS12_381g2: 3500})}, // LIES

{0xe4, "ec_subgroup_check", opEcSubgroupCheck, proto("b:i"), pairingVersion,
costByField("g", &EcGroups, []int{
BN254_G1: 50, BN254_G2: 11500, // How is the g1 subgroup check so much faster?
BLS12_381_G1: 5600, BLS12_381_G2: 7100})},
BN254g1: 50, BN254g2: 11500, // How is the g1 subgroup check so much faster?
BLS12_381g1: 5600, BLS12_381g2: 7100})},
{0xe5, "ec_map_to", opEcMapTo, proto("b:b"), pairingVersion,
costByField("g", &EcGroups, []int{
BN254_G1: 1700, BN254_G2: 11000,
BLS12_381_G1: 5600, BLS12_381_G2: 43000})}, // eip: 5500, 75000
BN254g1: 1700, BN254g2: 11000,
BLS12_381g1: 5600, BLS12_381g2: 43000})}, // eip: 5500, 75000
}

type sortByOpcode []OpSpec
Expand Down
48 changes: 24 additions & 24 deletions data/transactions/logic/pairing.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ func opEcAdd(cx *EvalContext) error {
var res []byte
var err error
switch fs.field {
case BN254_G1:
case BN254g1:
res, err = bn254G1Add(a, b)
case BN254_G2:
case BN254g2:
res, err = bn254G2Add(a, b)
case BLS12_381_G1:
case BLS12_381g1:
res, err = bls12381G1Add(a, b)
case BLS12_381_G2:
case BLS12_381g2:
res, err = bls12381G2Add(a, b)
default:
err = fmt.Errorf("invalid ec_add group %s", group)
Expand Down Expand Up @@ -91,13 +91,13 @@ func opEcScalarMul(cx *EvalContext) error {
var res []byte
var err error
switch fs.field {
case BN254_G1:
case BN254g1:
res, err = bn254G1ScalarMul(aBytes, k)
case BN254_G2:
case BN254g2:
res, err = bn254G2ScalarMul(aBytes, k)
case BLS12_381_G1:
case BLS12_381g1:
res, err = bls12381G1ScalarMul(aBytes, k)
case BLS12_381_G2:
case BLS12_381g2:
res, err = bls12381G2ScalarMul(aBytes, k)
default:
err = fmt.Errorf("invalid ec_scalar_mul group %s", group)
Expand Down Expand Up @@ -125,15 +125,15 @@ func opEcPairingCheck(cx *EvalContext) error {
var err error
ok = false
switch fs.field {
case BN254_G2:
case BN254g2:
g1Bytes, g2Bytes = g2Bytes, g1Bytes
fallthrough
case BN254_G1:
case BN254g1:
ok, err = bn254PairingCheck(g1Bytes, g2Bytes)
case BLS12_381_G2:
case BLS12_381g2:
g1Bytes, g2Bytes = g2Bytes, g1Bytes
fallthrough
case BLS12_381_G1:
case BLS12_381g1:
ok, err = bls12381PairingCheck(g1Bytes, g2Bytes)
default:
err = fmt.Errorf("invalid ec_pairing_check group %s", group)
Expand Down Expand Up @@ -161,13 +161,13 @@ func opEcMultiExp(cx *EvalContext) error {
var res []byte
var err error
switch fs.field {
case BN254_G1:
case BN254g1:
res, err = bn254G1MultiExp(g1Bytes, scalarBytes)
case BN254_G2:
case BN254g2:
res, err = bn254G2MultiExp(g1Bytes, scalarBytes)
case BLS12_381_G1:
case BLS12_381g1:
res, err = bls12381G1MultiExp(g1Bytes, scalarBytes)
case BLS12_381_G2:
case BLS12_381g2:
res, err = bls12381G2MultiExp(g1Bytes, scalarBytes)
default:
err = fmt.Errorf("invalid ec_multiexp group %s", group)
Expand All @@ -193,13 +193,13 @@ func opEcSubgroupCheck(cx *EvalContext) error {
var err error
ok = false
switch fs.field {
case BN254_G1:
case BN254g1:
ok, err = bn254G1SubgroupCheck(pointBytes)
case BN254_G2:
case BN254g2:
ok, err = bn254G2SubgroupCheck(pointBytes)
case BLS12_381_G1:
case BLS12_381g1:
ok, err = bls12381G1SubgroupCheck(pointBytes)
case BLS12_381_G2:
case BLS12_381g2:
ok, err = bls12381G2SubgroupCheck(pointBytes)
default:
err = fmt.Errorf("invalid ec_pairing_check group %s", group)
Expand All @@ -225,13 +225,13 @@ func opEcMapTo(cx *EvalContext) error {
var res []byte
var err error
switch fs.field {
case BN254_G1:
case BN254g1:
res, err = bn254MapToG1(fpBytes)
case BN254_G2:
case BN254g2:
res, err = bn254MapToG2(fpBytes)
case BLS12_381_G1:
case BLS12_381g1:
res, err = bls12381MapToG1(fpBytes)
case BLS12_381_G2:
case BLS12_381g2:
res, err = bls12381MapToG2(fpBytes)
default:
err = fmt.Errorf("invalid ec_pairing_check group %s", group)
Expand Down
Loading

0 comments on commit 86e5228

Please sign in to comment.