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

evm: Add EIP-2537 BLS12-381 precompiles #111

Merged
merged 9 commits into from
Oct 21, 2024
Merged

Conversation

hyunsooda
Copy link
Contributor

@hyunsooda hyunsooda commented Oct 16, 2024

Proposed changes

History

Implementation

  • Ported EIP2537
  • As Kaia does not have OSS fuzz system, fuzzer-related stuff were not grabbed.

This is an example contract that calls add operations.

// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity 0.8.24;

contract EIP2537 {

    function bls12381add() public returns (bytes memory) {
        bytes memory input = hex"0000000000000000000000000000000012196c5a43d69224d8713389285f26b98f86ee910ab3dd668e413738282003cc5b7357af9a7af54bb713d62255e80f560000000000000000000000000000000006ba8102bfbeea4416b710c73e8cce3032c31c6269c44906f8ac4f7874ce99fb17559992486528963884ce429a992fee000000000000000000000000000000000001101098f5c39893765766af4512a0c74e1bb89bc7e6fdf14e3e7337d257c
c0f94658179d83320b99f31ff94cd2bac0000000000000000000000000000000003e1a9f9f44ca2cdab4f43a1a3ee3470fdf90b2fc228eb3b709fcd72f014838ac82a6d797aeefed9a0804b22ed1ce8f7";
        (bool ok, bytes memory output) = address(0x0b).call(input);
        require(ok, "bls12381 add operation failed");
        return output;
    }
}

Once deployed, can be called like this

> kaia.call({to:addr, data:"0xa1abdc96"}) // "0xa1abdc96" is the selector of "bls12381add()" function.
> 0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000001466e1373ae4a7e7ba885c5f0c3ccfa48cdb50661646ac6b779952f466ac9fc92730dcaed9be831cd1f8c4fefffd5209000000000000000000000000000000000c1fb750d2285d4ca0378e1e8cdbf6044151867c34a711b73ae818aee6dbe9e886f53d7928cc6ed9c851e0422f609b11

The output of bytes memory is encoded as offset(32bytes) | length(32bytes) | value(conductive 32bytes).
The actual value of add operation starts from 64, the total output size is 192 bytes, and the actual value size is 128 bytes.

Discussion

The calculated CC numbers were based on static execution (comparison with other existing operations). add operation was selected and the CC value was derived from below.

CC = Base_CC * New_Gas / Base_Gas

Types of changes

Please put an x in the boxes related to your change.

  • Bugfix
  • New feature or enhancement
  • Others

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

  • I have read the CONTRIBUTING GUIDELINES doc
  • I have read the CLA and signed by comment I have read the CLA Document and I hereby sign the CLA in first time contribute
  • Lint and unit tests pass locally with my changes ($ make test)
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • Any dependent changes have been merged and published in downstream modules

Related issues

  • Please leave the issue numbers or links related to this PR here.

Further comments

If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...

@hyunsooda
Copy link
Contributor Author

@ian0371

I initially tried to remove this comment from this PR, but some words(bls-signature) were a little odd to me, so they have not been removed yet. If this comment just targeted BLS12381 operations, let me remove it.

Copy link
Collaborator

@ian0371 ian0371 left a comment

Choose a reason for hiding this comment

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

I only updated TODO-klaytn to TODO-kaia. @yoomee1313 commented the original one.

@blukat29 blukat29 changed the title evm: Ported EIP2537 evm: Add EIP-2537 BLS12-381 precompiles Oct 17, 2024
@hyunsooda hyunsooda merged commit de62451 into kaiachain:dev Oct 21, 2024
11 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Oct 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants