Skip to content

Commit

Permalink
feat: added require to test that the result value from the gateway is…
Browse files Browse the repository at this point in the history
… equal to the calculated value
  • Loading branch information
Julink-eth committed Apr 7, 2023
1 parent 377b7c6 commit b8ba1c6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 23 deletions.
9 changes: 2 additions & 7 deletions packages/contracts/contracts/l1/LineaResolverStub.sol
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.9;
pragma abicoder v2;

import { Lib_OVMCodec } from "@eth-optimism/contracts/libraries/codec/Lib_OVMCodec.sol";
import { Lib_SecureMerkleTrie } from "@eth-optimism/contracts/libraries/trie/Lib_SecureMerkleTrie.sol";
import { Lib_RLPReader } from "@eth-optimism/contracts/libraries/rlp/Lib_RLPReader.sol";
import { Lib_BytesUtils } from "@eth-optimism/contracts/libraries/utils/Lib_BytesUtils.sol";

import "hardhat/console.sol";

struct L2StateProof {
uint64 nodeIndex;
bytes32 blockHash;
Expand Down Expand Up @@ -120,12 +117,10 @@ contract LineaResolverStub is IExtendedResolver, SupportsInterface {

require(
keccak256(proof.result) == keccak256(abi.encode(value)),
"NEEDS TO BE EQUAL"
"LineaResolverStub: value different from expected result"
);
console.logBytes(proof.result);
console.logBytes(abi.encode(value));

return abi.encode(value);
return proof.result;
}

function getl2Resolver() external view returns (address) {
Expand Down
20 changes: 10 additions & 10 deletions packages/contracts/contracts/l2/LineaResolver.sol
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.9;

import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";

contract LineaResolver is Ownable {
mapping(bytes32 => address) addresses;
mapping(bytes32 => address) addresses;

event AddrChanged(bytes32 indexed node, address a);
event AddrChanged(bytes32 indexed node, address a);

function setAddr(bytes32 node, address _addr) public onlyOwner {
addresses[node] = _addr;
emit AddrChanged(node, _addr);
}
function setAddr(bytes32 node, address _addr) public {
addresses[node] = _addr;
emit AddrChanged(node, _addr);
}

function addr(bytes32 node) public view returns (address) {
return addresses[node];
}
function addr(bytes32 node) public view returns (address) {
return addresses[node];
}
}
2 changes: 1 addition & 1 deletion packages/contracts/scripts/deployL1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async function main() {
}

// Deploy Linea Resolver Stub to L1
const gatewayUrl = process.env.GATEWAY_URL ? process.env.GATEWAY_URL : "http://localhost:8080/{sender}/{data}.json";
const gatewayUrl = process.env.GATEWAY_URL ? process.env.GATEWAY_URL : "https://www.ensgateway.amineharty.me/{sender}/{data}.json";
const rollupAddress = ROLLUP_ADDRESSES[network.name as keyof typeof ROLLUP_ADDRESSES];
const LineaResolverStub = await ethers.getContractFactory("LineaResolverStub");
const lineaResolverStub = await LineaResolverStub.deploy([gatewayUrl], rollupAddress, L2_RESOLVER_ADDRESS);
Expand Down
6 changes: 1 addition & 5 deletions packages/gateway/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ function decodeDnsName(dnsname: Buffer) {
async function getResult(
name: string,
data: string
): Promise<{ result: BytesLike; validUntil: number }> {
): Promise<{ result: BytesLike }> {
// Parse the data nested inside the second argument to `resolve`
const { signature, args } = Resolver.parseTransaction({ data });
console.log("signature", signature);
Expand All @@ -188,11 +188,7 @@ async function getResult(
const node = ethers.utils.namehash(name);
const result = await resolverL2.addr(node);

const test = Resolver.encodeFunctionResult(signature, [result]);
console.log("test", test);

return {
result: Resolver.encodeFunctionResult(signature, [result]),
validUntil: Math.floor(Date.now() / 1000),
};
}

0 comments on commit b8ba1c6

Please sign in to comment.