github.com/kotalco/kotal@v0.3.0/clients/ethereum/accounts.go (about)

     1  package ethereum
     2  
     3  import (
     4  	"fmt"
     5  
     6  	ethereumv1alpha1 "github.com/kotalco/kotal/apis/ethereum/v1alpha1"
     7  )
     8  
     9  // genesisAccounts returns genesis config accounts
    10  func genesisAccounts(withBuiltins bool, forks *ethereumv1alpha1.Forks) map[string]interface{} {
    11  	accounts := map[string]interface{}{}
    12  	for i := 0; i < 256; i++ {
    13  		address := fmt.Sprintf("%#040x", i)
    14  		var fn map[string]interface{}
    15  		if i >= 1 && i <= 9 {
    16  			if withBuiltins {
    17  				fn = builtinFunction(i, forks)
    18  			}
    19  			accounts[address] = map[string]interface{}{
    20  				"balance": "0x1",
    21  				"builtin": fn,
    22  			}
    23  		} else {
    24  			accounts[address] = map[string]interface{}{
    25  				"balance": "0x1",
    26  			}
    27  		}
    28  	}
    29  	return accounts
    30  }
    31  
    32  // builtinFunction returns built in parity functions
    33  func builtinFunction(i int, forks *ethereumv1alpha1.Forks) map[string]interface{} {
    34  	switch i {
    35  	case 1:
    36  		return ecRecover()
    37  	case 2:
    38  		return sha256()
    39  	case 3:
    40  		return ripemd160()
    41  	case 4:
    42  		return identity()
    43  	case 5:
    44  		return modexp(forks)
    45  	case 6:
    46  		return altBn128Add(forks)
    47  	case 7:
    48  		return altBn128Mul(forks)
    49  	case 8:
    50  		return altBn128Pairing(forks)
    51  	case 9:
    52  		return blake2(forks)
    53  	}
    54  	return nil
    55  }
    56  
    57  // ecRecover revcovers public key from elliptic curve signature
    58  func ecRecover() map[string]interface{} {
    59  	return map[string]interface{}{
    60  		"name": "ecrecover",
    61  		"pricing": map[string]interface{}{
    62  			"linear": map[string]int{
    63  				"base": 3000,
    64  				"word": 0,
    65  			},
    66  		},
    67  	}
    68  }
    69  
    70  // sha256 is sha256 function
    71  func sha256() map[string]interface{} {
    72  	return map[string]interface{}{
    73  		"name": "sha256",
    74  		"pricing": map[string]interface{}{
    75  			"linear": map[string]int{
    76  				"base": 60,
    77  				"word": 12,
    78  			},
    79  		},
    80  	}
    81  }
    82  
    83  // ripemd160 is ripemd160 hash function
    84  func ripemd160() map[string]interface{} {
    85  	return map[string]interface{}{
    86  		"name": "ripemd160",
    87  		"pricing": map[string]interface{}{
    88  			"linear": map[string]int{
    89  				"base": 600,
    90  				"word": 120,
    91  			},
    92  		},
    93  	}
    94  }
    95  
    96  // identity function
    97  func identity() map[string]interface{} {
    98  	return map[string]interface{}{
    99  		"name": "identity",
   100  		"pricing": map[string]interface{}{
   101  			"linear": map[string]int{
   102  				"base": 15,
   103  				"word": 3,
   104  			},
   105  		},
   106  	}
   107  }
   108  
   109  // modexp is modular exponentiaiton function
   110  func modexp(forks *ethereumv1alpha1.Forks) map[string]interface{} {
   111  	byzantiumBlock := fmt.Sprintf("%#x", forks.Byzantium)
   112  	berlinBlock := fmt.Sprintf("%#x", forks.Berlin)
   113  
   114  	return map[string]interface{}{
   115  		"name": "modexp",
   116  		"pricing": map[string]interface{}{
   117  			byzantiumBlock: map[string]interface{}{
   118  				"info": "EIP-198: Big integer modular exponentiation.",
   119  				"price": map[string]interface{}{
   120  					"modexp": map[string]uint{
   121  						"divisor": 20,
   122  					},
   123  				},
   124  			},
   125  			berlinBlock: map[string]interface{}{
   126  				"info": "EIP-2565: ModExp Gas Cost.",
   127  				"price": map[string]interface{}{
   128  					"modexp2565": map[string]interface{}{},
   129  				},
   130  			},
   131  		},
   132  	}
   133  }
   134  
   135  // altBn128Add is elliptic curve add function
   136  func altBn128Add(forks *ethereumv1alpha1.Forks) map[string]interface{} {
   137  
   138  	byzantiumBlock := fmt.Sprintf("%#x", forks.Byzantium)
   139  	istanbulBlock := fmt.Sprintf("%#x", forks.Istanbul)
   140  
   141  	return map[string]interface{}{
   142  		"name": "alt_bn128_add",
   143  		"pricing": map[string]interface{}{
   144  			byzantiumBlock: map[string]interface{}{
   145  				"price": map[string]interface{}{
   146  					"alt_bn128_const_operations": map[string]int{
   147  						"price": 500,
   148  					},
   149  				},
   150  			},
   151  			istanbulBlock: map[string]interface{}{
   152  				"info": "EIP 1108 transition",
   153  				"price": map[string]interface{}{
   154  					"alt_bn128_const_operations": map[string]int{
   155  						"price": 150,
   156  					},
   157  				},
   158  			},
   159  		},
   160  	}
   161  }
   162  
   163  // altBn128Mul is elliptic function Multiplication funciton
   164  func altBn128Mul(forks *ethereumv1alpha1.Forks) map[string]interface{} {
   165  
   166  	byzantiumBlock := fmt.Sprintf("%#x", forks.Byzantium)
   167  	istanbulBlock := fmt.Sprintf("%#x", forks.Istanbul)
   168  
   169  	return map[string]interface{}{
   170  		"name": "alt_bn128_mul",
   171  		"pricing": map[string]interface{}{
   172  			byzantiumBlock: map[string]interface{}{
   173  				"price": map[string]interface{}{
   174  					"alt_bn128_const_operations": map[string]int{
   175  						"price": 40000,
   176  					},
   177  				},
   178  			},
   179  			istanbulBlock: map[string]interface{}{
   180  				"info": "EIP 1108 transition",
   181  				"price": map[string]interface{}{
   182  					"alt_bn128_const_operations": map[string]int{
   183  						"price": 6000,
   184  					},
   185  				},
   186  			},
   187  		},
   188  	}
   189  }
   190  
   191  // altBn128Pairing is elliptic curve pairing function
   192  func altBn128Pairing(forks *ethereumv1alpha1.Forks) map[string]interface{} {
   193  
   194  	byzantiumBlock := fmt.Sprintf("%#x", forks.Byzantium)
   195  	istanbulBlock := fmt.Sprintf("%#x", forks.Istanbul)
   196  
   197  	return map[string]interface{}{
   198  		"name": "alt_bn128_pairing",
   199  		"pricing": map[string]interface{}{
   200  			byzantiumBlock: map[string]interface{}{
   201  				"price": map[string]interface{}{
   202  					"alt_bn128_pairing": map[string]int{
   203  						"base": 100000,
   204  						"pair": 80000,
   205  					},
   206  				},
   207  			},
   208  			istanbulBlock: map[string]interface{}{
   209  				"info": "EIP 1108 transition",
   210  				"price": map[string]interface{}{
   211  					"alt_bn128_pairing": map[string]int{
   212  						"base": 45000,
   213  						"pair": 34000,
   214  					},
   215  				},
   216  			},
   217  		},
   218  	}
   219  }
   220  
   221  // blake2 is blake hash function
   222  func blake2(forks *ethereumv1alpha1.Forks) map[string]interface{} {
   223  
   224  	return map[string]interface{}{
   225  		"name":        "blake2_f",
   226  		"activate_at": fmt.Sprintf("%#x", forks.Istanbul),
   227  		"pricing": map[string]interface{}{
   228  			"blake2_f": map[string]interface{}{
   229  				"gas_per_round": 1,
   230  			},
   231  		},
   232  	}
   233  }