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

Feat/hfm 23 3 #317

Draft
wants to merge 8 commits into
base: develop
Choose a base branch
from
Draft
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
7 changes: 6 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
{
"solidity.compileUsingRemoteVersion": "v0.8.13+commit.abaa5c0e"
"workbench.colorCustomizations": {
"statusBar.background": "#7C21D7",
"statusBar.debuggingBackground": "#7C21D7",
"statusBar.noFolderBackground": "#7C21D7",
"statussBar.prominentBackground": "#7C21D7"
}
}
5 changes: 3 additions & 2 deletions deploy/11_layer_zero.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const func: DeployFunction = async function (hre1: HardhatRuntimeEnvironment) {
const currentNetworkType: NetworkType = networks[hre.networkName].type;
let lzEndpoint = networks[hre.networkName].lzEndpoint.toLowerCase();

if (lzEndpoint && lzEndpoint !== zeroAddress) {
if (lzEndpoint) {
if (currentNetworkType === NetworkType.local && lzEndpoint === zeroAddress) {
lzEndpoint = (await hre.getNamedAccounts()).lzEndpoint;
const mockLZEndpoint = await hre.deployments.deploy('MockLZEndpoint', {
Expand All @@ -32,13 +32,14 @@ const func: DeployFunction = async function (hre1: HardhatRuntimeEnvironment) {
gasLimit: await hre.ethers.provider.estimateGas(
(await hre.ethers.getContractFactory('MockLZEndpoint')).getDeployTransaction()
),
nonce: await hre.ethers.provider.getTransactionCount(lzEndpoint),
// nonce: await hre.ethers.provider.getTransactionCount(lzEndpoint),
})),
args: [],
log: true,
waitConfirmations: 1,
} as any);
lzEndpoint = mockLZEndpoint.address.toLowerCase();
console.log(`Deployed MockLZEndpoint to: ${mockLZEndpoint.address}`);
}

const layerZeroModuleProxy = await hre.ethers.getContract('LayerZeroModuleProxy', deployerAddress);
Expand Down
9 changes: 8 additions & 1 deletion src/HolographBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ import "./interface/HolographFactoryInterface.sol";
import "./interface/HolographOperatorInterface.sol";
import "./interface/HolographRegistryInterface.sol";
import "./interface/InitializableInterface.sol";

import {console} from "forge-std/Test.sol";
/**
* @title Holograph Bridge
* @author https://github.com/holographxyz
Expand Down Expand Up @@ -354,6 +354,7 @@ contract HolographBridge is Admin, Initializable, HolographBridgeInterface {
"HOLOGRAPH: not holographed"
);
bytes memory payload;
console.log("############## HolographBridge 1 ");
/**
* @dev the revertedBridgeOutRequest function is wrapped into a try/catch function
*/
Expand All @@ -363,11 +364,14 @@ contract HolographBridge is Admin, Initializable, HolographBridgeInterface {
/**
* @dev a non reverted result is actually a revert
*/
console.log("############## HolographBridge 2 ");
console.log(revertReason);
revert(revertReason);
} catch (bytes memory realResponse) {
/**
* @dev a revert is actually success, so the return data is stored as payload
*/
console.log("############## HolographBridge 3 ");
payload = realResponse;
}
uint256 jobNonce;
Expand All @@ -378,6 +382,7 @@ contract HolographBridge is Admin, Initializable, HolographBridgeInterface {
* @dev extract hlgFee from operator
*/
uint256 fee = 0;
console.log("############## HolographBridge 4 ");
if (gasPrice < type(uint256).max && gasLimit < type(uint256).max) {
(uint256 hlgFee, , uint256 dstGasPrice) = _operator().getMessageFee(
toChain,
Expand All @@ -393,6 +398,7 @@ contract HolographBridge is Admin, Initializable, HolographBridgeInterface {
/**
* @dev the data is abi encoded into actual bridgeOutRequest payload bytes
*/
console.log("############## HolographBridge 5 ");
bytes memory encodedData = abi.encodeWithSelector(
HolographBridgeInterface.bridgeInRequest.selector,
/**
Expand All @@ -407,6 +413,7 @@ contract HolographBridge is Admin, Initializable, HolographBridgeInterface {
true,
payload
);
console.log("############## HolographBridge 6 ");
/**
* @dev this abi encodes the data just like in Holograph Operator
*/
Expand Down
44 changes: 44 additions & 0 deletions src/HolographFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ import "./struct/Verification.sol";

import "./library/Strings.sol";

import {console} from "forge-std/Test.sol";
/**
* @title Holograph Factory
* @author https://github.com/holographxyz
Expand Down Expand Up @@ -233,6 +234,14 @@ contract HolographFactory is Admin, Initializable, Holographable, HolographFacto
/**
* @dev the configuration is encoded and hashed along with signer address
*/
console.log("------- Factory - config.contractType: ");
console.logBytes32(config.contractType);
console.log("------- Factory - config.chainType: ");
console.logUint(config.chainType);
console.log("------- Factory - config.salt: ");
console.logBytes32(config.salt);
console.log("------- Factory - config.signer: ");
console.logAddress(signer);
bytes32 hash = keccak256(
abi.encodePacked(
config.contractType,
Expand All @@ -243,10 +252,29 @@ contract HolographFactory is Admin, Initializable, Holographable, HolographFacto
signer
)
);
console.log("------- Factory - hash: ");
console.logBytes32(hash);
if (hash == 0xa3a2316b8119471cb8f7f5d293ef00c9a2544864c2cc4ac7efaadfb71736b99e) {
console.log("sample found");
console.log("------- Factory - config.byteCode: ");
console.logBytes32(keccak256(config.byteCode));
console.log("------- Factory - config.initCode: ");
console.logBytes32(keccak256(config.initCode));
}
/**
* @dev the hash is validated against signature
* this is to guarantee that the original creator's configuration has not been altered
*/
console.log("------- Factory - signatyre.r: ");
console.logBytes32(signature.r);
console.log("------- Factory - signatyre.s: ");
console.logBytes32(signature.s);
console.log("------- Factory - signatyre.v: ");
console.logUint(signature.v);
console.log("------- Factory - hash: ");
console.logBytes32(hash);
console.log("------- Factory - signer: ");
console.logAddress(signer);
require(_verifySigner(signature.r, signature.s, signature.v, hash, signer), "HOLOGRAPH: invalid signature");
/**
* @dev check that this contract has not already been deployed on this chain
Expand All @@ -255,13 +283,17 @@ contract HolographFactory is Admin, Initializable, Holographable, HolographFacto
address holographerAddress = address(
uint160(uint256(keccak256(abi.encodePacked(bytes1(0xff), address(this), hash, keccak256(holographerBytecode)))))
);
console.log("------- Factory - holographerAddress 1 : ");
console.logAddress(holographerAddress);
require(!_isContract(holographerAddress), "HOLOGRAPH: already deployed");
/**
* @dev convert hash into uint256 which will be used as the salt for create2
*/
uint256 saltInt = uint256(hash);
address sourceContractAddress;
bytes memory sourceByteCode = config.byteCode;
console.log("------- Factory - saltInt: ");
console.logUint(saltInt);
assembly {
/**
* @dev deploy the user created smart contract first
Expand All @@ -277,16 +309,28 @@ contract HolographFactory is Admin, Initializable, Holographable, HolographFacto
/**
* @dev initialize the Holographer contract
*/
console.log("------- Factory - InitializableInterface.init.selector: ");
console.logBytes4(InitializableInterface.init.selector);
console.log("------- Factory - initializableinterface");
// console.logBytes4(InitializableInterface(holographerAddress).init(
// abi.encode(abi.encode(config.chainType, holograph, config.contractType, sourceContractAddress), config.initCode)
// ));
require(
InitializableInterface(holographerAddress).init(
abi.encode(abi.encode(config.chainType, holograph, config.contractType, sourceContractAddress), config.initCode)
) == InitializableInterface.init.selector,
"initialization failed"
);
console.log("------- Factory - si paso");
/**
*
* @dev update the Holograph Registry with deployed contract address
*/
HolographRegistryInterface(registry).setHolographedHashAddress(hash, holographerAddress);
console.log("------- Factory - holographerAddress 2 : ");
console.logAddress(holographerAddress);
console.log("------- Factory - hash: ");
console.logBytes32(hash);
/**
* @dev emit an event that on-chain indexers can easily read
*/
Expand Down
12 changes: 12 additions & 0 deletions src/HolographOperator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ import "./interface/HolographInterfacesInterface.sol";
import "./interface/Ownable.sol";

import "./struct/OperatorJob.sol";
import {console} from "forge-std/Test.sol";

/**
* @title Holograph Operator
Expand Down Expand Up @@ -497,6 +498,9 @@ contract HolographOperator is Admin, Initializable, HolographOperatorInterface {
* @dev This function is restricted for use by Holograph Messaging Module only
*/
function crossChainMessage(bytes calldata bridgeInRequestPayload) external payable {
console.log("$$$$$$$$$$$$$ Operator crossChainMessage 1");
console.logAddress(msg.sender);
console.logAddress(address(_messagingModule()));
require(msg.sender == address(_messagingModule()), "HOLOGRAPH: messaging only call");
uint256 gasPrice = 0;
assembly {
Expand All @@ -506,8 +510,10 @@ contract HolographOperator is Admin, Initializable, HolographOperatorInterface {
gasPrice := calldataload(sub(add(bridgeInRequestPayload.offset, bridgeInRequestPayload.length), 0x20))
}
bool underpriced = gasPrice < _minGasPrice();
console.log("$$$$$$$$$$$$$ Operator crossChainMessage 2");
unchecked {
bytes32 jobHash = keccak256(bridgeInRequestPayload);
console.log("$$$$$$$$$$$$$ Operator crossChainMessage 3");
/**
* @dev load and increment operator temp storage in one call
*/
Expand All @@ -516,12 +522,14 @@ contract HolographOperator is Admin, Initializable, HolographOperatorInterface {
* @dev use job hash, job nonce, block number, and block timestamp for generating a random number
*/
uint256 random = uint256(keccak256(abi.encodePacked(jobHash, _jobNonce(), block.number, block.timestamp)));
console.log("$$$$$$$$$$$$$ Operator crossChainMessage 4");
// use the left 128 bits of random number
uint256 random1 = uint256(random >> 128);
// use the right 128 bits of random number
uint256 random2 = uint256(uint128(random));
// combine the two new random numbers for use in additional pod operator selection logic
random = uint256(keccak256(abi.encodePacked(random1 + random2)));
console.log("$$$$$$$$$$$$$ Operator crossChainMessage 5");
/**
* @dev divide by total number of pods, use modulus/remainder
*/
Expand All @@ -530,6 +538,7 @@ contract HolographOperator is Admin, Initializable, HolographOperatorInterface {
* @dev identify the total number of available operators in pod
*/
uint256 podSize = _operatorPods[pod].length;
console.log("$$$$$$$$$$$$$ Operator crossChainMessage 6");
/**
* @dev select a primary operator
*/
Expand All @@ -541,6 +550,7 @@ contract HolographOperator is Admin, Initializable, HolographOperatorInterface {
*/
_operatorTempStorage[_operatorTempStorageCounter] = _operatorPods[pod][operatorIndex];
_popOperator(pod, operatorIndex);
console.log("$$$$$$$$$$$$$ Operator crossChainMessage 7");
if (podSize > 1) {
podSize--;
}
Expand All @@ -559,6 +569,8 @@ contract HolographOperator is Admin, Initializable, HolographOperatorInterface {
/**
* @dev emit event to signal to operators that a job has become available
*/
console.log("$$$$$$$$$$$$$ Operator crossChainMessage 7");
console.logBytes32(jobHash);
emit AvailableOperatorJob(jobHash, bridgeInRequestPayload);
}
}
Expand Down
Loading
Loading