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

[EIP-4844] Return Modulus From Precompile #5864

Merged
merged 5 commits into from
Nov 22, 2022

Conversation

adietrichs
Copy link
Member

Modifies the point evaluation precompile to return the BLS modulus as a U256 value.
Motivation / rationale to be provided by @dankrad, draft PR until then.

@github-actions github-actions bot added c-update Modifies an existing proposal s-draft This EIP is a Draft t-core labels Nov 1, 2022
@eth-bot
Copy link
Collaborator

eth-bot commented Nov 1, 2022

All tests passed; auto-merging...

(pass) eip-4844.md

classification
updateEIP
  • passed!

@dankrad
Copy link
Contributor

dankrad commented Nov 1, 2022

The idea of the VersionedHash is that it enables upgrading the commitment type (for example, to a post-quantum polynomial commitment) without requiring a smart contract upgrade. The PointEvaluationPrecompile simply takes a versioned hash with a proof, and will continue to work once a new commitment type is introduced, possibly on both old and new commitments (or only new ones depending on circumstances of the upgrade).

The PointEvaluationPrecompile can be used by both Optimistic Rollups and zkRollups. The former use it by simply evaluating it at a point determined by the fraud proof game, the latter use this trick in order to determine equivalence to an internal representation of the polynomial.

However, the evaluation happens inside a finite field, and it is only well defined if the field modulus is known. Smart contracts could contain a table mapping the commitment version to a modulus, but this would not allow smart contract to take into account future upgrades to a modulus that is not known yet. By allowing access to the modulus inside the EVM, the smart contract can be built so that it can use future commitments and proofs, without ever needing an upgrade.

In the interest of not adding another precompile, we use the easiest way possible to add this functionality: Just make the PointEvaluationPrecompile return the modulus as well. It can then be used by the caller. It is also "free" in that the caller can just ignore this part of the return value without incurring an extra cost -- systems that remain upgradable for the foreseeable future will likely use this route for now.

EIPS/eip-4844.md Outdated Show resolved Hide resolved
@adietrichs adietrichs marked this pull request as ready for review November 8, 2022 03:56
@adietrichs
Copy link
Member Author

I added a short version of the explanation by @dankrad to the EIP rationale section. The PR is now open and should be ready to be merged.

dankrad
dankrad previously approved these changes Nov 8, 2022
@eth-bot eth-bot enabled auto-merge (squash) November 8, 2022 12:04
eth-bot
eth-bot previously approved these changes Nov 8, 2022
@adietrichs
Copy link
Member Author

Regarding the structuring of return data:
Our approach here does meaningfully deviate from prior precompile precedent:

The bn128 pairing check
https://github.com/ethereum/execution-specs/blob/master/src/ethereum/paris/vm/precompiled_contracts/alt_bn128.py#L154

  • explicitly returns the success value (instead of making the precompile call fail if success == False)
  • pads the return value to 32 bytes

I personally prefer our approach, but there might be value in sticking with precedent?

@SamWilsn
Copy link
Contributor

I am not qualified to comment on reverting in a precompile (though I can't see why it would be a problem.)

That said, it might be best to format the return value according to Solidity ABI encoding?

uint<M>: enc(X) is the big-endian encoding of X, padded on the higher-order (left) side with zero-bytes such that the length is 32 bytes.

@adietrichs adietrichs marked this pull request as draft November 19, 2022 18:02
@adietrichs adietrichs dismissed stale reviews from eth-bot and dankrad via dae771e November 22, 2022 03:04
@adietrichs
Copy link
Member Author

That said, it might be best to format the return value according to Solidity ABI encoding?

uint<M>: enc(X) is the big-endian encoding of X, padded on the higher-order (left) side with zero-bytes such that the length is 32 bytes.

Added padding for the degree value, so the precompile returns 2*32 bytes now.

@adietrichs
Copy link
Member Author

Already reviewed by @dankrad and @protolambda, merging now.

@adietrichs adietrichs marked this pull request as ready for review November 22, 2022 03:09
@adietrichs adietrichs closed this Nov 22, 2022
@adietrichs adietrichs reopened this Nov 22, 2022
@eth-bot eth-bot merged commit 1226bfe into ethereum:master Nov 22, 2022
@adietrichs adietrichs deleted the 4844-modulus branch November 22, 2022 04:03
@@ -271,7 +271,7 @@ def point_evaluation_precompile(input: Bytes) -> Bytes:
# Quotient kzg: next 48 bytes
quotient_kzg = input[144:192]
assert verify_kzg_proof(data_kzg, x, y, quotient_kzg)
return Bytes([])
return Bytes(U256(FIELD_ELEMENTS_PER_BLOB).to_bytes32() + U256(BLS_MODULUS).to_bytes32())
Copy link
Member

Choose a reason for hiding this comment

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

Is this little or big endian? Should be clarified.

Copy link
Contributor

Choose a reason for hiding this comment

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

Should be big endian as the EVM is?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I will clarify in a quick separate PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c-update Modifies an existing proposal s-draft This EIP is a Draft t-core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants