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

Metropolis aggregate PR #14726

Closed
wants to merge 6 commits into from
Closed

Metropolis aggregate PR #14726

wants to merge 6 commits into from

Conversation

karalabe
Copy link
Member

@karalabe karalabe commented Jun 29, 2017

Todos:

  • EIP 96: Blockhash refactoring

Done:

  • EIP 98: Removal of intermediate state roots from receipts.
  • EIP 100: Change difficulty adjustment to target mean block time including uncles.
  • EIP 197: Precompiled contracts for pairing function check.
  • EIP 198: Precompiled contract for bigint modular exponentiation.
  • EIP 206 (140): New opcode: REVERT ("cheap throw").
  • EIP 208 (86): Abstraction of transaction origin and signature.
  • EIP 211: New opcodes: RETURNDATASIZE and RETURNDATACOPY.
  • EIP 213 (196): Precompiled contracts for addition and scalar multiplication on the elliptic curve alt_bn128.
  • EIP 214: New opcode STATICCALL.

Separated out:

obscuren and others added 3 commits June 29, 2017 11:54
This PR polishes the EIP 100 difficulty adjustment algorithm
to match the same mechanisms as the Homestead was implemented
to keep the code uniform. It also avoids a few memory allocs
by reusing big1 and big2, pulling it out of the common package
and into ethash.

The commit also fixes chain maker to forward the uncle hash
when creating a simulated chain (it wasn't needed until now
so we just skipped a copy there).
@holiman
Copy link
Contributor

holiman commented Jun 30, 2017

Not a concern pre-metro, but the receipt address here seems to use old nonce-based algo: https://github.com/ethereum/go-ethereum/pull/14726/files#diff-5b5942d1b7feac47d38b879796555098R121

@karalabe
Copy link
Member Author

Yeah, I'm waiting for today's meeting about the address scheme before I go through the code and update everything.

@holiman
Copy link
Contributor

holiman commented Jun 30, 2017

Also not a concern pre-metro: in order for a tx to be a valid eip-86 tx, these must also be 0: nonce, value, gasPrice. Is that checked anywhere? I would have expected the new signer to check it.

return nil
var hr homesteadReceiptRLP
var mr metropolisReceiptRLP
if err = rlp.DecodeBytes(raw, &mr); err == nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be active immediately. Is there a possibility that an attacker can insert a metro-receipt before metro is active?

// required for anything significant is so high it's impossible to pay for.
func (c *pairing) RequiredGas(input []byte) uint64 {
//return 0 // TODO
return uint64(60000*len(input) + 40000)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong (and it's my fault). Should be like this: obscuren@90010b2 . @pirapira please verify?

// homestead we must check for CodeStoreOutOfGasError (homestead only
// rule) and treat as an error, if the ruleset is frontier we must
// ignore this error and pretend the operation was successful.
if evm.ChainConfig().IsHomestead(evm.BlockNumber) && suberr == ErrCodeStoreOutOfGas {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Not a concern pre-metro)
Does it make sense to have special handling for Homestead, for an op only on Metro ?

writes: true,
clearsReturndata: true,
},
CREATE2: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoa - why is this in homestead ??

@holiman
Copy link
Contributor

holiman commented Jun 30, 2017

Benchmarks :

BenchmarkPrecompiledEcdsa/-Gas=3000-8  	   50000	    174450 ns/op
BenchmarkPrecompiledSha256/128-Gas=108-8         	10000000	       690 ns/op
BenchmarkPrecompiledRipeMD/128-Gas=1080-8        	 3000000	      2356 ns/op
BenchmarkPrecompiledIdentity/128-Gas=27-8        	500000000	        18.7 ns/op
BenchmarkPrecompiledModexp/eip_example1-Gas=4197376-8         	   50000	    139575 ns/op
BenchmarkPrecompiledModexp/eip_example2-Gas=4459488-8         	 1000000	      7918 ns/op
BenchmarkPrecompiledBn256Add/chfast1-Gas=0-8                  	  100000	     72309 ns/op
BenchmarkPrecompiledBn256Add/chfast2-Gas=0-8                  	  100000	     77082 ns/op
BenchmarkPrecompiledBn256ScalarMul/chfast1-Gas=0-8            	   10000	    707198 ns/op
BenchmarkPrecompiledBn256ScalarMul/chfast2-Gas=0-8            	    3000	   2748802 ns/op
BenchmarkPrecompiledBn256ScalarMul/chfast3-Gas=0-8            	    3000	   2722783 ns/op
BenchmarkPrecompiledPairing/jeff1-Gas=160000-8                	     300	  26254395 ns/op
BenchmarkPrecompiledPairing/jeff2-Gas=160000-8                	     300	  26270137 ns/op
BenchmarkPrecompiledPairing/jeff3-Gas=160000-8                	     300	  26865023 ns/op
BenchmarkPrecompiledPairing/jeff4-Gas=220000-8                	     200	  33845527 ns/op
BenchmarkPrecompiledPairing/jeff5-Gas=220000-8                	     200	  33726438 ns/op
BenchmarkPrecompiledPairing/jeff6-Gas=160000-8                	     300	  26327948 ns/op
BenchmarkPrecompiledPairing/empty_data-Gas=40000-8            	500000000	        15.6 ns/op
BenchmarkPrecompiledPairing/one_point-Gas=100000-8            	     500	  18404827 ns/op
BenchmarkPrecompiledPairing/two_point_match_2-Gas=160000-8    	     500	  16035837 ns/op
BenchmarkPrecompiledPairing/two_point_match_3-Gas=160000-8    	     300	  26066772 ns/op
BenchmarkPrecompiledPairing/two_point_match_4-Gas=160000-8    	     300	  25983786 ns/op
BenchmarkPrecompiledPairing/ten_point_match_1-Gas=640000-8    	     100	  70304992 ns/op
BenchmarkPrecompiledPairing/ten_point_match_2-Gas=640000-8    	     100	  82823341 ns/op
BenchmarkPrecompiledPairing/ten_point_match_3-Gas=160000-8    	     300	  25751592 ns/op
BenchmarkOpAdd64-8                                            	30000000	       240 ns/op
BenchmarkOpAdd128-8                                           	30000000	       248 ns/op
BenchmarkOpAdd256-8                                           	30000000	       262 ns/op
BenchmarkOpSub64-8                                            	30000000	       261 ns/op
BenchmarkOpSub128-8                                           	20000000	       305 ns/op
BenchmarkOpSub256-8                                           	20000000	       387 ns/op
BenchmarkOpMul-8                                              	20000000	       478 ns/op
BenchmarkOpDiv256-8                                           	10000000	       716 ns/op
BenchmarkOpDiv128-8                                           	20000000	       332 ns/op
BenchmarkOpDiv64-8                                            	30000000	       275 ns/op
BenchmarkOpSdiv-8                                             	10000000	      1056 ns/op
BenchmarkOpMod-8                                              	10000000	       688 ns/op
BenchmarkOpSmod-8                                             	10000000	      1138 ns/op
BenchmarkOpExp-8                                              	  200000	     33435 ns/op
BenchmarkOpSignExtend-8                                       	20000000	       428 ns/op
BenchmarkOpLt-8                                               	20000000	       396 ns/op
BenchmarkOpGt-8                                               	20000000	       392 ns/op
BenchmarkOpSlt-8                                              	10000000	       650 ns/op
BenchmarkOpSgt-8                                              	10000000	       644 ns/op
BenchmarkOpEq-8                                               	20000000	       376 ns/op
BenchmarkOpAnd-8                                              	20000000	       355 ns/op
BenchmarkOpOr-8                                               	20000000	       359 ns/op
BenchmarkOpXor-8                                              	20000000	       368 ns/op
BenchmarkOpByte-8                                             	20000000	       354 ns/op
BenchmarkOpAddmod-8                                           	10000000	       919 ns/op
BenchmarkOpMulmod-8                                           	10000000	      1186 ns/op

@mattdf
Copy link
Member

mattdf commented Jul 7, 2017

Important thing to note for the benchmarks, the bn256 Go implementation from the Google crypto libs is incomplete. It doesn't handle the case where the points you're trying to add are equal to each other.

See:

https://github.com/golang/crypto/blob/master/bn256/bn256.go#L76

The Go equivalent of the following needs to be implemented:

https://github.com/scipr-lab/libsnark/blob/master/src/algebra/curves/alt_bn128/alt_bn128_g1.cpp#L325

Edit: Never mind! I see it's been added in curve.go - the comments in bn256.go are just misleading.

Copy link
Contributor

@holiman holiman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll make a PR, as I'm going to do that anyway for some new benchmarks.

var (
baseLen = new(big.Int).SetBytes(input[:31])
expLen = math.BigMax(new(big.Int).SetBytes(input[32:64]), big.NewInt(1))
modLen = new(big.Int).SetBytes(input[65:97])
Copy link
Contributor

@holiman holiman Jul 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These three are wrong, should be the same as the calculations in Run below (but without constraining them to Uint64() as the Run does:

	baseLen  = new(big.Int).SetBytes(input[:32])
	expLen   = new(big.Int).SetBytes(input[32:64])
	modLen   = new(big.Int).SetBytes(input[64:96])

@karalabe
Copy link
Member Author

All code pulled out from this PR, and superseded by the individual PRs linked in the description. Closing this one.

@karalabe karalabe closed this Aug 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants