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

Remove winston #53

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
11 changes: 6 additions & 5 deletions abi/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import {
BedrockCcipVerifier__factory,
BedrockProofVerifier__factory,
IBedrockProofVerifier__factory,
SignatureCcipVerifier__factory, CcipResponseVerifier__factory,
SignatureCcipVerifier__factory,
CcipResponseVerifier__factory,
ICcipResponseVerifier__factory,
ERC3668Resolver__factory,
IExtendedResolver__factory,
IMetadataResolver__factory,
SupportsInterface__factory
} from "../typechain"
SupportsInterface__factory,
} from '../typechain';

export default {
ProofServiceTestContract: ProofServiceTestContract__factory.abi,
Expand All @@ -22,5 +23,5 @@ export default {
ERC3668Resolver: ERC3668Resolver__factory.abi,
IExtendedResolver: IExtendedResolver__factory.abi,
IMetadataResolver: IMetadataResolver__factory.abi,
SupportsInterface: SupportsInterface__factory.abi
}
SupportsInterface: SupportsInterface__factory.abi,
};
8 changes: 4 additions & 4 deletions contracts/ERC3668Resolver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ contract ERC3668Resolver is IExtendedResolver, IMetadataResolver, SupportsInterf
/*
* Retrieves the owner of the node. NameWrapper profiles are supported too. This will be the context of the request.
*/
address nodeOwner = getNameOwner(name, 0);
address nodeOwner = getNameOwner(name, 0);
bytes memory context = abi.encodePacked(nodeOwner);

/*
Expand Down Expand Up @@ -279,11 +279,11 @@ contract ERC3668Resolver is IExtendedResolver, IMetadataResolver, SupportsInterf
bytes32 node = name.namehash(offset);
(, offset) = name.readLabel(offset);
nodeOwner = ensRegistry.owner(node);
if(offset >= name.length) {
if (offset >= name.length) {
return address(0);
}else if (nodeOwner == address(0)){
} else if (nodeOwner == address(0)) {
return getNameOwner(name, offset);
}else if(nodeOwner == address(nameWrapper)){
} else if (nodeOwner == address(nameWrapper)) {
return nameWrapper.ownerOf(uint256(node));
}
return nodeOwner;
Expand Down
4 changes: 3 additions & 1 deletion contracts/IMetadataResolver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ interface IMetadataResolver {
* @return context can be l2 resolver contract address for evm chain but can be any l2 storage identifier for non evm chain
*
*/
function metadata(bytes calldata name) external view returns (string memory, uint256, string memory, uint8, bytes memory, bytes memory);
function metadata(
bytes calldata name
) external view returns (string memory, uint256, string memory, uint8, bytes memory, bytes memory);
}
8 changes: 6 additions & 2 deletions contracts/verifier/optimism-bedrock/BedrockProofVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ contract BedrockProofVerifier is IBedrockProofVerifier {
* See https://github.com/ethereum-optimism/optimism/blob/4611198bf8bfd16563cc6bdf49bb35eed2e46801/packages/contracts-bedrock/contracts/L1/OptimismPortal.sol#L261
*/
require(
l2OutputOracle.getL2Output(proof.l2OutputIndex).outputRoot == Hashing.hashOutputRootProof(proof.outputRootProof),
l2OutputOracle.getL2Output(proof.l2OutputIndex).outputRoot ==
Hashing.hashOutputRootProof(proof.outputRootProof),
"Invalid output root"
);

Expand Down Expand Up @@ -110,7 +111,10 @@ contract BedrockProofVerifier is IBedrockProofVerifier {
* @param storageProof the StorageProof struct containing the necessary proof data
* @return the retrieved storage proof value or 0x if the storage slot is empty
*/
function getSingleStorageProof(bytes32 storageRoot, StorageProof memory storageProof) private pure returns (bytes memory) {
function getSingleStorageProof(
bytes32 storageRoot,
StorageProof memory storageProof
) private pure returns (bytes memory) {
(bool storageExists, bytes memory retrievedValue) = Lib_SecureMerkleTrie.get(
abi.encodePacked(storageProof.key),
storageProof.storageTrieWitness,
Expand Down
18 changes: 15 additions & 3 deletions contracts/verifier/signature/SignatureVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ library SignatureVerifier {
* @param request: The original request that was sent.
* @param result: The `result` field of the response (not including the signature part).
*/
function makeSignatureHash(address target, uint64 expires, bytes memory request, bytes memory result) internal pure returns (bytes32) {
function makeSignatureHash(
address target,
uint64 expires,
bytes memory request,
bytes memory result
) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(hex"1900", target, expires, keccak256(request), keccak256(result)));
}

Expand All @@ -24,9 +29,16 @@ library SignatureVerifier {
* @return signer: The address that signed this message.
* @return result: The `result` decoded from `response`.
*/
function verify(address resolver, bytes calldata request, bytes calldata response) internal view returns (address, bytes memory) {
function verify(
address resolver,
bytes calldata request,
bytes calldata response
) internal view returns (address, bytes memory) {
(bytes memory result, uint64 expires, bytes memory sig) = abi.decode(response, (bytes, uint64, bytes));
address signer = ECDSA.recover(ECDSA.toEthSignedMessageHash(makeSignatureHash(resolver, expires, request, result)), sig);
address signer = ECDSA.recover(
ECDSA.toEthSignedMessageHash(makeSignatureHash(resolver, expires, request, result)),
sig
);
require(expires >= block.timestamp, "SignatureVerifier: Signature expired");
return (signer, result);
}
Expand Down
4 changes: 2 additions & 2 deletions gateway/handler/signing/signAndEncodeResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export async function signAndEncodeResponse(
ttl: number = 30000,
): Promise<string> {
const validUntil = Math.floor(Date.now() / 1000 + ttl);
global.logger.debug({ message: 'signAndEncodeResponse', signer, resolverAddr, result, calldata, validUntil });
console.debug({ message: 'signAndEncodeResponse', signer, resolverAddr, result, calldata, validUntil });
/**
* This hash has to be compiled the same way as at the OffchainResolver.makeSignatureHash method
* since it'll be compared within the {@see resolveWithProof} function
Expand All @@ -34,6 +34,6 @@ export async function signAndEncodeResponse(
*/
const sig = await signer.signMessage(msgHashDigest);

global.logger.debug({ message: 'signAndEncodeResponse result', result, validUntil, sig });
console.debug({ message: 'signAndEncodeResponse result', result, validUntil, sig });
return ethers.utils.defaultAbiCoder.encode(['bytes', 'uint64', 'bytes'], [result, validUntil, sig]);
}
3 changes: 1 addition & 2 deletions gateway/handler/signing/signingHandler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import axios from 'axios';
import { ethers } from 'ethers';
import { Logger } from 'winston';

import { SigningConfigEntry } from '../../config/Config';

Expand Down Expand Up @@ -37,6 +36,6 @@ export async function signingHandler(calldata: string, resolverAddr: string, con
* Sign and encode the response the signingHandler has returned using the private key from the environment variable.
*/
const signer = new ethers.Wallet(singerPk);
global.logger.info({ message: 'signingHandler', signer: signer.address });
console.info({ message: 'signingHandler', signer: signer.address });
return signAndEncodeResponse(signer, resolverAddr, result, calldata);
}
13 changes: 6 additions & 7 deletions gateway/http/ccipGateway.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import express from 'express';
import { Logger } from 'winston';

import { ConfigReader } from '../config/ConfigReader';
import { optimismBedrockHandler } from '../handler/optimism-bedrock/optimismBedrockHandler';
Expand Down Expand Up @@ -33,7 +32,7 @@ export function ccipGateway(configReader: ConfigReader) {
/**
* If there is no config entry for the resolverAddr, we return a 404. As there is no way for the gateway to resolve the request
*/
global.logger.warn(`Unknown resolver selector pair for resolverAddr: ${resolverAddr}`);
console.warn(`Unknown resolver selector pair for resolverAddr: ${resolverAddr}`);

res.status(404).send({
message: 'Unknown resolver selector pair',
Expand All @@ -46,15 +45,15 @@ export function ccipGateway(configReader: ConfigReader) {
*/
switch (configEntry.type) {
case 'signing': {
global.logger.info({ type: 'signing' });
global.logger.debug({ type: 'signing', calldata, resolverAddr, configEntry });
console.info({ type: 'signing' });
console.debug({ type: 'signing', calldata, resolverAddr, configEntry });
const response = await signingHandler(calldata, resolverAddr, configEntry);
res.status(200).send({ data: response });
break;
}
case 'optimism-bedrock': {
global.logger.info({ type: 'optimism-bedrock' });
global.logger.debug({ type: 'optimism-bedrock', calldata, resolverAddr, configEntry });
console.info({ type: 'optimism-bedrock' });
console.debug({ type: 'optimism-bedrock', calldata, resolverAddr, configEntry });
const response = await optimismBedrockHandler(calldata, resolverAddr, configEntry);

res.status(200).send({ data: response });
Expand All @@ -67,7 +66,7 @@ export function ccipGateway(configReader: ConfigReader) {
});
}
} catch (e) {
global.logger.warn((e as Error).message);
console.warn((e as Error).message);
res.status(400).send({ message: 'ccip gateway error ,' + e });
}
});
Expand Down
34 changes: 12 additions & 22 deletions gateway/index.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,17 @@
import * as dotenv from "dotenv";
import bodyParser from "body-parser";
import express from "express";
import http from "http";
import cors from "cors";
import winston from "winston";
import * as dotenv from 'dotenv';
import bodyParser from 'body-parser';
import express from 'express';
import http from 'http';
import cors from 'cors';

import { ccipGateway } from "./http/ccipGateway";
import { getConfigReader } from "./config/ConfigReader";
import { ccipGateway } from './http/ccipGateway';
import { getConfigReader } from './config/ConfigReader';

dotenv.config();

declare global {
var logger: winston.Logger
}

global.logger = winston.createLogger({
level: process.env.LOG_LEVEL ?? 'info',
transports: [new winston.transports.Console()],
});

const app = express();
app.use(express.json({ limit: "50mb" }));
app.use(express.urlencoded({ limit: "50mb" }));
app.use(express.json({ limit: '50mb' }));
app.use(express.urlencoded({ limit: '50mb' }));

const server = http.createServer(app);

Expand All @@ -30,9 +20,9 @@ app.use(bodyParser.json());

(async () => {
const config = getConfigReader(process.env.CONFIG);
app.use("/", ccipGateway(config));
app.use('/', ccipGateway(config));
})();
const port = process.env.PORT || "8081";
const port = process.env.PORT || '8081';
server.listen(port, () => {
global.logger.info("[Server] listening at port " + port + " and dir " + __dirname);
console.info('[Server] listening at port ' + port + ' and dir ' + __dirname);
});
24 changes: 12 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
const ProofServiceTestContract = require("./build/contracts/test-contract/ProofServiceTestContract");
const ProofServiceTestContract = require('./build/contracts/test-contract/ProofServiceTestContract');

const BedrockCcipVerifier = require("./build/contracts/verifier/optimism-bedrock/BedrockCcipVerifier");
const BedrockProofVerifier = require("./build/contracts/verifier/optimism-bedrock/BedrockProofVerifier");
const IBedrockProofVerifier = require("./build/contracts/verifier/optimism-bedrock/IBedrockProofVerifier");
const BedrockCcipVerifier = require('./build/contracts/verifier/optimism-bedrock/BedrockCcipVerifier');
const BedrockProofVerifier = require('./build/contracts/verifier/optimism-bedrock/BedrockProofVerifier');
const IBedrockProofVerifier = require('./build/contracts/verifier/optimism-bedrock/IBedrockProofVerifier');

const SignatureVerifier = require("./build/contracts/verifier/signature/SignatureVerifier");
const SignatureCcipVerifier = require("./build/contracts/verifier/signature/SignatureCcipVerifier");
const SignatureVerifier = require('./build/contracts/verifier/signature/SignatureVerifier');
const SignatureCcipVerifier = require('./build/contracts/verifier/signature/SignatureCcipVerifier');

const CcipResponseVerifier = require("./build/contracts/verifier/CcipResponseVerifier");
const ICcipResponseVerifier = require("./build/contracts/verifier/ICcipResponseVerifier");
const CcipResponseVerifier = require('./build/contracts/verifier/CcipResponseVerifier');
const ICcipResponseVerifier = require('./build/contracts/verifier/ICcipResponseVerifier');

const ERC3668Resolver = require("./build/contracts/ERC3668Resolver");
const IContextResolver = require("./build/contracts/IContextResolver");
const IExtendedResolver = require("./build/contracts/IExtendedResolver");
const Supportsinterface = require("./build/contracts/Supportsinterface");
const ERC3668Resolver = require('./build/contracts/ERC3668Resolver');
const IContextResolver = require('./build/contracts/IContextResolver');
const IExtendedResolver = require('./build/contracts/IExtendedResolver');
const Supportsinterface = require('./build/contracts/Supportsinterface');

module.exports = {
ProofServiceTestContract,
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@
"axios": "^1.4.0",
"body-parser": "^1.20.2",
"express": "^4.18.2",
"solidity-bytes-utils": "^0.8.0",
"winston": "^3.9.0"
"solidity-bytes-utils": "^0.8.0"
}
}
7 changes: 0 additions & 7 deletions test/contracts/SignatureCcipVerifier.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
import exp from 'constants';
import { BigNumber, ethers } from 'ethers';
import { dnsEncode } from 'ethers/lib/utils';
import { ethers as hreEthers } from 'hardhat';
import winston from 'winston';

import { signAndEncodeResponse } from '../../gateway/handler/signing/signAndEncodeResponse';
import { expect } from '../../test/chai-setup';
Expand All @@ -17,11 +15,6 @@ describe('Signature Ccip Verifier', () => {
let alice: SignerWithAddress;
let resolver: SignerWithAddress;

global.logger = winston.createLogger({
level: process.env.LOG_LEVEL ?? 'info',
transports: [new winston.transports.Console()],
});

beforeEach(async () => {
// Get signers
[owner, signer1, signer2, rando, alice, resolver] = await hreEthers.getSigners();
Expand Down
6 changes: 0 additions & 6 deletions test/e2e/optimismBedrockHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { ethers, Wallet } from 'ethers';
import express from 'express';
import { config, ethers as hreEthers } from 'hardhat';
import request from 'supertest';
import winston from 'winston';

import { getConfigReader } from '../../gateway/config/ConfigReader';
import { ccipGateway } from '../../gateway/http/ccipGateway';
Expand Down Expand Up @@ -95,11 +94,6 @@ describe('Optimism Bedrock Handler', () => {

ccipApp = express();
ccipApp.use(bodyParser.json());

global.logger = winston.createLogger({
level: process.env.LOG_LEVEL ?? 'info',
transports: [new winston.transports.Console()],
});
});

it('Returns valid string data from resolver', async () => {
Expand Down
5 changes: 0 additions & 5 deletions test/gateway/readConfig.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { expect } from 'chai';
import winston from 'winston';

import { getConfigReader } from '../../gateway/config/ConfigReader';

global.logger = winston.createLogger({
level: process.env.LOG_LEVEL ?? 'info',
transports: [new winston.transports.Console()],
});
// 0x49e0aec78ec0df50852e99116e524a43be91b789
// 0x49e0AeC78ec0dF50852E99116E524a43bE91B789
describe('ReadConfig Test', () => {
Expand Down
6 changes: 0 additions & 6 deletions test/gateway/signatureHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { ethers, Wallet } from 'ethers';
import express from 'express';
import { config, ethers as hreEthers } from 'hardhat';
import request from 'supertest';
import winston from 'winston';

import { getConfigReader } from '../../gateway/config/ConfigReader';
import { ccipGateway } from '../../gateway/http/ccipGateway';
Expand All @@ -21,11 +20,6 @@ import {
} from '../../typechain';
import { getGateWayUrl, getGateWayUrlForAddress } from '../helper/getGatewayUrl';

global.logger = winston.createLogger({
level: process.env.LOG_LEVEL ?? 'info',
transports: [new winston.transports.Console()],
});

describe('Signature Handler', () => {
let ccipApp: express.Express;
let erc3668Resolver: ERC3668Resolver;
Expand Down
Loading
Loading