Skip to content

Commit

Permalink
Merge pull request #10 from unruggable-labs/inc-artifacts
Browse files Browse the repository at this point in the history
Add Artifacts to NPM, Few Test Changes
  • Loading branch information
clowestab committed Oct 18, 2024
2 parents b109adc + 6c470d6 commit dc46be3
Show file tree
Hide file tree
Showing 34 changed files with 341 additions and 243 deletions.
1 change: 1 addition & 0 deletions .gitignore
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
node_modules/
cache/
out/
artifacts/
junk/
dist/
.vscode/
Expand Down
Empty file modified README.md
100755 → 100644
Empty file.
Empty file modified bunfig.toml
100755 → 100644
Empty file.
3 changes: 2 additions & 1 deletion contracts/GatewayFetcher.sol
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ library GatewayFetcher {
string memory label
) internal pure returns (GatewayRequest memory) {
bytes memory v = bytes(label);
return r.addByte(GatewayOP.DEBUG).push(v.length).addBytes(v);
if (v.length >= 256) revert RequestOverflow();
return r.addByte(GatewayOP.DEBUG).addByte(uint8(v.length)).addBytes(v);
}

function push(
Expand Down
8 changes: 4 additions & 4 deletions contracts/GatewayVM.sol
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ library GatewayVM {
function evalCommand(
Machine memory vm,
bytes[] memory outputs
) internal view returns (uint8 exitCode) {
) internal view returns (uint8 /*exitCode*/) {
while (vm.pos < vm.buf.length) {
//uint256 g = gasleft();
uint8 op = vm.readByte();
Expand All @@ -340,8 +340,8 @@ library GatewayVM {
uint256 i = vm.popAsUint256(); // rhs evaluates BEFORE lhs
outputs[i] = vm.popAsBytes();
} else if (op == GatewayOP.ASSERT) {
uint8 code = vm.readByte();
if (vm.isStackZeros(vm.pop())) return code;
uint8 exitCode = vm.readByte();
if (vm.isStackZeros(vm.pop())) return exitCode;
} else if (op == GatewayOP.READ_SLOT) {
vm.pushBytes(vm.proveSlots(1));
} else if (op == GatewayOP.READ_SLOTS) {
Expand Down Expand Up @@ -479,7 +479,7 @@ library GatewayVM {
(uint256 pos, bytes memory buf) = (vm.pos, vm.buf); // save program
vm.buf = program;
vm.pos = 0;
exitCode = vm.evalCommand(outputs);
uint8 exitCode = vm.evalCommand(outputs);
if (exitCode != 0) return exitCode;
(vm.pos, vm.buf) = (pos, buf); // restore program
}
Expand Down
10 changes: 6 additions & 4 deletions contracts/op/OPFaultVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,7 @@ contract OPFaultVerifier is AbstractVerifier {
(, , IDisputeGame gameProxy1) = _portal
.disputeGameFactory()
.gameAtIndex(gameIndex1);
_checkWindow(
Timestamp.unwrap(gameProxy1.resolvedAt()),
Timestamp.unwrap(gameProxy.resolvedAt())
);
_checkWindow(_getGameTime(gameProxy1), _getGameTime(gameProxy));
}
require(
Claim.unwrap(gameProxy.rootClaim()) ==
Expand All @@ -116,4 +113,9 @@ contract OPFaultVerifier is AbstractVerifier {
)
);
}

function _getGameTime(IDisputeGame g) internal view returns (uint256) {
return
Timestamp.unwrap(_minAgeSec == 0 ? g.resolvedAt() : g.createdAt());
}
}
17 changes: 11 additions & 6 deletions foundry.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
# https://book.getfoundry.sh/reference/config/overview

[profile.default]
src = "contracts"
solc = "0.8.25"

evm_version = "cancun"

libs = ["lib"]
remappings = [
'@openzeppelin/contracts=lib/openzeppelin-contracts/contracts/',
'@eth-optimism=lib/optimism/packages/',
]

solc = "0.8.25"
evm_version = "cancun"
optimizer = true
optimizer_runs = 200
optimizer_runs = 1 # https://docs.soliditylang.org/en/latest/internals/optimizer.html#optimizer-parameter-runs

[profile.dist]
test = "contracts" # disables tests
out = "artifacts"
cache = false
6 changes: 3 additions & 3 deletions package.json
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@unruggable/gateways",
"version": "0.1.2",
"version": "0.1.3",
"description": "Trustless Ethereum Multichain CCIP-Read Gateway",
"publishConfig": {
"access": "public"
Expand All @@ -19,7 +19,7 @@
],
"type": "module",
"scripts": {
"check": "tsc -p . --noEmit",
"check": "bunx tsc -p . --noEmit",
"forge": "forge build --force",
"serve": "bun scripts/serve.ts",
"test": "IS_CI=1 bun test --timeout 25000",
Expand All @@ -40,7 +40,7 @@
},
"files": [
"dist/",
"src/",
"artifacts/",
"contracts/GatewayFetcher.sol",
"contracts/GatewayFetchTarget.sol",
"contracts/GatewayRequest.sol",
Expand Down
23 changes: 13 additions & 10 deletions scripts/build-dist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
readdirSync,
renameSync,
} from 'node:fs';
import { FoundryBase } from '@adraffy/blocksmith';
import { spawnSync } from 'node:child_process';
import { fileURLToPath } from 'node:url';
import { join } from 'node:path';
Expand All @@ -31,25 +32,27 @@ if (pkg.type !== 'module') {
}
log(`Saved configuration`);

// verify build
log(`Typechecking...`);
runTypescript('--noEmit');
log('Ready!');

// clear dist
rmdirSync(distDir, { recursive: true });
mkdirSync(distDir);
log(`Cleaned ${distDir}`);

// remove tests and scripts
tsc.include = ['src'];
writeFileSync(tsconfigFile, JSON.stringify(tsc));
log(`Typechecking...`);
runTypescript('--noEmit');

log(`Compiling Contracts...`);
const foundry = await FoundryBase.load({ profile: 'dist' });
await foundry.build(true);

log('Ready!');

// create outputs
const cjsDir = join(distDir, 'cjs');
const esmDir = join(distDir, 'esm');
const typesDir = join(distDir, 'types');
try {
tsc.include = ['src']; // remove tests and scripts
writeFileSync(tsconfigFile, JSON.stringify(tsc));

setPackageType('commonjs');
runTypescript('--outDir', cjsDir, '--module', 'node16');
forceExtension(cjsDir, 'cjs');
Expand Down Expand Up @@ -77,7 +80,7 @@ try {
}

function runTypescript(...args: string[]) {
spawnSync('bun', ['tsc', '-p', '.', ...args]);
spawnSync('bunx', ['tsc', '-p', '.', ...args]);
}

function setPackageType(type: string) {
Expand Down
Loading

0 comments on commit dc46be3

Please sign in to comment.