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

Update precompile address: point evaluation #21

Merged
merged 3 commits into from
Sep 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions contracts/EthStorageContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ import "./Decoder.sol";
import "./BinaryRelated.sol";

contract EthStorageContract is StorageContract, Decoder {
uint256 constant modulusBls = 0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001;
uint256 constant ruBls = 0x564c0a11a0f704f4fc3e8acfe0f8245f0ad1347b378fbf96e206da11a5d36306;
uint256 constant ruBn254 = 0x931d596de2fd10f01ddd073fd5a90a976f169c76f039bb91c4775720042d43a;
uint256 constant modulusBn254 = 0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001;
uint256 constant fieldElementsPerBlob = 0x1000;

event PutBlob(uint256 indexed kvIdx, uint256 indexed kvSize, bytes32 indexed dataHash);

constructor(
Expand Down Expand Up @@ -51,12 +57,17 @@ contract EthStorageContract is StorageContract, Decoder {
x := mload(add(input, 0x40))
y := mload(add(input, 0x60))

// Call the precompiled contract 0x14 = point evaluation, reuse scratch to get the results
if iszero(staticcall(not(0), 0x14, add(input, 0x20), 0xc0, 0x0, 0x40)) {
// Call the precompiled contract 0x0a = point evaluation, reuse scratch to get the results
if iszero(staticcall(not(0), 0x0a, add(input, 0x20), 0xc0, 0x0, 0x40)) {
revert(0, 0)
}
// Check the results
if iszero(eq(mload(0x0), fieldElementsPerBlob)) {
revert(0, 0)
}
if iszero(eq(mload(0x20), modulusBls)) {
revert(0, 0)
}

// TODO: Check the results
}
}

Expand All @@ -66,8 +77,6 @@ contract EthStorageContract is StorageContract, Decoder {
uint256 sampleIdxInKv,
uint256 mask
) public view returns (bool) {
uint256 ruBn254 = 0x931d596de2fd10f01ddd073fd5a90a976f169c76f039bb91c4775720042d43a;
uint256 modulusBn254 = 0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001;
uint256 xBn254 = modExp(ruBn254, sampleIdxInKv, modulusBn254);

uint256[] memory input = new uint256[](3);
Expand All @@ -84,8 +93,6 @@ contract EthStorageContract is StorageContract, Decoder {
uint256 decodedData,
bytes memory peInput
) public view returns (bool) {
uint256 ruBls = 0x564c0a11a0f704f4fc3e8acfe0f8245f0ad1347b378fbf96e206da11a5d36306;
uint256 modulusBls = 0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001;
// peInput includes an input point that comes from bit reversed sampleIdxInKv
uint256 sampleIdxInKvRev = BinaryRelated.reverseBits(12, sampleIdxInKv);
uint256 xBls = modExp(ruBls, sampleIdxInKvRev, modulusBls);
Expand Down