Skip to content

Commit

Permalink
alpha1
Browse files Browse the repository at this point in the history
Signed-off-by: Logan Nguyen <[email protected]>
  • Loading branch information
quiet-node committed Apr 23, 2024
1 parent e616d15 commit 6179e9d
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 3 deletions.
2 changes: 0 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions packages/relay/src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,10 @@ export default {
NEW_HEADS: 'newHeads',
NEW_PENDING_TRANSACTIONS: 'newPendingTransactions',
},

// @source: Foundry related constants below can be found at https://github.com/Arachnid/deterministic-deployment-proxy?tab=readme-ov-file#latest-outputs
DETERMINISTIC_DEPLOYER_TRANSACTION:
'0xf8a58085174876e800830186a08080b853604580600e600039806000f350fe7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf31ba02222222222222222222222222222222222222222222222222222222222222222a02222222222222222222222222222222222222222222222222222222222222222',
DETERMINISTIC_DEPLOYMENT_SIGNER: '0x3fab184622dc19b6109349b94811493bf2a45362',
DETERMINISTIC_PROXY_CONTRACT: '0x4e59b44847b379578588920ca78fbf26c0b4956c',
};
17 changes: 16 additions & 1 deletion packages/relay/src/lib/precheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,13 @@ export class Precheck {
const requestIdPrefix = formatRequestIdMessage(requestId);
const minGasPrice = BigInt(gasPrice);
const txGasPrice = tx.gasPrice || tx.maxFeePerGas! + tx.maxPriorityFeePerGas!;
const passes = txGasPrice >= minGasPrice;

// **notice: Pass gasPrice precheck if txGasPrice is greater than the minimum network's gas price value,
// OR if the transaction is the deterministic deployment transaction (a special case).
// **explanation: The deterministic deployment transaction is pre-signed with a gasPrice value of only 10 hbars,
// which is lower than the minimum gas price value in all Hedera network environments. Therefore,
// this special case is exempt from the precheck in the Relay, and the gas price logic will be resolved at the Services level.
const passes = txGasPrice >= minGasPrice || Precheck.isDeterministicDeploymentTransaction(tx);

if (!passes) {
if (constants.GAS_PRICE_TINY_BAR_BUFFER) {
Expand All @@ -152,6 +158,15 @@ export class Precheck {
}
}

/**
* Checks if a transaction is the deterministic deployment transaction.
* @param {Transaction} tx - The transaction to check.
* @returns {boolean} Returns true if the transaction is the deterministic deployment transaction, otherwise false.
*/
static isDeterministicDeploymentTransaction(tx: Transaction): boolean {
return tx.serialized === constants.DETERMINISTIC_DEPLOYER_TRANSACTION;
}

/**
* @param tx
* @param callerName
Expand Down
25 changes: 25 additions & 0 deletions packages/relay/tests/lib/precheck.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,31 @@ describe('Precheck', async function () {
expect(result).to.not.exist;
});

it('should recognize if a signed raw transaction is the deterministic deployment transaction', async () => {
const parsedDeterministicDeploymentTransaction = ethers.Transaction.from(
constants.DETERMINISTIC_DEPLOYER_TRANSACTION,
);

expect(Precheck.isDeterministicDeploymentTransaction(parsedDeterministicDeploymentTransaction)).to.be.true;
});

it('Should recognize if a signed raw transaction is NOT the deterministic deployment transaction', async () => {
expect(Precheck.isDeterministicDeploymentTransaction(parsedtxWithChainId0x0)).to.be.false;
expect(Precheck.isDeterministicDeploymentTransaction(parsedTxWithMatchingChainId)).to.be.false;
expect(Precheck.isDeterministicDeploymentTransaction(parsedTxWithNonMatchingChainId)).to.be.false;
});

it('should pass for gas price if the transaction is the deterministic deployment transaction', async function () {
const parsedDeterministicDeploymentTransaction = ethers.Transaction.from(
constants.DETERMINISTIC_DEPLOYER_TRANSACTION,
);
const result = precheck.gasPrice(
parsedDeterministicDeploymentTransaction,
100 * constants.TINYBAR_TO_WEIBAR_COEF,
);
expect(result).to.not.exist;
});

it('should not pass for gas price not enough', async function () {
const minGasPrice = 1000 * constants.TINYBAR_TO_WEIBAR_COEF;
try {
Expand Down

0 comments on commit 6179e9d

Please sign in to comment.